ryenus / HN NewTab

// ==UserScript==
// @name         HN NewTab
// @namespace    ryenus.toys
// @version      0.1
// @description  Open Hacker News links in new tabs
// @copyright    2014+ (https://github.com/ryenus)
// @match        https://news.ycombinator.com/*
// @grant        none
// ==/UserScript==

(function() {
  var filters = ['a',
    'not([onclick])',
    'not([target])',
    'not([class*=pocket])',
    'not([href^="#"])',
    'not([href^=mailto])',
    'not([href^=logout])'];
  Array.from(document.querySelectorAll(filters.join(':')), function(a) {
    a.setAttribute('target', '_blank');
    a.setAttribute('rel', 'noopener noreferrer');
  });
})();