Skip to content

Instantly share code, notes, and snippets.

@mxamber
Last active March 15, 2022 15:16
Show Gist options
  • Save mxamber/5be3eaddc2f06c2c834747a79d287e76 to your computer and use it in GitHub Desktop.
Save mxamber/5be3eaddc2f06c2c834747a79d287e76 to your computer and use it in GitHub Desktop.
Userscript that adds a "is a transphobe?" link to every user profile on Twitter to quickly look up a person's position on transgender rights before interacting with them.
// ==UserScript==
// @name Twitter Transphobe Search
// @namespace http://tampermonkey.net/
// @version 0.4
// @description Find trans-related tweets from any public user
// @author mxamber
// @match https://twitter.com/*
// @icon https://www.google.com/s2/favicons?domain=twitter.com
// @grant none
// ==/UserScript==
(function() {
'use strict';
function searchUrl(wordsArray, username) {
let returnUrl = "https://twitter.com/search?q=";
for(let i = 0; i < wordsArray.length; i++) {
returnUrl += wordsArray[i];
if(i != wordsArray.length - 1) {
returnUrl += "%20OR%20";
}
}
returnUrl += "%20from%3A" + username + "&src=typed_query";
return returnUrl;
}
function createLink(title, url, id, targetlink) {
let returnLink = document.createElement("a");
returnLink.href = url;
returnLink.setAttribute("style", "margin-left: 1em; font-weight: bold; font-family: 'sans', 'Sans-Serif', 'Sans'; text-decoration: none; color: rgb(29, 161, 242); font-size: small;");
returnLink.setAttribute("target", "_blank");
returnLink.setAttribute("id", id);
returnLink.innerHTML = title;
if(!document.querySelector("#" + id)) {
targetlink.parentNode.parentNode.appendChild(returnLink);
}
}
function addLink() {
if(document.querySelector("#transphobesearch_en") || document.querySelector("#transphobesearch_de")) {
return;
}
let regexTweet = /status\/\d+/i;
if(window.location.toString().match(regexTweet)) {
return;
}
let targetlink = document.querySelectorAll("a[href*='followers']:not([href*='followers_you_follow'])")[0];
if(!targetlink) {1
return;
}
let reserved = ["notifications", "explore", "home", "messages", "bookmarks", "search"];
let regexUser = /https?:\/\/(www\.)?twitter\.com\/([a-zA-Z0-9_-]*)/i;
let username = window.location.toString().match(regexUser)[2];
if(!username || reserved.indexOf(username) != -1) {
return;
}
// don't make it any longer or the end will be truncated in the search, that's why there's two parts for the English search
let searchterms_en = ["trans", "transgender", "transsexual", "gender-critical", "gender-crit", "terf", "transwoman", "transwomen", "transmen", "transman", "nonbinary", "non-binary", "\"non binary\""];
let searchterms_en2 = ["Chappelle", "%23IStandWithJKRowling", "Self-ID", "\"sex-based rights\"", "\"Magdalen Berns\"", "\"Maya Forstater\""];
let searchterms_de = ["trans", "transsexuell", "transgeschlechtlich", "Transfrau", "Transmann", "Transfrauen", "Transmänner", "nichtbinär", "nicht-binär", "Selbstbestimmungsgesetz"];
let searchurl_en = searchUrl(searchterms_en, username);
let searchurl_en2 = searchUrl(searchterms_en2, username);
let searchurl_de = searchUrl(searchterms_de, username);
createLink("Search for transphobia", searchurl_en, "transphobesearch_en", targetlink);
createLink ("(more)", searchurl_en2, "transphobesearch_en2", targetlink);
createLink ("(German)", searchurl_de, "transphobesearch_de", targetlink);
}
setInterval(addLink, 1500);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment