Skip to content

Instantly share code, notes, and snippets.

@sorz
Forked from fdb713/twitter.mute.js
Last active November 7, 2015 08:29
Show Gist options
  • Save sorz/93fe7400cd50d2a3ee0c to your computer and use it in GitHub Desktop.
Save sorz/93fe7400cd50d2a3ee0c to your computer and use it in GitHub Desktop.
mute tweets containing specific keyword.
// 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