Last active
September 1, 2018 04:20
-
-
Save mohemohe/e316cb7b7e9674c06bc6eb2f84e329a3 to your computer and use it in GitHub Desktop.
プロモツイート非表示 user js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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