From a4435aa3182f287c2b594d7fe582876d3cfd884e Mon Sep 17 00:00:00 2001 From: Little Monkey <106759534+PlaceReporter99@users.noreply.github.com> Date: Tue, 26 Sep 2023 16:27:45 +0100 Subject: [PATCH 1/2] Update pronoun-assistant.user.js --- pronoun-assistant/pronoun-assistant.user.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pronoun-assistant/pronoun-assistant.user.js b/pronoun-assistant/pronoun-assistant.user.js index b21c63d..4d0f1ac 100644 --- a/pronoun-assistant/pronoun-assistant.user.js +++ b/pronoun-assistant/pronoun-assistant.user.js @@ -68,6 +68,16 @@ let pronounListRegex = new RegExp('\\b((' + allPronouns + ')(\\s*/\\s*(' + allPr let myPronounIsRegex = /(https?:\/\/)?(my\.)?pronoun\.is\/([\w/]+)/i; let explicitPronounsRegex = /pronouns:\s*([^.\n)\]}<]*)(\.|\n|\)|]|}|<|$)/im; let unlikelyCombinations = ["her/his", "her/him", "he/she"]; +let pronounWrapLimit = 10; // If the pronoun length is longer than this, we hide the pronouns in a details box. + +function pronounWrapper(pronouns) { + if (pronouns.length > pronounWrapLimit) { // It's too long so it's wrapped in a details box. + return "
Pronouns" + pronouns + "
"; + } + else { // Horray, we don't need to do anything! + return pronouns; + } +} // Keys: user IDs // Values: either a list of DOM elements (specifically, the anchors to chat profiles) @@ -138,7 +148,7 @@ function addPronounsToChatSignatures($element, pronouns) { // The element might contain both a tiny and a full signature $element.find("div.username").each(function (index, usernameElement) { usernameElement.innerHTML = '' + usernameElement.innerHTML + '
' - + ' ' + pronouns + ''; + + ' ' + pronounWrapper(pronouns) + ''; }); } @@ -178,7 +188,7 @@ function showPronouns($element, pronouns) { $element = $nextElement; } while (true); - $element.after($(' ' + pronouns + '')); + $element.after($(' ' + pronounWrapper(pronouns) + '')); } // Check text (obtained from the user's 'about me' in their chat profile or Q&A profile) for pronoun indicators From 9c4342076df322f3228fbf37d704f68d87a33fe5 Mon Sep 17 00:00:00 2001 From: Little Monkey <106759534+PlaceReporter99@users.noreply.github.com> Date: Tue, 26 Sep 2023 17:29:01 +0100 Subject: [PATCH 2/2] patch time --- pronoun-assistant/pronoun-assistant.user.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/pronoun-assistant/pronoun-assistant.user.js b/pronoun-assistant/pronoun-assistant.user.js index 4d0f1ac..d1e5e96 100644 --- a/pronoun-assistant/pronoun-assistant.user.js +++ b/pronoun-assistant/pronoun-assistant.user.js @@ -68,15 +68,10 @@ let pronounListRegex = new RegExp('\\b((' + allPronouns + ')(\\s*/\\s*(' + allPr let myPronounIsRegex = /(https?:\/\/)?(my\.)?pronoun\.is\/([\w/]+)/i; let explicitPronounsRegex = /pronouns:\s*([^.\n)\]}<]*)(\.|\n|\)|]|}|<|$)/im; let unlikelyCombinations = ["her/his", "her/him", "he/she"]; -let pronounWrapLimit = 10; // If the pronoun length is longer than this, we hide the pronouns in a details box. +let pronounWrapLimit = 13; // If the pronoun length is longer than this, we hide the excess by adding ellipsis. function pronounWrapper(pronouns) { - if (pronouns.length > pronounWrapLimit) { // It's too long so it's wrapped in a details box. - return "
Pronouns" + pronouns + "
"; - } - else { // Horray, we don't need to do anything! - return pronouns; - } + return pronouns.replace(new RegExp(`(?<=.{${pronounWrapLimit}}).*`), "…") } // Keys: user IDs @@ -130,7 +125,7 @@ function showPronounsForChat($element, pronouns) { if (pronouns == "") { return; } - + addPronounsToChatSignatures($element, pronouns); // After clicking the signature (to show the chat profile popup), *sometimes* @@ -177,7 +172,7 @@ function showPronouns($element, pronouns) { if (pronouns == "" || $element.siblings(".pronouns").length != 0) { return; } - + // Make sure the pronouns don't end up between the username and the diamond // or staff/mod labels do { @@ -187,7 +182,7 @@ function showPronouns($element, pronouns) { break; $element = $nextElement; } while (true); - + $element.after($(' ' + pronounWrapper(pronouns) + '')); } @@ -302,7 +297,7 @@ const selector = "div.user-details > a, a.comment-user"; } $userElements.each(function() { decorate($(this)); }); - + // Make sure new answers / comments receive the same treatment waitForKeyElements(selector, function(jNode) { decorate($(jNode));