From 42b954f209fdc9914662307671342c2ed0e43c6d Mon Sep 17 00:00:00 2001 From: ItsVipra Date: Wed, 19 Jul 2023 11:54:59 +0200 Subject: [PATCH 1/4] add htmlDecode() to unescape special characters --- src/libs/domhelpers.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/libs/domhelpers.js b/src/libs/domhelpers.js index cbcef9e..27baca2 100644 --- a/src/libs/domhelpers.js +++ b/src/libs/domhelpers.js @@ -85,3 +85,13 @@ export function insertAfter(insertion, target) { //docs: https://developer.mozilla.org/en-US/docs/Web/API/Node/insertBefore#example_2 target.parentElement.insertBefore(insertion, target.nextSibling); } + +/** + * Turns HTML text into human-readable text + * @param {string} input HTML Text + * @returns {string} + */ +export function htmlDecode(input) { + const doc = new DOMParser().parseFromString(input, "text/html"); + return doc.documentElement.textContent; +} From bd14d190a2f757899eb795f618da186750af98a3 Mon Sep 17 00:00:00 2001 From: ItsVipra Date: Wed, 19 Jul 2023 11:55:18 +0200 Subject: [PATCH 2/4] add html decoding to pronoun sanitation --- src/libs/pronouns.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/libs/pronouns.js b/src/libs/pronouns.js index aacc82e..0f0a708 100644 --- a/src/libs/pronouns.js +++ b/src/libs/pronouns.js @@ -1,4 +1,5 @@ import sanitizeHtml from "sanitize-html"; +import { htmlDecode } from "./domhelpers.js"; const fieldMatchers = [/\bpro.*nouns?\b/i, /\bpronomen\b/i, /(i )?go(es)? by/i]; const knownPronounUrls = [ @@ -179,9 +180,12 @@ function sanitizePronouns(str) { // Remove trailing characters that are used as separators. str = str.replace(/[-| :/]+$/, ""); - // Finally, remove leading and trailing whitespace. + // Remove leading and trailing whitespace. str = str.trim(); + //Finally, turn escaped characters (e.g. &,>) back into their original form + str = htmlDecode(str); + // If the result is empty, return null, otherwise the empty string. return str === "" ? null : str; } From 58a8404a8d902ec55da993fe61da97d908e71b61 Mon Sep 17 00:00:00 2001 From: nachtjasmin Date: Sat, 22 Jul 2023 12:55:28 +0200 Subject: [PATCH 3/4] Add a fallback if DOMParser does not exist --- src/libs/domhelpers.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/libs/domhelpers.js b/src/libs/domhelpers.js index 27baca2..366f25c 100644 --- a/src/libs/domhelpers.js +++ b/src/libs/domhelpers.js @@ -92,6 +92,19 @@ export function insertAfter(insertion, target) { * @returns {string} */ export function htmlDecode(input) { + if (typeof window === "undefined" || !window.DOMParser) { + const replacements = { + "&": "&", + """: '"', + "<": "<", + ">": ">", + " ": "", + }; + for (const [html, text] of Object.entries(replacements)) input = input.replaceAll(html, text); + + return input; + } + const doc = new DOMParser().parseFromString(input, "text/html"); return doc.documentElement.textContent; } From 70e9d20d8e535b0a335330ee3611ccbb0a4fb4a9 Mon Sep 17 00:00:00 2001 From: Vipra Date: Tue, 1 Aug 2023 14:03:33 +0200 Subject: [PATCH 4/4] add title to proplate --- src/content_scripts/protoots.js | 2 +- src/styles/proplate.css | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/content_scripts/protoots.js b/src/content_scripts/protoots.js index dc83ac7..35345d7 100644 --- a/src/content_scripts/protoots.js +++ b/src/content_scripts/protoots.js @@ -215,7 +215,7 @@ async function addProplate(element) { return; } proplate.innerText = pronouns; - //TODO?: alt text + proplate.title = pronouns; proplate.classList.add("protoots-proplate"); if (contributorList.includes(accountName)) { //i think you can figure out what this does on your own diff --git a/src/styles/proplate.css b/src/styles/proplate.css index 0027552..a776d4a 100644 --- a/src/styles/proplate.css +++ b/src/styles/proplate.css @@ -4,7 +4,6 @@ border-radius: 0.25rem; margin-left: 0.5rem; display: inline-flex; - text-transform: lowercase; animation: proplate-fadein 0.15s linear; font-weight: 500;