aboutsummaryrefslogtreecommitdiff
path: root/.local
diff options
context:
space:
mode:
authorLuca Matei Pintilie <luca@lucamatei.com>2023-11-25 10:03:55 +0000
committerLuca Matei Pintilie <luca@lucamatei.com>2023-11-25 10:03:55 +0000
commit759f0406608464cb7514914de9119d4eaff2eaac (patch)
treeb8c22169f7cf3e7562135a69e2f3154bbbe4da1a /.local
parent4df2b9df655ac792058611e3d8a27ffdfdc1c846 (diff)
downloaddotfiles-759f0406608464cb7514914de9119d4eaff2eaac.tar
dotfiles-759f0406608464cb7514914de9119d4eaff2eaac.tar.gz
dotfiles-759f0406608464cb7514914de9119d4eaff2eaac.tar.bz2
dotfiles-759f0406608464cb7514914de9119d4eaff2eaac.tar.lz
dotfiles-759f0406608464cb7514914de9119d4eaff2eaac.tar.xz
dotfiles-759f0406608464cb7514914de9119d4eaff2eaac.tar.zst
dotfiles-759f0406608464cb7514914de9119d4eaff2eaac.zip
Remove sanitize in favor of https://hg.sr.ht/~aninternettroll/sanitize
Diffstat (limited to '.local')
-rwxr-xr-x.local/bin/sanitize59
1 files changed, 0 insertions, 59 deletions
diff --git a/.local/bin/sanitize b/.local/bin/sanitize
deleted file mode 100755
index dbde059..0000000
--- a/.local/bin/sanitize
+++ /dev/null
@@ -1,59 +0,0 @@
-#!/usr/bin/env -S deno run --allow-read --ext ts
-// vi: ft=typescript
-import {
- DOMParser,
- Element,
-} from "https://deno.land/x/deno_dom@v0.1.41-alpha-artifacts/deno-dom-wasm.ts";
-
-function sanitizeLink(link: string): string {
- try {
- let url = new URL(link);
- url.searchParams.delete("tracking_data");
- url.searchParams.delete("utm_source");
- url.searchParams.delete("utm_medium");
- url.searchParams.delete("utm_campaign");
- if (
- url.host.includes("safelinks.protection.outlook.com") &&
- url.searchParams.has("url")
- ) {
- url = new URL(url.searchParams.get("url")!);
- }
- return url.href;
- } catch (err) {
- console.error(err);
- return link;
- }
-}
-
-function sanitizeEl(el: Element) {
- const href = el.getAttribute("href");
- if (href) {
- el.setAttribute("href", sanitizeLink(href));
- }
- const src = el.getAttribute("src");
- if (src) {
- el.setAttribute("src", sanitizeLink(src));
- }
-}
-
-function sanitize(html: string): string {
- const document = new DOMParser().parseFromString(html, "text/html");
-
- const aTags = document?.querySelectorAll("a");
- aTags?.forEach((a) => sanitizeEl(a as Element));
- const imgTags = document?.querySelectorAll("a");
- imgTags?.forEach((img) => sanitizeEl(img as Element));
-
- if (document?.documentElement?.outerHTML) {
- return document.documentElement.outerHTML;
- } else throw new Error("No document available");
-}
-
-if (import.meta.main) {
- let file: string;
- const [path] = Deno.args;
- if (!path || path === "-") {
- file = await new Response(Deno.stdin.readable).text();
- } else file = await Deno.readTextFile(path);
- console.log(sanitize(file));
-}