From 0c8a516e7067f1b34fad7d3476b388e032290c71 Mon Sep 17 00:00:00 2001 From: Glorfindel Date: Mon, 30 Sep 2019 22:55:04 +0200 Subject: [PATCH] Pronoun Assistant v0.1 --- pronoun-assistant/pronoun-assistant.user.js | 87 +++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 pronoun-assistant/pronoun-assistant.user.js diff --git a/pronoun-assistant/pronoun-assistant.user.js b/pronoun-assistant/pronoun-assistant.user.js new file mode 100644 index 0000000..3c78af0 --- /dev/null +++ b/pronoun-assistant/pronoun-assistant.user.js @@ -0,0 +1,87 @@ +// ==UserScript== +// @name Stack Exchange Pronoun Assistant +// @namespace https://github.com/Glorfindel83/ +// @description Displays users' pronouns +// @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 +// @version 0.1 +// @match *://*.stackexchange.com/* +// @match *://*.stackoverflow.com/* +// @match *://*.superuser.com/* +// @match *://*.serverfault.com/* +// @match *://*.askubuntu.com/* +// @match *://*.stackapps.com/* +// @match *://*.mathoverflow.net/* +// @exclude *://api.stackexchange.com/* +// @exclude *://blog.*.com/* +// @exclude *://data.stackexchange.com/* +// @exclude *://elections.stackexchange.com/* +// @exclude *://openid.stackexchange.com/* +// @exclude *://stackexchange.com/* +// @grant none +// @require https://gist.github.com/raw/2625891/waitForKeyElements.js +// ==/UserScript== + +/* global $ */ + +let pronouns = [ + "he", "him", "his", + "she", "her", + "they", "them", + "ze", "hir", "zir", + "xey", "xem", "xyr" +]; +let pronounsComponent = /^[^\w\/]*([\w\/]+)[^\w\/]*$/; +var users = {}; + +function addInformation(element, information) { + if (information != "") { + element.append($("" + information + "")); + } +} + +if (window.location.host.startsWith("chat.")) { + waitForKeyElements("a.signature", function(jNode) { + let userID = jNode.attr("href").split("/users/")[1]; + if (!users.hasOwnProperty(userID)) { + users[userID] = []; + users[userID].push(jNode); + $.get("https://chat.stackexchange.com/users/thumbs/" + userID + "?showUsage=true", function(data) { + var information = ""; + if (data.user_message != null) { + // Check the user's 'about' in their chat profile for pronouns (see above for the list) + // 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 + for (let component of data.user_message.split(/\s+/)) { + if (!component.includes("/")) + continue; + var allPronouns = true; + for (let word of pronounsComponent.exec(component)[1].split("/")) { + if (!pronouns.includes(word.toLowerCase())) { + allPronouns = false; + break; + } + }; + if (allPronouns) { + information = component; + break; + } + } + } + users[userID].forEach(function (element) { + addInformation(element, information); + }); + users[userID] = information; + }); + } else if (typeof users[userID] == 'string') { + addInformation(jNode, users[userID]); + } else { + users[userID].push(jNode); + } + }); +}