Greasy Fork

Greasy Fork is available in English.

Google搜索页面贴吧链接替换

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

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

// ==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'
    });