Greasy Fork

Greasy Fork is available in English.

Google搜索页面贴吧链接替换

最近访问dq.tieba.com/*老是出现 “您好,该页面正在维护中。” 。 于是就写了这个script

当前为 2019-10-02 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name                 dq.tieba.com to tieba.baidu.com for Google results
// @name:zh-CN           Google搜索页面贴吧链接替换
// @name:zh-TW           Google搜索页面贴吧链接替换
// @namespace            http://tampermonkey.net/
// @version              0.1
// @description          Replace Tieba URL hostname in <a> tags to `tieba.baidu.com`
// @description:zh-CN    最近访问dq.tieba.com/*老是出现 “您好,该页面正在维护中。” 。 于是就写了这个script
// @description:zh-TW    最近访问dq.tieba.com/*老是出现 “您好,该页面正在维护中。” 。 于是就写了这个script
// @author               Jiaxing Peng
// @include              *://www.google.*
// @grant                none
// ==/UserScript==

// **********************************************************************
// You can add ` @match *://*/* ` above to apply the script for all sites
// **********************************************************************

"use strict";

var patterns = [
    'tieba.baidu.*',
    'dq.tieba.*',
    'c.tieba.baidu.*',
    'post.baidu.*',
    'xingqu.baidu.*'
];

var replaceBy = "tieba.baidu.com";

var regExps = patterns.map(p => new RegExp(p));

var links = document.getElementsByTagName('a');

[].slice.call(links)
    .map((a) => ({
        elm: a,
        hostname: a.hostname,
        matchedPatterns: regExps.filter(p => p.test(a.hostname))
    }))
    .filter((info) => info.matchedPatterns.length > 0)
    .forEach((info) => {
        info.elm.hostname = info.hostname.replace(info.matchedPatterns[0], replaceBy)
        info.elm.protocol = 'https'
    });