Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
👀
// ==UserScript==
// @name maud.io NSFW
// @namespace net.ghippos.hide.nsfw.io.maud.mstdn
// @version 1.1
// @description FUCK TWITTER
// @author mohemohe <mohemohe@ghippos.net>
// @match https://mstdn.maud.io/*
// @grant none
// ==/UserScript==
class Mstdn {
constructor() {
this.mutationObserver = new MutationObserver(() => this.onUpdate());
}
start() {
this.mutationObserver.observe(document.body, {
childList: true,
subtree: true,
});
}
onUpdate() {
this.hookNSFW();
}
hookNSFW() {
const nsfwWarns = document.evaluate(`//span[text()='閲覧注意']`, document, null, XPathResult.ANY_TYPE, null);
let nsfwWarn;
for (;(nsfwWarn = nsfwWarns.iterateNext()) != null;) {
const nsfwWarnContainerElement = this.getNSFWWarnContainerElement(nsfwWarn);
if (!nsfwWarnContainerElement.classList || nsfwWarnContainerElement.classList.contains('nsfw-eye')) {
continue;
}
nsfwWarnContainerElement.classList.add('nsfw-eye');
nsfwWarnContainerElement.insertAdjacentHTML('afterbegin','<div style="position: absolute; bottom: 0; left: 0; z-index: 114514;">👀</div>');
}
}
getNSFWWarnContainerElement(element) {
return (
element.classList.contains('media-gallery') ?
element :
element.parentElement !== null ?
this.getNSFWWarnContainerElement(element.parentElement) :
{}
);
}
}
new Mstdn().start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.