-
-
Save sorz/93fe7400cd50d2a3ee0c to your computer and use it in GitHub Desktop.
mute tweets containing specific keyword.
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
// origin: @ayanamist | |
// ==UserScript== | |
// @name Twitter Keyword Filter | |
// @namespace Twitter-Timeline-URL-Expand | |
// @description Replace t.co href of A tag with real url. | |
// @match https://twitter.com/ | |
// @version 1.1 | |
// ==/UserScript== | |
(function (window) { | |
var document = window.document; | |
var OneTimeTrigger = function (func, delay) { | |
var timerCountdown = 0; | |
return function() { | |
setTimeout(function() { | |
timerCountdown -= 1; | |
if (timerCountdown == 0) { | |
func(); | |
} | |
}, delay); | |
timerCountdown += 1; | |
}; | |
}; | |
var muteAll = function () { | |
Array.prototype.forEach.call(document.querySelectorAll(".js-tweet-text"), | |
function (node) { | |
var tweet = node.textContent; | |
if (tweet.match('ポスト') || tweet.match('#FilterR7Q')) { | |
$(node.parentNode.parentNode.parentNode).remove(); | |
} | |
}); | |
}; | |
var trigger = OneTimeTrigger(muteAll, 100); | |
var MutationObserver = window.MutationObserver ? window.MutationObserver : window.WebKitMutationObserver; | |
if (typeof MutationObserver !== "undefined") { | |
var observer = new MutationObserver(trigger); | |
observer.observe(document, { childList: true, subtree: true }); | |
} | |
else { | |
document.addEventListener("DOMNodeInserted", trigger, false); | |
document.addEventListener("DOMSubtreeModified", trigger, false); | |
} | |
muteAll() | |
})(window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment