Irreverent Anthropoid
kiwifarms.net
- Joined
- Feb 2, 2019
Not sure where programming stuff goes, so move/delete as necessary.
Anyway, I had a bit of spare time today and decided to try my hand at writing a chrome extension to translate troonspeak into something more reality based.
Figured it might be of curiosity to those who have thought about doing such a thing and the good citizens here might get a chuckle out of the output.
Naturally something like this would never approved for any of the browser stores, so if you want to try it out you'll need to do the following in whatever flavour of chromium you are using.
manifest.json - This describes the extension and what operations it will perform.
detroonifier.js - This is the script which performs the substitutions.
It's all fairly straightforward, given a list of substitution values we do the following.
On load the current document body is searched for text content in elements, the substitutions are performed and if the element text has changed then the element is updated. The replacement function "demonsBegone" performs a case-insensitive replacement but attempts to keep the initial characters capitalization.
An observer is then set up to watch for updates to the DOM and for elements updated the above is applied. The observer is disabled while it performs its updates, otherwise it would trigger itself. This is needed for ajax sites like Twitter/X which bring in content after the initial load.
It is by no means production ready code, just a little gizmo to play around with.
Hopefully it might be of help to anyone looking at playing with the WebExtensions API.
back to lurking with me.
Anyway, I had a bit of spare time today and decided to try my hand at writing a chrome extension to translate troonspeak into something more reality based.
Figured it might be of curiosity to those who have thought about doing such a thing and the good citizens here might get a chuckle out of the output.
Naturally something like this would never approved for any of the browser stores, so if you want to try it out you'll need to do the following in whatever flavour of chromium you are using.
- Create a folder for the extension.
- Copy the files "manifest.json" and "detroonifier.js".
They'll follow later in the post. - Off to about:extensions in the browser address bar with you.
- Enable developer mode.
- Then use the "Load Unpacked" button to bring the extension in.
- And give it a try. The transgender page on wikiphedia is a good sample.
manifest.json - This describes the extension and what operations it will perform.
Here we calling a content_script on all urls, with the script to be executed supplied in the detroonifier.js{
"manifest_version": 2,
"name": "Detroonifier",
"version": "1.0",
"description": "An extension to banish the transcult nonsense.",
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["detroonifier.js"]
}
]
}
detroonifier.js - This is the script which performs the substitutions.
const madnessToSanity = [
["cis-", "real-"],
["cismale", "real male"],
["cis male", "real male"],
["cisman", "real man"],
["cis man", "real man"],
["cismen", "real men"],
["cis men", "real men"],
["cisfemale", "real female"],
["cis female", "real female"],
["cis-female", "real-female"],
["ciswoman", "real woman"],
["cis woman", "real woman"],
["ciswomen", "real women"],
["cisgender", "real gender"],
["cis gender", "real gender"],
["cis-gender", "real gender"],
["cissexual", "real sex"],
["cisnormativity", "reality"],
["trans-", "pretend-"],
["transmale", "pretend male"],
["trans male", "pretend male"],
["trans-male", "pretend male"],
["transman", "pretend man"],
["trans man", "pretend man"],
["trans-man", "pretend man"],
["transmen", "pretend men"],
["trans men", "pretend men"],
["trans-men", "pretend men"],
["transfemale", "pretend female"],
["trans female", "pretend female"],
["trans-female", "pretend female"],
["transwoman", "pretend woman"],
["trans woman", "pretend woman"],
["trans-woman", "pretend woman"],
["transwomen", "pretend women"],
["trans women", "pretend women"],
["trans-women", "pretend women"],
["transgender", "pretend"],
["transphobia", "sanity"],
["misgendering", "calling a spade a spade"],
["misgender", "point out reality to"],
[" cis ", " real "],
[" trans ", " pretend "],
["womyn", "women"],
];
const demonsBegone = (toSanity) => {
madnessToSanity.forEach((r) => {
const re = new RegExp(r[0], "gi");
toSanity = toSanity.replace(re, (match) => {
let isUpper = match[0] === match[0].toUpperCase();
return isUpper ? r[1][0].toUpperCase() + r[1].slice(1) : r[1];
});
});
return toSanity;
}
const performExorcism = (node) => {
node = node || document.body;
var childs = node.childNodes, i = 0;
while (node = childs ) {
if (node.nodeType == 3) {
const newContent = demonsBegone(node.textContent);
if (newContent != node.textContent) {
node.textContent = newContent;
}
} else {
performExorcism(node);
}
i++;
}
}
let observer = undefined;
const observerProps = {
attributes: false,
characterData: false,
childList: true,
subtree: true
};
const callback = (mutationsList) => {
observer.disconnect();
for (var mutation of mutationsList) {
if (mutation.type == "childList" && mutation.addedNodes) {
for (varnode of mutation.addedNodes)
{
performExorcism(mutation.node);
}
}
}
observer.observe(document.body, observerProps);
};
performExorcism(document.body)
observer = new MutationObserver(callback);
observer.observe(document.body, observerProps);
It's all fairly straightforward, given a list of substitution values we do the following.
On load the current document body is searched for text content in elements, the substitutions are performed and if the element text has changed then the element is updated. The replacement function "demonsBegone" performs a case-insensitive replacement but attempts to keep the initial characters capitalization.
An observer is then set up to watch for updates to the DOM and for elements updated the above is applied. The observer is disabled while it performs its updates, otherwise it would trigger itself. This is needed for ajax sites like Twitter/X which bring in content after the initial load.
It is by no means production ready code, just a little gizmo to play around with.
Hopefully it might be of help to anyone looking at playing with the WebExtensions API.
back to lurking with me.