Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,428 changes: 1,428 additions & 0 deletions common/christmas.js

Large diffs are not rendered by default.

81 changes: 81 additions & 0 deletions common/season.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// common/season.js
// Sieve — Christmas: when it shows, and what the person chose.
//
// By itself it comes on on 1 December and goes on 2 January, by the
// computer's own clock, without anyone touching it. The switch in Settings ›
// Advanced › Appearance (and the popup's "Turn off Christmas") can also force
// it: on, to have it sooner, or off, to skip it. A forced choice belongs to one
// Christmas, so it never outlives it: turned on in November, it still packs
// itself away on 2 January; turned off in December, it comes back next
// 1 December. Nothing kept means "follow the calendar". common/christmas.js
// draws it; this file only decides, so the tests can ask it about any date.

(() => {
"use strict";

if (window.SieveSeason) return;

// A forced choice, { on, season }, or null to follow the calendar.
const KEY = "uiChristmas";
// The copy each page reads before its first paint, as theme.js keeps one for
// the theme: chrome.storage answers too late to make room for the lights.
const CACHE_KEY = "sieve.uiChristmas";

function asDate(date) {
return date && typeof date.getMonth === "function" ? date : new Date();
}

// 1 December to 1 January, both days included, in local time.
function inSeason(date) {
const d = asDate(date);
const month = d.getMonth();
return month === 11 || (month === 0 && d.getDate() === 1);
}

// The Christmas a day belongs to: the one coming, or the one being had.
// New Year's Day still belongs to the year before's.
function seasonOf(date) {
const d = asDate(date);
return d.getMonth() === 0 && d.getDate() === 1 ? d.getFullYear() - 1 : d.getFullYear();
}

// A kept choice, or null for anything that isn't one.
function normalize(value) {
if (!value || typeof value !== "object") return null;
if (typeof value.on !== "boolean" || !Number.isInteger(value.season)) return null;
return { on: value.on, season: value.season };
}

// Whether it shows on this day: a choice made for this Christmas, else the
// calendar.
function isOn(value, date) {
const choice = normalize(value);
if (choice && choice.season === seasonOf(date)) return choice.on;
return inSeason(date);
}

// What to keep when the switch is set to `on` on this day. The same as the
// calendar would say keeps nothing, so turning it on and off again to try it
// in November still leaves 1 December to bring it.
function choose(on, date) {
return on === inSeason(date) ? null : { on: !!on, season: seasonOf(date) };
}

// The few words under the name in the popup.
function line(date) {
const d = asDate(date);
const y = d.getFullYear();
const m = d.getMonth();
const day = d.getDate();
if (m === 0 && day === 1) return "Happy New Year";
if (m === 11 && day === 24) return "Christmas Eve";
if (m === 11 && day === 31) return "New Year’s Eve";
if (m === 11 && day > 24) return "Merry Christmas";
// Counted in calendar days, so a clock change in between can't make it 23.
const days = Math.round((new Date(y, 11, 25) - new Date(y, m, day)) / 86400000);
if (days > 1) return `${days} days to Christmas`;
return "Merry Christmas";
}

window.SieveSeason = { KEY, CACHE_KEY, inSeason, seasonOf, normalize, isOn, choose, line };
})();
13 changes: 10 additions & 3 deletions common/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
// "light" — data-theme="light", which the dark rules are written to skip.
// "dark" — data-theme="dark", which the dark rules also match outright.
//
// Dark until you choose: nothing kept, or anything unknown, means "dark", as
// BlockNSFW does; only a kept "auto" follows the computer. Someone who never
// chose turns dark on the update that brought this: the first page may paint
// once from the old copy, then storage answers and the copy says dark.
//
// Where the attribute goes depends on whose page it is:
//
// - On Sieve's own pages (settings, popup, blocked page, onboarding, release
Expand All @@ -31,20 +36,21 @@
const KEY = "uiTheme";
const CACHE_KEY = "sieve.uiTheme";
const THEMES = ["auto", "light", "dark"];
const DEFAULT = "dark";

const ownPage = /^(chrome|moz)-extension:$/.test(location.protocol);
const listeners = [];
let current = "auto";
let current = DEFAULT;

function normalize(value) {
return THEMES.includes(value) ? value : "auto";
return THEMES.includes(value) ? value : DEFAULT;
}

function readCache() {
try {
return normalize(localStorage.getItem(CACHE_KEY));
} catch {
return "auto";
return DEFAULT;
}
}

Expand Down Expand Up @@ -99,6 +105,7 @@
window.SieveTheme = {
KEY,
THEMES,
DEFAULT,
normalize,
get: () => current,
mark,
Expand Down
15 changes: 8 additions & 7 deletions content/search-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,15 +307,16 @@
let hideCount = false; // the user chose no count, and so no way back to what is hidden
let compiled = [];
let palette = [];
// Sieve's Appearance choice: "auto", "light" or "dark". Read here with the
// other settings rather than by loading common/theme.js, which would add a
// storage read to every page this script is injected into.
let uiTheme = "auto";
// Sieve's Appearance choice: "auto", "light" or "dark", and dark until one
// is made, as in common/theme.js. Read here with the other settings rather
// than by loading common/theme.js, which would add a storage read to every
// page this script is injected into.
let uiTheme = "dark";

function markTheme(el) {
if (!el) return;
if (uiTheme === "light" || uiTheme === "dark") el.setAttribute("data-theme", uiTheme);
else el.removeAttribute("data-theme");
if (uiTheme === "auto") el.removeAttribute("data-theme");
else el.setAttribute("data-theme", uiTheme === "light" ? "light" : "dark");
}
// What is hidden on the page now: the total the notice states, and the same
// results by site for its "By site" list. Changed only through noteHidden(),
Expand Down Expand Up @@ -1124,7 +1125,7 @@
searchFilterHideBlocked: true,
searchFilterHideCount: false,
customBlocks: [],
uiTheme: "auto",
uiTheme: "dark",
});
enabled = stored.searchFilterEnabled;
hideCount = stored.searchFilterHideCount;
Expand Down
55 changes: 55 additions & 0 deletions options/options.css
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,12 @@ html.preload .loading-veil {
outline: none;
}

/* Christmas (common/christmas.js), 1 December to 1 January: lights hang
across the top of the column, so it starts lower. */
.is-christmas .main {
padding-top: 104px;
}

/* One section is shown at a time; options.js hides the rest. Arriving at one
is the only page-level motion: a short rise, no stagger. */
.section {
Expand Down Expand Up @@ -2203,6 +2209,46 @@ html.preload .loading-veil {
flex: none;
}

/* Christmas: the dial wears a Santa hat on its ring (options.html), drawn
inside the dial so it scales with it, only while it's Christmas. Its
colours live in its SVG; the bobble swings unless motion is reduced. */
.xmas-hat {
display: none;
}

.is-christmas .xmas-hat {
display: inline;
}

.is-christmas .warden-dial {
overflow: visible;
}

.xmas-hat-dial {
filter: drop-shadow(0 1px 1.5px rgba(0, 0, 0, 0.4));
}

.xmas-hat-pom {
transform-box: fill-box;
transform-origin: 40% 23%;
animation: xmas-hat-sway 3.4s ease-in-out infinite alternate;
}

@keyframes xmas-hat-sway {
from {
transform: rotate(-8deg);
}
to {
transform: rotate(10deg);
}
}

@media (prefers-reduced-motion: reduce) {
.xmas-hat-pom {
animation: none;
}
}

.warden-clock {
font-family: var(--font-mono);
font-size: 15px;
Expand Down Expand Up @@ -2489,6 +2535,15 @@ html.preload .loading-veil {
padding: 40px 16px 56px;
}

/* With the index on top, the lights hang above it instead. */
.is-christmas .main {
padding-top: 40px;
}

.is-christmas .sidebar {
padding-top: 88px;
}

.section-title {
font-size: 34px;
}
Expand Down
30 changes: 30 additions & 0 deletions options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<script src="../common/theme.js"></script>
<link rel="stylesheet" href="options.css" />
<link rel="stylesheet" href="usage-insights.css" />
<script src="../common/season.js"></script>
<script src="../common/christmas.js"></script>
</head>
<body class="paper">
<!-- Loading veil — shown only while <html> carries `preload` (i.e. until
Expand Down Expand Up @@ -161,6 +163,19 @@ <h2 class="warden-title" id="warden-title">In a weak moment, Warden <em>makes yo
<circle class="warden-arc" cx="64" cy="64" r="46" fill="none" stroke="var(--band-signal)" stroke-width="1.5" stroke-linecap="round" stroke-dasharray="289.03" stroke-dashoffset="91.53" transform="rotate(-90 64 64)"/>
<text class="warden-clock" x="64" y="67" text-anchor="middle" data-warden-clock>23:59:41</text>
<text class="warden-clock-label" x="64" y="82" text-anchor="middle">COOL-DOWN</text>
<!-- Christmas: a Santa hat worn on the ring, at an angle, as on
BlockNSFW's Warden dial. -->
<g class="xmas-hat xmas-hat-dial" transform="translate(70 12.5) rotate(16) translate(-48 -34.3) scale(0.6857)">
<defs>
<linearGradient id="xmas-hat-red" x1="0.1" y1="0.1" x2="0.9" y2="0.9"><stop offset="0" stop-color="#e5523d" /><stop offset="0.55" stop-color="#c4352a" /><stop offset="1" stop-color="#8f2219" /></linearGradient>
<radialGradient id="xmas-hat-fur" cx="0.4" cy="0.3" r="0.8"><stop offset="0" stop-color="#ffffff" /><stop offset="0.7" stop-color="#eef2f3" /><stop offset="1" stop-color="#c9d4da" /></radialGradient>
</defs>
<path d="M20 70 C24 44 46 18 80 16 C102 15 118 28 122 48 C115 43 106 41 98 43 C92 52 90 61 90 70 Z" fill="url(#xmas-hat-red)" />
<path d="M98 43 C106 41 115 43 122 48 C113 46.5 105 47 99 50 Z" fill="#3c0806" fill-opacity="0.35" />
<path d="M31 63 C35 46 50 29 69 23" fill="none" stroke="#ffffff" stroke-opacity="0.32" stroke-width="2.4" stroke-linecap="round" />
<g class="xmas-hat-pom" fill="url(#xmas-hat-fur)"><circle cx="122" cy="54" r="9.5" /><circle cx="115.5" cy="50" r="3.6" /><circle cx="128.5" cy="50.5" r="3.6" /><circle cx="122" cy="45.5" r="3.6" /><circle cx="116.5" cy="59.5" r="3.4" /><circle cx="127.5" cy="60" r="3.4" /></g>
<g fill="url(#xmas-hat-fur)"><path d="M10 66 Q55 57 100 66 Q103 73 100 80 Q55 72 10 80 Q7 73 10 66 Z" /><circle cx="14" cy="65" r="3.6" /><circle cx="26" cy="63" r="3.6" /><circle cx="38" cy="61.7" r="3.6" /><circle cx="50" cy="61.2" r="3.6" /><circle cx="62" cy="61.2" r="3.6" /><circle cx="74" cy="61.9" r="3.6" /><circle cx="86" cy="63.2" r="3.6" /><circle cx="98" cy="65.2" r="3.6" /><circle cx="14" cy="79.6" r="3.4" /><circle cx="26" cy="78" r="3.4" /><circle cx="38" cy="77" r="3.4" /><circle cx="50" cy="76.5" r="3.4" /><circle cx="62" cy="76.5" r="3.4" /><circle cx="74" cy="77.1" r="3.4" /><circle cx="86" cy="78.3" r="3.4" /><circle cx="98" cy="80" r="3.4" /></g>
</g>
</svg>
<button class="warden-hide" id="warden-hide" type="button" aria-label="Hide this message" aria-controls="warden-band">
<svg viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><path d="M3.5 3.5l9 9M12.5 3.5l-9 9" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round"/></svg>
Expand Down Expand Up @@ -1800,6 +1815,21 @@ <h3 class="field-title" id="ui-theme-title">Theme</h3>
</label>
</div>
</div>
<!-- Christmas: common/season.js says when, common/christmas.js
draws it. The switch shows whether it is on now, and is
there all year: on to have it sooner, off to skip it. -->
<div class="field" id="christmas-field">
<div class="switch-row">
<div class="switch-label">
<span class="label">Christmas</span>
<span class="description">Snow settles on the lines and lights hang along the top of the toolbar popup, the blocked page and these settings. It comes on by itself on 1 December and packs itself away on 2 January. Switch it on to have it sooner, or off to skip it this year.</span>
</div>
<label class="switch">
<input type="checkbox" id="christmas-toggle" />
<span class="slider"></span>
</label>
</div>
</div>
</div>
</section>
</section>
Expand Down
43 changes: 41 additions & 2 deletions options/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,41 @@ function setupAppearance(store) {
check(T.normalize(store.uiTheme));
}

// Christmas: snow and lights, by themselves from 1 December to 1 January
// (common/season.js; common/christmas.js draws them). The switch shows whether
// it is on now: off before December unless switched on, on through it unless
// switched off. Only how pages look, so no Guardian gate, as for the theme.
// The localStorage copy lets the popup and the blocked page make room for the
// lights in their first paint, as the theme's copy does.
function setupChristmas(store) {
const S = window.SieveSeason;
const toggle = document.getElementById("christmas-toggle");
if (!S || !toggle) return;
let choice = S.normalize(store[S.KEY]);
const show = () => {
toggle.checked = S.isOn(choice, new Date());
};
toggle.addEventListener("change", () => {
choice = S.choose(toggle.checked, new Date());
try {
if (choice) localStorage.setItem(S.CACHE_KEY, JSON.stringify(choice));
else localStorage.removeItem(S.CACHE_KEY);
} catch {
/* storage blocked — each page then waits for chrome.storage */
}
chrome.storage.local.set({ [S.KEY]: choice });
});
// Turned off from the popup, or in another settings window: follow it.
chrome.storage.onChanged.addListener((changes, area) => {
if (area !== "local" || !changes[S.KEY]) return;
choice = S.normalize(changes[S.KEY].newValue);
show();
});
// It comes on by itself at midnight on 1 December, page open or not.
setInterval(show, 60000);
show();
}

// `actionName`, when given, marks this as a protection switch: turning it OFF
// goes through the Guardian gate (asks for the PIN when one is set).
function setupCheckbox(id, storageKey, currentValue, actionName) {
Expand Down Expand Up @@ -569,8 +604,11 @@ function optionsDefaults() {
guardianPinHash: "",
// Cool-off — the wait in hours (0 = off); see common/cooloff.js
cooloffConfig: { hours: 0 },
// Appearance — "auto" | "light" | "dark"; see common/theme.js
uiTheme: "auto",
// Appearance — "auto" | "light" | "dark", dark until chosen; see common/theme.js
uiTheme: "dark",
// Christmas — null follows the calendar (1 December to 1 January), or a
// choice forced for one Christmas, { on, season }; see common/season.js
uiChristmas: null,
// Search Result Filter — rules carry their own colour; see setupSearchFilter
searchFilterEnabled: false,
searchFilterRules: [],
Expand Down Expand Up @@ -734,6 +772,7 @@ async function applyStoredSettings(store) {
// protection toggles.
setupCheckbox("url-shortener-resolver-toggle", "urlShortenerResolverEnabled", store.urlShortenerResolverEnabled, "Turn off URL Shortener Resolver");
setupAppearance(store); // light / dark / match the system
setupChristmas(store); // snow and lights, 1 December to 1 January

setupSearchFilter(store); // hide / colour-code search results
setupWhatsNew(store); // release notes bundled with the extension
Expand Down
9 changes: 9 additions & 0 deletions pages/blocked.html
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@
padding: 28px 32px 0;
}

/* Christmas (common/christmas.js), 1 December to 1 January: lights hang
along the top, so the letterhead starts lower. Never while the urge
screen leads the page; it keeps the page to itself. */
.is-christmas .letterhead {
padding-top: 96px;
}

.lockup {
display: inline-flex;
align-items: center;
Expand Down Expand Up @@ -1888,6 +1895,8 @@
}
}
</style>
<script src="../common/season.js"></script>
<script src="../common/christmas.js"></script>
</head>
<body>
<header class="letterhead">
Expand Down
Loading
Loading