diff options
| author | 2024-01-03 12:59:25 +0100 | |
|---|---|---|
| committer | 2024-01-03 12:59:25 +0100 | |
| commit | b69610285c11ec3251c78c31f60d8a9e92db6e0d (patch) | |
| tree | a64fd8b91e9ba0a11b7e6d3ee983781f83e3d4d1 /floating-cats.js | |
| download | floating-cats-extension-b69610285c11ec3251c78c31f60d8a9e92db6e0d.tar.gz floating-cats-extension-b69610285c11ec3251c78c31f60d8a9e92db6e0d.tar.xz floating-cats-extension-b69610285c11ec3251c78c31f60d8a9e92db6e0d.zip | |
Floating Cats 0.1
Diffstat (limited to 'floating-cats.js')
| -rw-r--r-- | floating-cats.js | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/floating-cats.js b/floating-cats.js new file mode 100644 index 0000000..74acea4 --- /dev/null +++ b/floating-cats.js | |||
| @@ -0,0 +1,50 @@ | |||
| 1 | "use strict"; | ||
| 2 | |||
| 3 | if (typeof(browser) == "undefined") { | ||
| 4 | globalThis.browser = chrome; | ||
| 5 | } | ||
| 6 | |||
| 7 | const cats = []; | ||
| 8 | |||
| 9 | function reflectChange(changes, name, proc) { | ||
| 10 | if (name in changes | ||
| 11 | && "newValue" in changes[name] | ||
| 12 | && !Object.is(changes[name].newValue, changes[name].oldValue)) { | ||
| 13 | proc(changes[name].newValue); | ||
| 14 | } | ||
| 15 | } | ||
| 16 | |||
| 17 | async function main() { | ||
| 18 | let enabled = (await browser.storage.sync.get("enabled")).enabled; | ||
| 19 | |||
| 20 | browser.storage.onChanged.addListener(changes => { | ||
| 21 | reflectChange(changes, "enabled", newEnabled => { | ||
| 22 | enabled = newEnabled; | ||
| 23 | cats.forEach(cat => cat.hidden = !enabled); | ||
| 24 | }); | ||
| 25 | }); | ||
| 26 | |||
| 27 | let counter = 0; | ||
| 28 | function addCat(alt, url) { | ||
| 29 | const floatingX = document.createElement("div"); | ||
| 30 | floatingX.style.setProperty("--floating-cats-floating-delay", `-${50 * counter++}s`); | ||
| 31 | floatingX.classList.add("floating-cats-clickthru"); | ||
| 32 | floatingX.classList.add("floating-cats-floating"); | ||
| 33 | floatingX.classList.add("floating-cats-floating-x"); | ||
| 34 | floatingX.hidden = !enabled; | ||
| 35 | cats.push(floatingX); | ||
| 36 | document.body.appendChild(floatingX); | ||
| 37 | |||
| 38 | const floatingY = document.createElement("img"); | ||
| 39 | floatingY.classList.add("floating-cats-clickthru"); | ||
| 40 | floatingY.classList.add("floating-cats-floating-y"); | ||
| 41 | floatingY.alt = alt; | ||
| 42 | floatingY.src = browser.runtime.getURL(url); | ||
| 43 | floatingX.appendChild(floatingY); | ||
| 44 | } | ||
| 45 | |||
| 46 | addCat("Spinning Marsey", "/marsey3d.webp"); | ||
| 47 | addCat("Spinning Bob", "/bobvibes.webp"); | ||
| 48 | } | ||
| 49 | |||
| 50 | main(); | ||