Pronoun Assistant v1.1
This commit is contained in:
parent
4895e666b9
commit
a0dc7dd5cb
|
@ -7,7 +7,7 @@
|
||||||
// @updateURL https://raw.githubusercontent.com/Glorfindel83/SE-Userscripts/master/pronoun-assistant/pronoun-assistant.user.js
|
// @updateURL https://raw.githubusercontent.com/Glorfindel83/SE-Userscripts/master/pronoun-assistant/pronoun-assistant.user.js
|
||||||
// @downloadURL https://raw.githubusercontent.com/Glorfindel83/SE-Userscripts/master/pronoun-assistant/pronoun-assistant.user.js
|
// @downloadURL https://raw.githubusercontent.com/Glorfindel83/SE-Userscripts/master/pronoun-assistant/pronoun-assistant.user.js
|
||||||
// @supportURL https://stackapps.com/questions/8440/pronoun-assistant
|
// @supportURL https://stackapps.com/questions/8440/pronoun-assistant
|
||||||
// @version 1.0
|
// @version 1.1
|
||||||
// @match *://chat.stackexchange.com/rooms/*
|
// @match *://chat.stackexchange.com/rooms/*
|
||||||
// @match *://chat.stackoverflow.com/rooms/*
|
// @match *://chat.stackoverflow.com/rooms/*
|
||||||
// @match *://chat.meta.stackexchange.com/rooms/*
|
// @match *://chat.meta.stackexchange.com/rooms/*
|
||||||
|
@ -15,7 +15,7 @@
|
||||||
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
|
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
|
||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
|
|
||||||
/* global $ */
|
/* global $, waitForKeyElements */
|
||||||
|
|
||||||
// NICETOHAVE: on main/meta sites as well; right now, there are very few users
|
// NICETOHAVE: on main/meta sites as well; right now, there are very few users
|
||||||
// who have indicated their pronouns in their main/meta profile.
|
// who have indicated their pronouns in their main/meta profile.
|
||||||
|
@ -38,17 +38,17 @@ GM_addStyle(`
|
||||||
|
|
||||||
// List of pronouns to look out for
|
// List of pronouns to look out for
|
||||||
let allPronouns = [
|
let allPronouns = [
|
||||||
"he", "him", "his",
|
"him", "his",
|
||||||
"she", "her",
|
"she", "her?", // that covers 'he' as well
|
||||||
"they", "them", "their",
|
"they", "them", "their",
|
||||||
"ze", "hir", "zir",
|
"ze", "hir", "zir",
|
||||||
"xey", "xem", "xyr"
|
"xey", "xem", "xyr"
|
||||||
];
|
].join("|");
|
||||||
// Regex to detect instances where users put the pronouns inside parentheses etc.,
|
let pronounListRegex = new RegExp('\\W*((' + allPronouns + ')(\\s*/\\s*(' + allPronouns + '))+)\\W*', 'i');
|
||||||
// e.g. (he/him)
|
let myPronounIsRegex = /(https?:\/\/)?(my\.)?pronoun\.is\/[\w/]+/i;
|
||||||
let pronounsComponent = /^[^\w\/]*([\w\/]+)[^\w\/]*$/;
|
let explicitPronounsRegex = /pronouns:\s*([^.]*)\./i;
|
||||||
|
|
||||||
// Keys: user IDs
|
// Keys: user IDs
|
||||||
// Values: either a list of DOM elements (specifically, the anchors to chat profiles)
|
// Values: either a list of DOM elements (specifically, the anchors to chat profiles)
|
||||||
// or a string with pronouns.
|
// or a string with pronouns.
|
||||||
var users = {};
|
var users = {};
|
||||||
|
@ -56,8 +56,9 @@ var users = {};
|
||||||
|
|
||||||
// Adds pronoun information to a user's 'signature' in chat.
|
// Adds pronoun information to a user's 'signature' in chat.
|
||||||
function showPronouns(element, pronouns) {
|
function showPronouns(element, pronouns) {
|
||||||
if (pronouns == "")
|
if (pronouns == "") {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
// the element might contain both a tiny and a full signature
|
// the element might contain both a tiny and a full signature
|
||||||
element.find("div.username").each(function (index, usernameElement) {
|
element.find("div.username").each(function (index, usernameElement) {
|
||||||
usernameElement.innerHTML = '<span class="name">' + usernameElement.innerHTML + '</span><br/>'
|
usernameElement.innerHTML = '<span class="name">' + usernameElement.innerHTML + '</span><br/>'
|
||||||
|
@ -65,31 +66,33 @@ function showPronouns(element, pronouns) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check the user's 'about' in their chat profile for pronouns (see above for the list)
|
// Check the user's 'about' in their chat profile for pronoun indicators
|
||||||
// joined by a forward slash.
|
|
||||||
//
|
|
||||||
// Examples of what would be detected:
|
|
||||||
// - "They/them"
|
|
||||||
// - "(he/him/his)"
|
|
||||||
// Examples of what would *not* be detected (yet):
|
|
||||||
// - "they / them"
|
|
||||||
function getPronouns(aboutMe) {
|
function getPronouns(aboutMe) {
|
||||||
for (let component of aboutMe.split(/\s+/)) {
|
// Link to Pronoun Island, e.g.
|
||||||
if (!component.includes("/"))
|
// http://my.pronoun.is/she
|
||||||
continue;
|
var match = myPronounIsRegex.exec(aboutMe);
|
||||||
let match = pronounsComponent.exec(component);
|
if (match != null) {
|
||||||
if (match == null)
|
return match[0];
|
||||||
continue;
|
|
||||||
var isOnlyPronouns = true;
|
|
||||||
for (let word of match[1].split("/")) {
|
|
||||||
if (!allPronouns.includes(word.toLowerCase())) {
|
|
||||||
isOnlyPronouns = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if (isOnlyPronouns)
|
|
||||||
return match[1];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Explicit pronouns specification, e.g.
|
||||||
|
// Pronouns: he/him.
|
||||||
|
// (the trailing dot is important)
|
||||||
|
match = explicitPronounsRegex.exec(aboutMe);
|
||||||
|
if (match != null) {
|
||||||
|
return match[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for pronouns (see above for the list) joined by a forward slash, e.g.
|
||||||
|
// she/her
|
||||||
|
// (he/him/his)
|
||||||
|
// they / them
|
||||||
|
match = pronounListRegex.exec(aboutMe);
|
||||||
|
if (match != null) {
|
||||||
|
return match[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
// No pronouns found
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue