From 1252e93d89d0d21911eabe035041cca6b6d20d0b Mon Sep 17 00:00:00 2001 From: Matthias Kestenholz Date: Mon, 16 Sep 2024 10:52:21 +0200 Subject: [PATCH] Switch to biome --- .eslintrc.js | 33 ---------- .pre-commit-config.yaml | 39 +++++++----- CHANGELOG.md | 1 + biome.json | 57 +++++++++++++++++ esbuild.js | 10 +-- feincms3_cookiecontrol/static/f3cc.js | 2 +- package.json | 3 - pyproject.toml | 90 +++++++++++++-------------- src/gcm.js | 1 + src/main.js | 75 +++++++++++----------- 10 files changed, 168 insertions(+), 143 deletions(-) delete mode 100644 .eslintrc.js create mode 100644 biome.json diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index fd52df0..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1,33 +0,0 @@ -module.exports = { - root: true, - parser: "@babel/eslint-parser", - env: { - browser: true, - es6: true, - node: true, - }, - extends: ["eslint:recommended", "prettier"], - globals: { - Atomics: "readonly", - SharedArrayBuffer: "readonly", - __API_HOST: "readonly", - }, - parserOptions: { - ecmaFeatures: { - experimentalObjectRestSpread: true, - jsx: true, - }, - ecmaVersion: 2021, - requireConfigFile: false, - sourceType: "module", - }, - rules: { - "no-unused-vars": [ - "error", - { - argsIgnorePattern: "^_", - varsIgnorePattern: "^_", - }, - ], - }, -} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fd2003d..ec5223d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,35 +1,40 @@ -exclude: ".yarn/|yarn.lock|static/f3cc" +exclude: ".yarn/|yarn.lock|\\.min\\.(css|js)$|static" repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.6.0 hooks: - id: check-added-large-files + - id: check-builtin-literals + - id: check-executables-have-shebangs - id: check-merge-conflict + - id: check-toml + - id: check-yaml + - id: detect-private-key - id: end-of-file-fixer + - id: mixed-line-ending - id: trailing-whitespace - repo: https://github.com/adamchainz/django-upgrade - rev: 1.20.0 + rev: 1.21.0 hooks: - id: django-upgrade args: [--target-version, "3.2"] - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.6.2" + rev: "v0.6.4" hooks: - id: ruff + args: [--unsafe-fixes] - id: ruff-format - - repo: https://github.com/pre-commit/mirrors-prettier - rev: v3.1.0 + - repo: https://github.com/biomejs/pre-commit + rev: "v0.4.0" hooks: - - id: prettier - args: [--list-different, --no-semi, "--trailing-comma=es5"] - exclude: "^conf/|.*\\.html$" - - repo: https://github.com/pre-commit/mirrors-eslint - rev: v8.56.0 + - id: biome-check + additional_dependencies: ["@biomejs/biome@1.9.1"] + args: [--unsafe] + - repo: https://github.com/tox-dev/pyproject-fmt + rev: 2.2.3 hooks: - - id: eslint - additional_dependencies: - - eslint@8.56.0 - - eslint-config-prettier - - "@babel/core" - - "@babel/eslint-parser" - - "@babel/preset-env" + - id: pyproject-fmt + - repo: https://github.com/abravalheri/validate-pyproject + rev: v0.19 + hooks: + - id: validate-pyproject diff --git a/CHANGELOG.md b/CHANGELOG.md index d937fd1..05a0410 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Reorganized the repository a bit. - Fixed and simplified the Google Consent Management integration. - Added SRF support to the embedding functionality. +- Updated the pre-commit hooks, switched to biome. ## 1.5 (2024-05-05) diff --git a/biome.json b/biome.json new file mode 100644 index 0000000..0b18abf --- /dev/null +++ b/biome.json @@ -0,0 +1,57 @@ +{ + "$schema": "https://biomejs.dev/schemas/1.9.1/schema.json", + "organizeImports": { + "enabled": false + }, + "formatter": { + "enabled": true, + "indentStyle": "space", + "indentWidth": 2 + }, + "linter": { + "enabled": true, + "rules": { + "recommended": true, + "a11y": { + "noSvgWithoutTitle": "off" + }, + "correctness": { + "noUndeclaredVariables": "error", + "noUnusedImports": "error", + "noUnusedVariables": "error", + "useArrayLiterals": "error", + "useHookAtTopLevel": "error" + }, + "security": { + "noDangerouslySetInnerHtml": "warn" + }, + "style": { + "noParameterAssign": "off", + "useForOf": "warn" + }, + "suspicious": { + "noArrayIndexKey": "warn", + "noAssignInExpressions": "off" + } + } + }, + "javascript": { + "formatter": { + "semicolons": "asNeeded" + }, + "globals": ["django", "CKEDITOR"] + }, + "css": { + "formatter": { + "enabled": true + }, + "linter": { + "enabled": true + } + }, + "json": { + "formatter": { + "enabled": false + } + } +} diff --git a/esbuild.js b/esbuild.js index 907ce40..42d334d 100644 --- a/esbuild.js +++ b/esbuild.js @@ -1,8 +1,8 @@ const esbuild = require("esbuild") -const path = require("path") -const util = require("util") -const readFile = util.promisify(require("fs").readFile) +const path = require("node:path") +const util = require("node:util") +const readFile = util.promisify(require("node:fs").readFile) const InlineCSSPlugin = (_options = {}) => { return { @@ -22,11 +22,11 @@ const InlineCSSPlugin = (_options = {}) => { async function generateInjectCSS(sourcePath) { const sourceCSS = await readFile(sourcePath) - let transformed = await esbuild.transform(sourceCSS, { + const transformed = await esbuild.transform(sourceCSS, { loader: "css", minify: true, }) - const minified = ("" + transformed.code.trim()) + const minified = `${transformed.code.trim()}` .replaceAll(/\s+/g, " ") .replaceAll(/\s*([{},;:])\s*/g, "$1") diff --git a/feincms3_cookiecontrol/static/f3cc.js b/feincms3_cookiecontrol/static/f3cc.js index e79f335..f45e35a 100644 --- a/feincms3_cookiecontrol/static/f3cc.js +++ b/feincms3_cookiecontrol/static/f3cc.js @@ -1 +1 @@ -(()=>{(function(){var e=document.createElement("style");e.textContent=".f3cc{font-size:16px;line-height:1.3;--_b:var(--f3cc-background,#e9e9e9);--_f:var(--f3cc-foreground,#000000);--_B:var(--f3cc-button-background,#cbcbcb);--_A:var(--f3cc-accept-background,#90f690);--_F:var(--f3cc-button-foreground,var(--_f));--_E:var(--f3cc-accept-foreground,var(--_F))}.f3cc .f3cc-banner{position:fixed;bottom:0;width:100%;background:var(--_b);color:var(--_f);z-index:2000;padding:1rem 1rem 1.25rem}.f3cc .f3cc-embed{background:var(--_b);color:var(--_f);padding:4rem}.f3cc .f3cc-container{display:flex;gap:2rem;max-width:70em;margin:0 auto;width:80%}@media (max-width:60rem){.f3cc .f3cc-container{width:100%;flex-direction:column}}.f3cc .f3cc-title{font-size:1.5em;font-weight:700;margin-bottom:.25em}.f3cc .f3cc-description a{color:inherit;text-decoration:underline}.f3cc .f3cc-description a:hover{opacity:.7}.f3cc .f3cc-buttons{display:flex;flex-direction:column;gap:1rem;justify-content:center;align-items:stretch}.f3cc .f3cc-button{display:inline-block;background:var(--_B);color:var(--_F);padding:.8rem 1.2rem;white-space:nowrap;text-decoration:none;text-align:center;cursor:pointer;border:none}.f3cc .f3cc-button:hover{opacity:.7}.f3cc .f3cc-button.accept{background:var(--_A);color:var(--_E)}.f3cc .f3cc-button.modify{position:fixed;z-index:2000;bottom:1rem;right:1rem}.f3cc-embed .f3cc-description{margin-bottom:1em}",document.head.appendChild(e)})();var b=(e,t=document)=>t.querySelector(e),k=(e,t=document)=>t.querySelectorAll(e),x=document.body,r="className",l="textContent",j="innerHTML",_="f3cc",i=window.f3ccData||JSON.parse(b("#f3cc-data")[l]),w={},m="f3cc-embed-providers",p,f,d,o=(e,t=null,n=[])=>{let c=document.createElement(e);if(t)for(let[a,s]of Object.entries(t))a.startsWith("data-")?c.setAttribute(a,s):c[a]=s;return c.append(...n),c},u=()=>{if(f){N(f);return}let e=[o("div",{[r]:"f3cc-title",[l]:i.heading}),o("div",{[r]:"f3cc-description",[j]:i.description})],t=[o("a",{[r]:"f3cc-button accept",[l]:i.buttonAccept,onclick:y(!0)}),o("a",{[r]:"f3cc-button reject",[l]:i.buttonReject,onclick:y(!1)})];f=o("div",{[r]:"f3cc f3cc-banner"},[o("div",{[r]:"f3cc-container"},[o("div",{[r]:"f3cc-content"},e),o("div",{[r]:"f3cc-buttons"},t)])]),g().append(f)},E=()=>{if(d){N(d);return}let e;if(e=b(".f3cc-modify")){e.addEventListener("click",c=>{c.preventDefault(),u()});return}let t=i.ppu,n=window.location;i.buttonModify&&(!t||t==`${n.protocol}//${n.host}${n.pathname}`)&&(d=o("a",{[r]:"f3cc-button modify",[l]:i.buttonModify,onclick:c=>{c.preventDefault(),T(d),u()}}),g().append(d))},D=e=>{let t=`${_}=${e};max-age=31536000;path=/;sameSite=Strict`;i.domain&&(t+=`;domain=${i.domain}`),document.cookie=t},S=()=>{let e=`${_}=`;for(let t of document.cookie.split("; "))if(t.startsWith(e))return decodeURIComponent(t.substring(e.length))},v="all",C="essential",H=()=>{let e=S();return v==e||C==e},A=()=>S()===v,N=e=>{e.style.display=""},T=e=>{e&&(e.style.display="none")},y=e=>t=>{t.preventDefault(),D(e?v:C),T(f),E(),h(),L(),window.dispatchEvent(new Event(`f3cc_consent_${e?"granted":"denied"}`))},L=()=>{if(A())for(let e of i.cookies){let t=w[e.name];t||(w[e.name]=t=o("div"),t.dataset.name=e.name,g().append(t)),z(t,e.script)}},g=()=>(p||(p=o("div",{[r]:"f3cc"}),x.append(p)),p),M={},I=(e,t)=>{try{window.localStorage.setItem(e,JSON.stringify(t))}catch{M[e]=t}},$=e=>{try{return JSON.parse(window.localStorage.getItem(e))}catch{return M[e]}},h=window.f3ccRenderEmbeds=()=>{let e=$(m)||[];k(".f3cc-embed").forEach(n=>{let c=b("template",n),a=n.dataset.provider;if(c&&a&&(A()||e.includes(a))){let s=c.content.cloneNode(!0);n.closest(".f3cc").replaceWith(s)}})},q=()=>{x.addEventListener("click",e=>{let t=e.target.closest(".f3cc-button"),n=t&&t.closest(".f3cc-embed");if(t&&n){e.preventDefault();let c=$(m)||[];c.push(n.dataset.provider),I(m,c),h()}})},z=(e,t)=>{e.innerHTML=t;for(let n of k("script",e)){let c=document.createElement("script");for(let s of n.attributes)c.setAttribute(s.name,s.value);let a=document.createTextNode(n.innerHTML);c.appendChild(a),n.replaceWith(c)}};L();h();q();H()?E():u();})(); +(()=>{(function(){var t=document.createElement("style");t.textContent=".f3cc{font-size:16px;line-height:1.3;--_b:var(--f3cc-background,#e9e9e9);--_f:var(--f3cc-foreground,#000000);--_B:var(--f3cc-button-background,#cbcbcb);--_A:var(--f3cc-accept-background,#90f690);--_F:var(--f3cc-button-foreground,var(--_f));--_E:var(--f3cc-accept-foreground,var(--_F))}.f3cc .f3cc-banner{position:fixed;bottom:0;width:100%;background:var(--_b);color:var(--_f);z-index:2000;padding:1rem 1rem 1.25rem}.f3cc .f3cc-embed{background:var(--_b);color:var(--_f);padding:4rem}.f3cc .f3cc-container{display:flex;gap:2rem;max-width:70em;margin:0 auto;width:80%}@media (max-width:60rem){.f3cc .f3cc-container{width:100%;flex-direction:column}}.f3cc .f3cc-title{font-size:1.5em;font-weight:700;margin-bottom:.25em}.f3cc .f3cc-description a{color:inherit;text-decoration:underline}.f3cc .f3cc-description a:hover{opacity:.7}.f3cc .f3cc-buttons{display:flex;flex-direction:column;gap:1rem;justify-content:center;align-items:stretch}.f3cc .f3cc-button{display:inline-block;background:var(--_B);color:var(--_F);padding:.8rem 1.2rem;white-space:nowrap;text-decoration:none;text-align:center;cursor:pointer;border:none}.f3cc .f3cc-button:hover{opacity:.7}.f3cc .f3cc-button.accept{background:var(--_A);color:var(--_E)}.f3cc .f3cc-button.modify{position:fixed;z-index:2000;bottom:1rem;right:1rem}.f3cc-embed .f3cc-description{margin-bottom:1em}",document.head.appendChild(t)})();var b=(t,e=document)=>e.querySelector(t),k=(t,e=document)=>e.querySelectorAll(t),_=document.body,r="className",l="textContent",j="innerHTML",x="f3cc",i=window.f3ccData||JSON.parse(b("#f3cc-data")[l]),w={},m="f3cc-embed-providers",p,f,d,o=(t,e=null,n=[])=>{let c=document.createElement(t);if(e)for(let[s,a]of Object.entries(e))s.startsWith("data-")?c.setAttribute(s,a):c[s]=a;return c.append(...n),c},u=()=>{if(f){T(f);return}let t=[o("div",{[r]:"f3cc-title",[l]:i.heading}),o("div",{[r]:"f3cc-description",[j]:i.description})],e=[o("a",{[r]:"f3cc-button accept",[l]:i.buttonAccept,onclick:y(!0)}),o("a",{[r]:"f3cc-button reject",[l]:i.buttonReject,onclick:y(!1)})];f=o("div",{[r]:"f3cc f3cc-banner"},[o("div",{[r]:"f3cc-container"},[o("div",{[r]:"f3cc-content"},t),o("div",{[r]:"f3cc-buttons"},e)])]),g().append(f)},E=()=>{if(d){T(d);return}let t;if(t=b(".f3cc-modify")){t.addEventListener("click",c=>{c.preventDefault(),u()});return}let e=i.ppu,n=window.location;i.buttonModify&&(!e||e===`${n.protocol}//${n.host}${n.pathname}`)&&(d=o("a",{[r]:"f3cc-button modify",[l]:i.buttonModify,onclick:c=>{c.preventDefault(),L(d),u()}}),g().append(d))},D=t=>{let e=`${x}=${t};max-age=31536000;path=/;sameSite=Strict`;i.domain&&(e+=`;domain=${i.domain}`),document.cookie=e},S=()=>{let t=`${x}=`;for(let e of document.cookie.split("; "))if(e.startsWith(t))return decodeURIComponent(e.substring(t.length))},v="all",C="essential",H=()=>{let t=S();return v===t||C===t},A=()=>S()===v,T=t=>{t.style.display=""},L=t=>{t&&(t.style.display="none")},y=t=>e=>{e.preventDefault(),D(t?v:C),L(f),E(),h(),M(),window.dispatchEvent(new Event(`f3cc_consent_${t?"granted":"denied"}`))},M=()=>{if(A())for(let t of i.cookies){let e=w[t.name];e||(w[t.name]=e=o("div"),e.dataset.name=t.name,g().append(e)),z(e,t.script)}},g=()=>(p||(p=o("div",{[r]:"f3cc"}),_.append(p)),p),N={},I=(t,e)=>{try{window.localStorage.setItem(t,JSON.stringify(e))}catch{N[t]=e}},$=t=>{try{return JSON.parse(window.localStorage.getItem(t))}catch{return N[t]}},h=window.f3ccRenderEmbeds=()=>{let t=$(m)||[];for(let e of k(".f3cc-embed")){let n=b("template",e),c=e.dataset.provider;if(n&&c&&(A()||t.includes(c))){let s=n.content.cloneNode(!0);e.closest(".f3cc").replaceWith(s)}}},q=()=>{_.addEventListener("click",t=>{let e=t.target.closest(".f3cc-button"),n=e?.closest(".f3cc-embed");if(e&&n){t.preventDefault();let c=$(m)||[];c.push(n.dataset.provider),I(m,c),h()}})},z=(t,e)=>{t.innerHTML=e;for(let n of k("script",t)){let c=document.createElement("script");for(let a of n.attributes)c.setAttribute(a.name,a.value);let s=document.createTextNode(n.innerHTML);c.appendChild(s),n.replaceWith(c)}};M();h();q();H()?E():u();})(); diff --git a/package.json b/package.json index 2b709b2..1150160 100644 --- a/package.json +++ b/package.json @@ -12,9 +12,6 @@ "scripts": { "build": "node esbuild.js" }, - "eslintIgnore": [ - "**/build.*" - ], "prettier": { "semi": false } diff --git a/pyproject.toml b/pyproject.toml index a21c403..d8d14d1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,61 +1,66 @@ [build-system] -requires = ["hatchling"] build-backend = "hatchling.build" +requires = [ "hatchling" ] + [project] name = "feincms3-cookiecontrol" -dynamic = ["version"] description = "Cookie Control Panel for GDPR compliant feincms3 websites" readme = "README.rst" -license = "BSD-3-Clause" -requires-python = ">=3.9" +license = { text = "BSD-3-Clause" } authors = [ - { name = "York Schickl", email = "ys@feinheit.ch" }, + { name = "York Schickl", email = "ys@feinheit.ch" }, ] +requires-python = ">=3.9" classifiers = [ - "Environment :: Web Environment", - "Framework :: Django", - "Framework :: Django :: 3.2", - "Framework :: Django :: 4.0", - "Framework :: Django :: 4.1", - "Framework :: Django :: 4.2", - "Framework :: Django :: 5.0", - "Intended Audience :: Developers", - "License :: OSI Approved :: BSD License", - "Operating System :: OS Independent", - "Programming Language :: Python", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", - "Topic :: Internet :: WWW/HTTP :: Dynamic Content", - "Topic :: Software Development", - "Topic :: Software Development :: Libraries :: Application Frameworks", + "Environment :: Web Environment", + "Framework :: Django", + "Framework :: Django :: 3.2", + "Framework :: Django :: 4.0", + "Framework :: Django :: 4.1", + "Framework :: Django :: 4.2", + "Framework :: Django :: 5.0", + "Intended Audience :: Developers", + "License :: OSI Approved :: BSD License", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Topic :: Internet :: WWW/HTTP :: Dynamic Content", + "Topic :: Software Development", + "Topic :: Software Development :: Libraries :: Application Frameworks", ] +dynamic = [ "version" ] dependencies = [ - "Django>=3.2", - "feincms3>=5.2.2", + "django>=3.2", + "feincms3>=5.2.2", ] -[project.optional-dependencies] -tests = [ - "coverage", - "requests", +optional-dependencies.tests = [ + "coverage", + "requests", ] - -[project.urls] -Homepage = "https://github.com/feinheit/feincms3-cookiecontrol/" +urls.Homepage = "https://github.com/feinheit/feincms3-cookiecontrol/" [tool.hatch.build] -include = ["feincms3_cookiecontrol/"] +include = [ "feincms3_cookiecontrol/" ] [tool.hatch.version] path = "feincms3_cookiecontrol/__init__.py" [tool.ruff] +target-version = "py39" + +fix = true +show-fixes = true extend-select = [ # pyflakes, pycodestyle - "F", "E", "W", + "F", + "E", + "W", # mmcabe "C90", # isort @@ -97,21 +102,12 @@ extend-ignore = [ # No line length errors "E501", ] -fix = true -show-fixes = true -target-version = "py39" - -[tool.ruff.isort] -combine-as-imports = true -lines-after-imports = 2 - -[tool.ruff.mccabe] -max-complexity = 15 - -[tool.ruff.per-file-ignores] -"*/migrat*/*" = [ +mccabe.max-complexity = 15 +per-file-ignores."*/migrat*/*" = [ # Allow using PascalCase model names in migrations "N806", # Ignore the fact that migration files are invalid module names "N999", ] +isort.combine-as-imports = true +isort.lines-after-imports = 2 diff --git a/src/gcm.js b/src/gcm.js index a59ee58..2ba2ebb 100644 --- a/src/gcm.js +++ b/src/gcm.js @@ -1,5 +1,6 @@ window.dataLayer = window.dataLayer || [] function gtag() { + // biome-ignore lint/style: arguments is fine here. window.dataLayer.push(arguments) } gtag("consent", "default", { diff --git a/src/main.js b/src/main.js index 69f8201..7c9c2d1 100644 --- a/src/main.js +++ b/src/main.js @@ -5,22 +5,24 @@ import "./main.css" -const qs = (selector, node = document) => node.querySelector(selector), - qsa = (selector, node = document) => node.querySelectorAll(selector), - body = document.body, - sClassName = "className", - sTextContent = "textContent", - sInnerHTML = "innerHTML", - cookieName = "f3cc", - settings = window.f3ccData || JSON.parse(qs("#f3cc-data")[sTextContent]), - injectedScripts = {}, - providerKey = "f3cc-embed-providers" -let mainElementRef, banner, modify +const qs = (selector, node = document) => node.querySelector(selector) +const qsa = (selector, node = document) => node.querySelectorAll(selector) +const body = document.body +const sClassName = "className" +const sTextContent = "textContent" +const sInnerHTML = "innerHTML" +const cookieName = "f3cc" +const settings = window.f3ccData || JSON.parse(qs("#f3cc-data")[sTextContent]) +const injectedScripts = {} +const providerKey = "f3cc-embed-providers" +let mainElementRef +let banner +let modify const crel = (tagName, attributes = null, children = []) => { const dom = document.createElement(tagName) if (attributes) { - for (let [name, value] of Object.entries(attributes)) { + for (const [name, value] of Object.entries(attributes)) { if (name.startsWith("data-")) dom.setAttribute(name, value) else dom[name] = value } @@ -87,7 +89,7 @@ const renderModify = () => { const loc = window.location if ( settings.buttonModify && - (!ppu || ppu == `${loc.protocol}//${loc.host}${loc.pathname}`) + (!ppu || ppu === `${loc.protocol}//${loc.host}${loc.pathname}`) ) { modify = crel("a", { [sClassName]: "f3cc-button modify", @@ -112,17 +114,17 @@ const setCookie = (value) => { const getCookie = () => { const prefix = `${cookieName}=` - for (let cookie of document.cookie.split("; ")) { + for (const cookie of document.cookie.split("; ")) { if (cookie.startsWith(prefix)) return decodeURIComponent(cookie.substring(prefix.length)) } } -const sAll = "all", - sEssential = "essential" +const sAll = "all" +const sEssential = "essential" const isKnownCookieValue = () => { const c = getCookie() - return sAll == c || sEssential == c + return sAll === c || sEssential === c } const getConsentToAll = () => { @@ -145,13 +147,13 @@ const onAccept = (accept) => (e) => { renderAcceptedEmbeds() injectAcceptedScripts() window.dispatchEvent( - new Event(`f3cc_consent_${accept ? "granted" : "denied"}`) + new Event(`f3cc_consent_${accept ? "granted" : "denied"}`), ) } const injectAcceptedScripts = () => { if (getConsentToAll()) { - for (let cookie of settings.cookies) { + for (const cookie of settings.cookies) { let node = injectedScripts[cookie.name] if (!node) { injectedScripts[cookie.name] = node = crel("div") @@ -171,27 +173,26 @@ const mainElement = () => { return mainElementRef } -const _lsFallback = {}, - _lsSet = (key, value) => { - try { - window.localStorage.setItem(key, JSON.stringify(value)) - } catch (e) { - _lsFallback[key] = value - } - }, - _lsGet = (key) => { - try { - return JSON.parse(window.localStorage.getItem(key)) - } catch (e) { - return _lsFallback[key] - } +const _lsFallback = {} +const _lsSet = (key, value) => { + try { + window.localStorage.setItem(key, JSON.stringify(value)) + } catch (_e) { + _lsFallback[key] = value + } +} +const _lsGet = (key) => { + try { + return JSON.parse(window.localStorage.getItem(key)) + } catch (_e) { + return _lsFallback[key] } +} const renderAcceptedEmbeds = (window.f3ccRenderEmbeds = () => { const providers = _lsGet(providerKey) || [] - const embedNodes = qsa(".f3cc-embed") - embedNodes.forEach((node) => { + for (const node of qsa(".f3cc-embed")) { const template = qs("template", node) const nodesProvider = node.dataset.provider @@ -201,13 +202,13 @@ const renderAcceptedEmbeds = (window.f3ccRenderEmbeds = () => { node.closest(".f3cc").replaceWith(clone) } } - }) + } }) const initEmbedClickListener = () => { body.addEventListener("click", (e) => { const button = e.target.closest(".f3cc-button") - const node = button && button.closest(".f3cc-embed") + const node = button?.closest(".f3cc-embed") if (button && node) { e.preventDefault() const providers = _lsGet(providerKey) || []