From 9cfdc4da389ed30fe740a70552957d55ddff3355 Mon Sep 17 00:00:00 2001 From: rohanharikr Date: Wed, 29 May 2024 17:19:26 +0100 Subject: [PATCH 1/2] add script --- public/assets/localStorage.js | 105 ++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 public/assets/localStorage.js diff --git a/public/assets/localStorage.js b/public/assets/localStorage.js new file mode 100644 index 0000000..3231ad3 --- /dev/null +++ b/public/assets/localStorage.js @@ -0,0 +1,105 @@ +const $ = (el) => document.getElementById(el) +const sites = [ + "https://www.greenfielddemo.com/localStorage.html", + "https://www.hello.dev/localStorage.html", + "https://www.hello.coop/localStorage.html", + "https://console.hello.coop/localStorage.html", + "https://playground.hello.dev/localStorage.html", + "https://wallet.hello.coop/localStorage.html", + "https://quickstart.hello.coop/localStorage.html", + "https://blog.hello.coop/localstorage/" +] +const hydrate = () => { + $("hostname").textContent = window.location.hostname + processParams() + addList() + plausibleIgnoreState() +} + +const processParams = () => { + const params = new URLSearchParams(window.location.search) + if (!params.get("action") || !params.get("sites")) { + cleanURL() + return + } + if (params.get("action") === "ignoreAll") { + console.info("Setting plausible_ignore at " + window.location.hostname) + localStorage.setItem("plausible_ignore", true) + } else if (params.get("action") === "clearAll") { + console.info("Clearing localStorage at " + window.location.hostname) + localStorage.clear() + } + let _sites = params.get("sites") + _sites = _sites.split(",") + _sites.pop() + if (!_sites.length) { + cleanURL() + return + } + params.set("sites", _sites.toString()) + const url = new URL(_sites[_sites.length - 1]) + url.search = params + window.location.href = url +} + +const ignoreAll = () => { + const url = makeParams("ignoreAll") + window.location.href = url +} + +const clearAll = () => { + const url = makeParams("clearAll") + window.location.href = url +} + +const cleanURL = () => { + window.history.pushState( + {}, + document.title, + window.location.href.substring(0, window.location.href.indexOf("?")) + ) +} + +const makeParams = (type) => { + let params = new URLSearchParams() + if (type === "clearAll") { + params.append("action", "clearAll") + } else if (type === "ignoreAll") { + params.append("action", "ignoreAll") + } + params.append("sites", sites.toString()) + const url = new URL(sites[sites.length - 1]) + url.search = params + return url +} + +const plausibleIgnoreState = () => { + const checkboxRef = $("plausible_ignore") + if (localStorage.getItem("plausible_ignore")) { + plausible_ignore.checked = true + } + checkboxRef.addEventListener("change", () => { + if (checkboxRef.checked) { + console.info("plausible_ignore added to localStorage") + localStorage.setItem("plausible_ignore", true) + } else { + console.info("plausible_ignore removed from localStorage") + localStorage.removeItem("plausible_ignore") + } + }) +} + +const addList = () => { + const linksRef = $("links") + for (const site of sites) { + if (site === window.location.href) continue + const link = new URL(site) + const liEl = document.createElement("li") + const aEl = document.createElement("a") + aEl.textContent = link.hostname + aEl.href = link + aEl.classList.add("underline") + liEl.appendChild(aEl) + linksRef.appendChild(liEl) + } +} \ No newline at end of file From 92f7dace4ff26692bf73552374a30e24371d200e Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 29 May 2024 16:19:58 +0000 Subject: [PATCH 2/2] 2024.5.4 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 30856b6..ba22947 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "src", - "version": "2024.5.3", + "version": "2024.5.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "src", - "version": "2024.5.3", + "version": "2024.5.4", "hasInstallScript": true, "devDependencies": { "@sveltejs/vite-plugin-svelte": "^2.4.1", diff --git a/package.json b/package.json index 208d9d8..c2fd84d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "src", "private": true, - "version": "2024.5.3", + "version": "2024.5.4", "type": "module", "scripts": { "dev": "vite",