Last active
February 12, 2018 01:58
-
-
Save chadlavi/f5ca94ccd1aafed21d1e1e250dc954e0 to your computer and use it in GitHub Desktop.
open tech crunch links in new tabs
This file contains hidden or 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 techcrunch open article in new tab | |
// @namespace https://gist.github.com/chadlavi/f5ca94ccd1aafed21d1e1e250dc954e0 | |
// @downloadURL https://gist.github.com/chadlavi/f5ca94ccd1aafed21d1e1e250dc954e0/raw/techcrunch-open-new-tab.user.js | |
// @updateURL https://gist.github.com/chadlavi/f5ca94ccd1aafed21d1e1e250dc954e0/raw/techcrunch-open-new-tab.user.js | |
// @version 1.2 | |
// @description Open tech crunch articles in new tabs | |
// @author You | |
// @match *techcrunch.com/* | |
// @grant none | |
// ==/UserScript== | |
/* jshint -W097 */ | |
'use strict'; | |
// open all links in a new tab | |
var links = document.getElementsByTagName('a'); | |
for (var j=0; j<links.length; j++) { | |
links[j].setAttribute('target', '_blank'); | |
links[j].setAttribute('rel', 'nofollow noreferrer'); | |
} | |
//but make the logo link open in the same tab | |
document.getElementsByClassName('logo-link')[0].setAttribute('target', '_self'); | |
//and make pagination links open in the same tab | |
var pageLinks = document.getElementsByClassName("pagination")[0].getElementsByTagName("a"); | |
for (var i=0; i<pageLinks.length; i++) { | |
pageLinks[i].setAttribute('target', '_self'); | |
} | |
//and remove dumb articles that are about tech crunch or their events, which are not news | |
var r=0; | |
var nono=['disrupt ny', 'disrupt ny', 'disrupt sf', 'disrupt sf', 'disrupt ticket', 'disrupt london', 'disrupt new york','disrupt san francisco', 'disrupt ticket', 'techcrunch', 'join us at', 'join us at', 'gillmor gang', 'gillmor gang', 'include office hours', 'at disrupt', 'at disrupt']; | |
var b = document.getElementsByClassName("river-block"); | |
for (var i=0; i<b.length; i++) { | |
var h=b[i].getElementsByTagName('h2')[0].getElementsByTagName('a')[0]; | |
for (var j=0; j<nono.length; j++) { | |
if (h.innerHTML.toLowerCase().indexOf(nono[j]) > -1) { | |
b[i].style.display='none'; | |
r+=1; | |
} | |
} | |
} | |
console.log(r + ' items removed'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment