Greasy Fork

Greasy Fork is available in English.

Google谷歌搜索页面dq.tieba.com贴吧链接替换

最近访问dq.tieba.com老是出现 “您好,该页面正在维护中。” 于是就写了这个。为什么要在Google搜索页面替换呢?这是因为当你按dq.tieba.com时服务器就给你的浏览器发个HTTP 302重定向到维护页面,脚本都来不及执行

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

// ==UserScript==
// @name                 Google谷歌搜索页面dq.tieba.com贴吧链接替换 dq.tieba.com to tieba.baidu.com for Google results
// @name:zh-CN           Google谷歌搜索页面dq.tieba.com贴吧链接替换
// @name:zh-TW           Google谷歌搜索頁面dq.tieba.com貼吧鏈接替換
// @version              0.5
// @include              *://www.google.*
// @description          最近访问dq.tieba.com老是出现 “您好,该页面正在维护中。” 于是就写了这个。为什么要在Google搜索页面替换呢?这是因为当你按dq.tieba.com时服务器就给你的浏览器发个HTTP 302重定向到维护页面,脚本都来不及执行
// @description:zh-CN    最近访问dq.tieba.com老是出现 “您好,该页面正在维护中。” 于是就写了这个。为什么要在Google搜索页面替换呢?这是因为当你按dq.tieba.com时服务器就给你的浏览器发个HTTP 302重定向到维护页面,脚本都来不及执行
// @description:zh-TW    最近訪問dq.tieba.com老是出現 “您好,该页面正在维护中。” 於是就寫了這個。為什麼要在Google搜索頁面替換呢?這是因為當你按dq.tieba.com時服務器就給你的瀏覽器發個HTTP 302轉址到維護頁面,脚本都來不及執行
// @author               Jiaxing Peng
// @namespace            bjxpen
// @grant                none
// ==/UserScript==

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

"use strict";

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

var replaceBy = "tieba.baidu.com";

var regExps = hostnamePatterns.map(function (p) {return new RegExp(p)});

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

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