Last active
February 12, 2018 02:00
-
-
Save chadlavi/90c5e30998ccdfc989cd846949b570ed to your computer and use it in GitHub Desktop.
hacker news open links in new tabs
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 hackernews open link in new tab | |
// @namespace https://gist.github.com/chadlavi/90c5e30998ccdfc989cd846949b570ed | |
// @downloadURL https://gist.github.com/chadlavi/90c5e30998ccdfc989cd846949b570ed/raw/hackernews-open-link-new-tab.user.js | |
// @updateURL https://gist.github.com/chadlavi/90c5e30998ccdfc989cd846949b570ed/raw/hackernews-open-link-new-tab.user.js | |
// @version 1.2 | |
// @description hn open links in new tabs | |
// @author Chad Lavimoniere | |
// @match https://news.ycombinator.com/* | |
// @grant none | |
// ==/UserScript== | |
'use strict'; | |
var itemList = document.getElementsByClassName("athing"); | |
for (var j=0; j<itemList.length; j++) { | |
var allLinks = itemList[j].getElementsByTagName("a"); | |
for (var i=0; i < allLinks.length; i++) { | |
var thisLink = allLinks[i]; | |
if (thisLink.href.match(/http/i)) { | |
thisLink.setAttribute('target', '_blank'); | |
thisLink.setAttribute('rel', 'nofollow noreferrer'); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment