Greasy Fork

Greasy Fork is available in English.

翻译垃圾再利用

跳转到源地址

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         翻译垃圾再利用
// @namespace    inqb.ga
// @version      0.5.0
// @description  跳转到源地址
// @author       no1xsyzy
// @match        *://*.stackexchange.com/search?q=*
// @match        *://stackoverflow.com/search?q=*
// @match        *://xbuba.com/questions/*
// @match        *://www.itranslater.com/qa/details/*
// @match        *://itranslater.com/qa/details/*
// @match        *://codeday.me/bug/*
// @match        *://www.codenong.com/*
// @match        *://codenong.com/*
// @match        *://ask.helplib.com/others/*
// @match        *://hant.ask.helplib.com/others/*
// @match        *://qa.1r1g.com/sf/ask/*
// @match        *://www.ojit.com/article/*
// @match        *://www.thinbug.com/q/*
// @match        *://*.stackovernet.xyz/cn/q/*
// @match        *://qastack.cn/*/*
// @match        *://cn.voidcc.com/question/*
// @grant        none
// ==/UserScript==

const HASHTAG = "#__translate_junk_jump";

(function() {
    'use strict'

    try{
        switch(window.location.hostname.split(".").slice(-2).join(".")){ // match second-level domain
            case "stackexchange.com":
            case "stackoverflow.com":
                if ( window.location.hash === HASHTAG ){ // assure hash tag for jump indication
                    let g = document.querySelectorAll(`.search-result`)
                    if ( g.length === 1 ) { // assure only one result
                        let link = g[0].querySelector(`a.question-hyperlink`)
                        window.location.href = link.href
                    } else {
                        let searchQuery = document.querySelector(`input.s-input`).value;
                        for ( let gg of g ){
                            if ( gg.querySelector('a.question-hyperlink').getAttribute('title') === searchQuery ){
                                window.location.href = gg.querySelector('a.question-hyperlink').getAttribute("href")
                                break
                            }
                        }
                    }
                }
                break
            case "xbuba.com":
            case "ojit.com":
                window.location.href = document.querySelector(`a[href^="https://stackoverflow.com/q"]`).getAttribute("href")
                break
            case "itranslater.com":
                window.location.href = document.querySelector(`a[href^="https://stackoverflow.com:/q"]`).getAttribute("href");
                break
            case "codeday.me":
                window.location.href = document.querySelector(`span.article-es-url:nth-child(4) > a:nth-child(1)`).getAttribute("href")
                break
            case "codenong.com":
                if (window.location.pathname === "/"){
                    throw TypeError
                }
                window.location.href = "https://stackoverflow.com/q"+window.location.pathname
                break
            case "helplib.com":
                window.location.href = "https://stackoverflow.com/search?q=" + document.querySelector(`a.main_title`).getAttribute("oldtitle") + HASHTAG
                break
            case "1r1g.com":
                window.location.href = "https://stackoverflow.com/q/"+(+/\d+/.exec(window.location.pathname)[0]-31)/70
                break
            case "thinbug.com":
                window.location.href = "https://stackoverflow.com"+window.location.pathname
                break
            case "stackovernet.xyz":
                var sub = window.location.hostname.split(".")[0]
                window.location.href = `https://${sub}.stackexchange.com/search?q=` + document.querySelector(`h1`).innerHTML + HASHTAG
                break
            case "qastack.cn":
                var domain = document.querySelector(`small>a:last-child`).hostname
                window.location.href = `https://${domain}/q/${window.location.pathname.split("/")[2]}`
                break
            case "voidcc.com":
                window.location.href = document.querySelector("span.source > a").href
                break
            default:
                throw Error
        }
    }catch(e){
        console.log("unknown source")
    }
})();