Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add patch for long pronouns. #54

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions pronoun-assistant/pronoun-assistant.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ 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 = 13; // If the pronoun length is longer than this, we hide the excess by adding ellipsis.

function pronounWrapper(pronouns) {
return pronouns.replace(new RegExp(`(?<=.{${pronounWrapLimit}}).*`), "…")
}

// Keys: user IDs
// Values: either a list of DOM elements (specifically, the anchors to chat profiles)
Expand Down Expand Up @@ -120,7 +125,7 @@ function showPronounsForChat($element, pronouns) {
if (pronouns == "") {
return;
}

addPronounsToChatSignatures($element, pronouns);

// After clicking the signature (to show the chat profile popup), *sometimes*
Expand All @@ -138,7 +143,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 = '<span class="name">' + usernameElement.innerHTML + '</span><br/>'
+ '<span class="pronouns"> ' + pronouns + '</span>';
+ '<span class="pronouns"> ' + pronounWrapper(pronouns) + '</span>';
});
}

Expand Down Expand Up @@ -167,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 {
Expand All @@ -177,8 +182,8 @@ function showPronouns($element, pronouns) {
break;
$element = $nextElement;
} while (true);
$element.after($('<span class="pronouns"> ' + pronouns + '</span>'));

$element.after($('<span class="pronouns"> ' + pronounWrapper(pronouns) + '</span>'));
}

// Check text (obtained from the user's 'about me' in their chat profile or Q&A profile) for pronoun indicators
Expand Down Expand Up @@ -292,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));
Expand Down