Skip to content

Instantly share code, notes, and snippets.

@mohemohe
Last active September 7, 2018 05:35
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mohemohe/194aaf60448a0aafd3ff26b38d6160f8 to your computer and use it in GitHub Desktop.
Save mohemohe/194aaf60448a0aafd3ff26b38d6160f8 to your computer and use it in GitHub Desktop.
πŸ‘€
// ==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