🎉 欢迎访问GreasyFork.Org 镜像站!本镜像站由公众号【爱吃馍】搭建,用于分享脚本。联系邮箱📮

Greasy fork 爱吃馍镜像

Open all links in the new tab WITH exceptions

except for the turn page link whose inner text is 'next', 'previous' and other page numbers etc.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey, Greasemonkey или Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Userscripts.

За да инсталирате скрипта, трябва да инсталирате разширение като Tampermonkey.

За да инсталирате този скрипт, трябва да имате инсталиран скриптов мениджър.

(Вече имам скриптов мениджър, искам да го инсталирам!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

(Вече имам инсталиран мениджър на стиловете, искам да го инсталирам!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

// ==UserScript==
// @name           Open all links in the new tab WITH exceptions
// @description    except for the turn page link whose inner text is 'next', 'previous' and other page numbers etc.
// @include        http://*
// @include        https://*
// @exclude *.wikipedia.org*
// @exclude *greasyfork.org*
// @exclude *ezgif.com*
// @exclude *armorgames.com*
// @exclude http*://*/#
//
// @author         yechenyin, me:) (kliop)
// @version        1.0.0
// @namespace 	   https://greasyfork.org/users/3586-yechenyin
// @grant       	 GM_openInTab
// ==/UserScript==
(function() {
  "use strict";

  var exception = [/^https:\/\/www\.google\.\w+\/search/, 'https://m.leiphone.com/page/'];
  function getAncestorLink(element) {
    while (element && element.nodeName != "A") {
      element = element.parentNode;
    }
    if (element && element.nodeName && 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 && strings[i].test(this))
        return true;
    }
    return false;
  };

  if (location.href.indexOf('https://tech.sina.cn') === 0) {

    var setLinkAction = function(node) {
      if (node && !node.hasAttribute('setted') && node.nodeName && node.nodeName === "A" && node.href && node.href.indexOf('http') === 0) {
        node.setAttribute('setted', '');
        node.addEventListener('click', function(e) {
          e.preventDefault();
          e.stopPropagation();
          if (this && this.href && !this.href.matched(exception) && !/^(\d+|Next|Prev|>|<|下一页|上一页|下一頁|上一頁|回首頁|次へ|前へ)$/.test(this.innerText)) {
            console.log(this, e.target);
            window.open(this.href);
          } else {
            location.href = this.href;
          }
        });
      }
    };

    for (var i = 0; i < document.getElementsByTagName("A").length; i++) {
      setLinkAction(document.getElementsByTagName("A")[i]);
    }
    var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
    if (MutationObserver) {
      var observer = new MutationObserver(function(records) {
        records.map(function(record) {
          setLinkAction(record.target);
          for (var i = 0; i < record.target.getElementsByTagName("A").length; i++) {
            setLinkAction(record.target.getElementsByTagName("A")[i]);
          }
        });
      });
      observer.observe(document.body, {
        childList: true,
        subtree: true
      });
    }
  } else {
    document.addEventListener('click', function(e) {
      var link = getAncestorLink(e.target);
      console.log(link.innerText);
      if (link && link.href && !link.href.matched(exception) && link.innerText && !/^(\d+|Next|Next >|page|Page|Sort|Filter|Prev|< Prev|Last|Random|1|5|10|[>|]|[|<]|>|<|>>|<<|下一页|上一页|下一|上一|首|次へ|前へ)$/.test(link.innerText))
        link.target = '_blank';
    });
  }



})();