HN Open In New Tab

Open Hacker News links in new tabs

// ==UserScript==
// @name         HN Open In New Tab
// @namespace    https://news.ycombinator.com/
// @version      0.1
// @description  Open Hacker News links in new tabs
// @author       ezist#7571
// @match        *://news.ycombinator.com/*
// @grant        none
// ==/UserScript==

const classes = ["storylink", "hnuser"];
const ids = ["me"];
classes.forEach(c => {
    let elements = document.getElementsByClassName(c);
    for (var i = 0; i < elements.length; i++) {elements[i].setAttribute("target", "_blank");}
});
ids.forEach(i => {
    let element = document.getElementById(i);
    if (typeof element !== "undefined" && element) element.setAttribute("target", "_blank");
});