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-11-10 提交的版本。查看 最新版本

// ==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.6
// @namespace 	   https://gf.qytechs.cn/users/3586-yechenyin
// @grant       	 GM_openInTab
// ==/UserScript==
var exception = ['https://m.leiphone.com/page/'];
function getAncestorLink(element) {
  while (element && element.nodeName != "A") {
    element = element.parentNode;
  }
  if (element.nodeName === "A" && element.href && element.href.indexOf('http') === 0)
    return element;
}

String.prototype.matched = function(strings) {
  for (var i = 0; i < strings.length; i++) {
    if (typeof strings[i] == 'string' && this.indexOf(strings[i]) === 0)
      return true;
    else if (strings[i] instanceof RegExp && this.test(strings[i]))
      return true;
  }
  return false;
};

document.addEventListener('click', function(e) {
  var link = getAncestorLink(e.target);
  console.log(link.innerText, link.href);
  if (link && link.href && !/^(\d+|Next|Prev|>|<|下一页|上一页|下一頁|上一頁|回首頁|次へ|前へ)$/.test(link.innerText) && !link.href.matched(exception)) {
    window.open(link.href);
    e.preventDefault();
    e.stopPropagation();
    return false;
  }
});
document.body.innerHTML += '<script>' + `
window.addEventListener("beforeunload", function (e) {
    //debugger;
    return 'left?';
});
` + '</script>';

QingJ © 2025

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