open all links in the new tab

except for the link in the same directory(the link whose web address are same before the last '/' as the current url)

目前为 2017-08-18 提交的版本。查看 最新版本

// ==UserScript==
// @name           open all links in the new tab
// @description    except for the link in the same directory(the link whose web address are same before the last '/' as the current url)
// @include        http://*
// @include        https://*
// @author         yechenyin
// @version        0.3
// @namespace 	   https://gf.qytechs.cn/users/3586-yechenyin
// @grant       	 GM_openInTab
// ==/UserScript==
function getAncestorLink(element) {
  while (element && element.nodeName != "A") {
    element = element.parentNode;
  }
  if (element.nodeName === "A")
    return element;
}

document.addEventListener('click', function(e) {
  var link = getAncestorLink(e.target);
  if (link && e.isTrusted && link.href && link.href.substr(0, link.href.lastIndexOf('/')) !== location.href.substr(0, location.href.lastIndexOf('/')))
    link.target = '_blank';
});

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址