Skip to content

Commit

Permalink
Merge branch 'main' into 61-search-for-pronounspage-link-in-all-fields
Browse files Browse the repository at this point in the history
  • Loading branch information
nachtjasmin authored Aug 1, 2023
2 parents 564c04d + 5cc45f5 commit 87aef3e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/content_scripts/protoots.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions src/libs/domhelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,26 @@ 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) {
if (typeof window === "undefined" || !window.DOMParser) {
const replacements = {
"&": "&",
""": '"',
"&lt;": "<",
"&gt;": ">",
"&nbsp;": "",
};
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;
}
6 changes: 5 additions & 1 deletion src/libs/pronouns.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sanitizeHtml from "sanitize-html";
import { allKnownPronouns } from "./generated/pronouns/index.js";
import { htmlDecode } from "./domhelpers.js";

const fieldMatchers = [/\bpro.*nouns?\b/i, /\bpronomen\b/i, /(i )?go(es)? by/i];
const knownPronounUrls = [
Expand Down Expand Up @@ -211,9 +212,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;
}
Expand Down
1 change: 0 additions & 1 deletion src/styles/proplate.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 87aef3e

Please sign in to comment.