Skip to content

Instantly share code, notes, and snippets.

@mohemohe
Last active September 1, 2018 04:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mohemohe/e316cb7b7e9674c06bc6eb2f84e329a3 to your computer and use it in GitHub Desktop.
Save mohemohe/e316cb7b7e9674c06bc6eb2f84e329a3 to your computer and use it in GitHub Desktop.
プロモツイート非表示 user js
// ==UserScript==
// @name プロモツイート非表示
// @namespace net.ghippos.delete.twitter.promo
// @version 1.1
// @description FUCK TWITTER
// @author mohemohe <mohemohe@ghippos.net>
// @match https://mobile.twitter.com/*
// @grant none
// ==/UserScript==
function onUpdate() {
hidePromotion("プロモーション");
hidePromotion("Promoted");
}
function hidePromotion(text) {
const promotions = document.evaluate(`//div[text()='${text}']`, document, null, XPathResult.ANY_TYPE, null);
let promotion;
for (;(promotion = promotions.iterateNext()) != null;) {
const promotionContainerElement = getPromotionContainerElement(promotion);
promotion.innerHTML = "";
promotionContainerElement.style.height = 0;
promotionContainerElement.style.padding = 0;
promotionContainerElement.style.margin = 0;
promotionContainerElement.style.overflow = "hidden";
}
}
function getPromotionContainerElement(element) {
return element.tagName.toLowerCase() === "article" ? element :
element.parentElement !== null ? getPromotionContainerElement(element.parentElement) :
{};
}
function start() {
const mutationObserver = new MutationObserver(onUpdate);
mutationObserver.observe(document.body, {
childList: true,
subtree: true,
});
}
start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment