open all links in the new tab except for the turn page link

except for the turn page link whose inner text is 'next', 'previous' and other page number)

目前為 2017-09-25 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name           open all links in the new tab except for the turn page link
// @description    except for the turn page link whose inner text is 'next', 'previous' and other page number)
// @include        http://*
// @include        https://*
// @author         yechenyin
// @version        0.5
// @namespace 	   https://greasyfork.org/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")
    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);
  if (link && link.href && !/^(\d+|Next|Prev|>|<|下一页|上一页|下一頁|上一頁|回首頁|次へ|前へ)$/.test(link.innerText) && !link.href.matched(exception))
    link.target = '_blank';
});