Commit 3df3fc63 authored by Tobias Zeumer's avatar Tobias Zeumer
Browse files

Reddit: Highlight promo in red (a bit)

parent b996f418
......@@ -12,6 +12,7 @@ Sofern Tampermonkey installiert ist, sollten die Scripts direkt per Click instal
* [TUB TORE: Fehlende DE-Übersetzungen](https://collaborating.tuhh.de/tobias.zeumer/Tampermonkey/raw/master/tub/tore/TUB-Tore_-_Provide-Missing-Translations-DE.user.js
## WWW (Sonstiges)
* [Reddit-Promoted](https://collaborating.tuhh.de/tobias.zeumer/Tampermonkey/raw/master/www/twitter/Reddit_-_Highlight_Promoted_Posts.user.js)
* [Twitter-Timeline](https://collaborating.tuhh.de/tobias.zeumer/Tampermonkey/raw/master/www/twitter/Twitter_-_Highlight_Promoted_Tweets.user.js)
# Changelog
......
// ==UserScript==
// @name Reddit: Highlight promoted tweets
// @namespace https://collaborating.tuhh.de/tobias.zeumer/Tampermonkey/
// @version 0.0.3
// @updateURL https://collaborating.tuhh.de/tobias.zeumer/Tampermonkey/-/raw/master/www/reddit/Reddit_-_Highlight_Promoted_Posts.user.js xxx
// @description Promoted posts are far to similar to regular posts. Make them red! (Test only; bad implementation)
// @author Tobias Zeumer
// @match https://www.reddit.com/
// @grant none
// ==/UserScript==
(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.
filterRedditPromo(mutation.addedNodes.NodeList);
}
});
});
// The closest "safe" node to the twitter timeline is main (?)
//var obsTarget = document.querySelector('main'); // Tampermonkey exits with "not of type node"...?
var obsTarget = document;
var obsConfig = {
subtree: true,
childList: true,
attributes: false
}
observer.observe(obsTarget, obsConfig);
function filterRedditPromo(target) {
target = document; //check later how best to manage
var redditTag = 'span';
var redditTxt = 'promoted';
var filter = Array.prototype.filter,
result = target.querySelectorAll(redditTag),
filtered = filter.call( result, function( node ) {
return RegExp(redditTxt).test(node.textContent);
});
filtered.forEach(function(element) {
element.style.backgroundColor = 'red';
let article = element.closest('div[tabindex="-1"');
if(article !== null) {
article.style.backgroundColor = 'red';
console.log('Tampermonkey - Reddit: Highlight promoted post. Found "Promoted"!')
}
});
}
// on page load
filterRedditPromo(obsTarget);
})();
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