Skip to content

Instantly share code, notes, and snippets.

@chadlavi
Last active February 12, 2018 01:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chadlavi/f5ca94ccd1aafed21d1e1e250dc954e0 to your computer and use it in GitHub Desktop.
Save chadlavi/f5ca94ccd1aafed21d1e1e250dc954e0 to your computer and use it in GitHub Desktop.
open tech crunch links in new tabs
// ==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&nbsp;ny', 'disrupt sf', 'disrupt&nbsp;sf', 'disrupt ticket', 'disrupt london', 'disrupt new york','disrupt san francisco', 'disrupt&nbsp;ticket', 'techcrunch', 'join us at', 'join&nbsp;us&nbsp;at', 'gillmor gang', 'gillmor&nbsp;gang', 'include office hours', 'at&nbsp;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