Created
March 29, 2020 21:59
-
-
Save rakslice/552faf61b5afb5687824c1ef6bf7a8e4 to your computer and use it in GitHub Desktop.
userscript to hide articles with the 'opinion' label on google news
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 google news opinion remover | |
// @namespace http://rakslice.net/userscripts/google-news-opinion-remover | |
// @version 0.1 | |
// @description remove google news opinion articles | |
// @author You | |
// @match https://news.google.com/* | |
// @grant none | |
// @require http://code.jquery.com/jquery-3.4.1.min.js | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
var ourJQuery = jQuery; | |
jQuery.noConflict(); | |
function processPage() { | |
var articles = ourJQuery('article'); | |
var i; | |
var j; | |
for (i = 0; i < articles.length; i++) { | |
var article = articles[i]; | |
var isOpinion = false; | |
var spans = ourJQuery('span', article); | |
for (j = 0; j < spans.length; j++) { | |
var span = spans[j]; | |
if (ourJQuery(span).text().toLowerCase() == "opinion") { | |
isOpinion = true; | |
break; | |
} | |
} | |
if (isOpinion) { | |
var links = ourJQuery('a', article); | |
var linkText = ""; | |
for (j = 0; j < links.length; j++) { | |
var link = links[j]; | |
linkText = ourJQuery(link).text(); | |
if (linkText != "") { | |
break; | |
} | |
} | |
console.log("opinion label match", linkText, article); | |
ourJQuery(article).remove(); | |
} | |
} | |
} | |
processPage(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment