// ==UserScript== // @name 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.2 // @description Replace Tieba URL hostname in 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 // @namespace http://tampermonkey.net/ // @downloadURL 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, matchedPatterns: regExps.filter(p => p.test(a.hostname)) })) .filter(info => info.matchedPatterns.length > 0) .forEach(info => { info.elm.hostname = info.elm.hostname.replace(info.matchedPatterns[0], replaceBy) info.elm.protocol = 'https' });