Get rid of innerHTML usage

This commit is contained in:
Jasmin 2023-07-14 08:51:47 +02:00 committed by GitHub
parent f51b2e71fe
commit 60aae7b1a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 20 deletions

View file

@ -19,7 +19,7 @@ import {
waitForElement,
waitForElementRemoved,
} from "../libs/domhelpers";
import { addTypeAttribute, normaliseAccountName, sanitizePronouns } from "../libs/protootshelpers";
import { addTypeAttribute, normaliseAccountName } from "../libs/protootshelpers";
//before anything else, check whether we're on a Mastodon page
checkSite();
@ -197,7 +197,7 @@ async function addProplate(element) {
if (pronouns == "null" && !isLogging()) {
return;
}
proplate.innerHTML = sanitizePronouns(pronouns);
proplate.innerText = pronouns;
//TODO?: alt text
proplate.classList.add("protoots-proplate");
if (accountName == "jasmin@queer.group" || accountName == "vivien@queer.group") {

View file

@ -13,6 +13,7 @@ let conversationsCache;
* @param {string | undefined} dataID ID of the object being requested, in case cache misses.
* @param {string} accountName The account name, used for caching. Should have the "@" prefix.
* @param {string} type Type of data-id
* @returns {string} The pronouns if we have any, otherwise "null".
*/
export async function fetchPronouns(dataID, accountName, type) {
// log(`searching for ${account_name}`);

View file

@ -33,6 +33,7 @@ export async function extractFromStatus(status) {
pronouns = extractFromBio(note);
}
pronouns = sanitizePronouns(pronouns)
return pronouns;
}
@ -120,6 +121,24 @@ function sanitizePronounPageValue(val) {
return val;
}
/**
* Sanitizes the pronoun field by removing various long information parts.
* As of today, this just removes custom emojis from the field.
* If the passed string is not defined, null is returned.
*
* @param {string} str The input string.
* @returns {string|null} The sanitized string.
*/
function sanitizePronouns(str) {
if (!str) return null;
// Remove all custom emojis with the :shortcode: format.
str = str.replace(/:[\w_]+:/gi, "");
// Finally, remove leading and trailing whitespace.
return str.trim();
}
const knownPronouns = [
"ae",
"aer",

View file

@ -17,24 +17,6 @@ export function normaliseAccountName(name) {
return name;
}
/**
* Sanitizes the pronoun field by removing various long information parts.
* As of today, this just removes custom emojis from the field.
* If the passed string is not defined, an empty string is returned.
*
* @param {string} str The input string.
* @returns The sanitized string.
*/
export function sanitizePronouns(str) {
if (!str) return "";
// Remove all custom emojis with the :shortcode: format.
str = str.replace(/:[\w_]+:/gi, "");
// Finally, remove leading and trailing whitespace.
return str.trim();
}
/**
* Checks which type an element is and adds the according protoots-type attribute
* @param {HTMLElement} ActionElement