Commit e4abc318 authored by Tobias Zeumer's avatar Tobias Zeumer
Browse files

Twitter: Highlight promoted tweets - 0.0.2

parent 2319b139
// ==UserScript==
// @name Twitter: Highlight promoted tweets
// @namespace https://collaborating.tuhh.de/tobias.zeumer/Tampermonkey/
// @version 0.0.1
// @version 0.0.2
// @updateURL https://collaborating.tuhh.de/tobias.zeumer/Tampermonkey/raw/master/www/twitter/Twitter_-_Highlight_Promoted_Tweets.user.js xxx
// @description Promoted tweets are far to similar to regular tweets. Make them red!
// @description Promoted tweets are far to similar to regular tweets. Make them red! (Test only; bad implementation)
// @author Tobias Zeumer
// @match https://*twitter.com/*
// @grant none
......@@ -11,19 +11,55 @@
(function() {
'use strict';
// @see: https://dom.spec.whatwg.org/#interface-mutationobserver
// @see: https://medium.com/better-programming/js-mutationobserver-1d7aed479da2
MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
var observer = new MutationObserver(function(mutations, observer) {
//console.log(mutations, observer);
mutations.forEach(function(mutation) {
//console.log(mutation);
// Check each added node for promo (well, this is @todo ...)
if (mutation.type === 'childList') {
//mutation.addedNodes.forEach(function(newNode) { ... }); - e.g. if is span etc.
filterTwitterPromo(mutation.addedNodes.NodeList);
}
});
});
// The closest "safe" node to the twitter timeline is main (?)
var obsTarget = document.querySelector('main');
var obsConfig = {
subtree: true,
childList: true,
attributes: false
}
observer.observe(obsTarget, obsConfig);
function filterTwitterPromo(target) {
target = document; //check later how best to manage
var twitterTag = 'span';
var twitterTxt = 'Promoted';
var twitterTag = 'span';
var twitterTxt = 'Promoted';
var filter = Array.prototype.filter,
result = target.querySelectorAll(twitterTag),
filtered = filter.call( result, function( node ) {
return RegExp(twitterTxt).test(node.textContent);
});
filtered.forEach(function(element) {
let article = element.closest('article');
if(article !== null) {
article.style.backgroundColor = 'red';
console.log('Tampermonkey - Twitter: Highlight promoted tweets. Found "Promoted"!')
}
});
}
var filter = Array.prototype.filter,
result = document.querySelectorAll(twitterTag),
filtered = filter.call( result, function( node ) {
return RegExp(twitterTxt).test(node.textContent);
});
console.log('Found "Promoted" Tweets: ' + filtered.length.toString());
filtered.forEach(function(element) {
element.closest('article').style.backgroundColor = 'red';
});
// on page load
filterTwitterPromo(obsTarget);
})();
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment