大人的Greasy Fork

访问匿名不可用内容时跳转至sleazyfork,未登录状态下尝试在sleazyfork查找内容后合并至greasyfork | Merge sleazyfork results into greasyfork when the script is no longer anonymously available

Verze ze dne 08. 10. 2016. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         大人的Greasy Fork
// @namespace    hoothin
// @version      0.2
// @description  访问匿名不可用内容时跳转至sleazyfork,未登录状态下尝试在sleazyfork查找内容后合并至greasyfork | Merge sleazyfork results into greasyfork when the script is no longer anonymously available
// @author       hoothin
// @match        http*://greasyfork.org/*
// @match        http*://www.greasyfork.org/*
// @grant        GM_xmlhttpRequest
// ==/UserScript==

(function() {
    'use strict';
    if(document.querySelector('span.sign-in-link')){
        if(/scripts\/search/.test(location.href)){
            GM_xmlhttpRequest({
                method: 'GET',
                url: location.href.replace(/\/\/([^\.]+\.)?greasyfork\.org/,"//$1sleazyfork\.org"),
                onload: function(result) {
                    var doc = null;
                    try {
                        doc = document.implementation.createHTMLDocument('');
                        doc.documentElement.innerHTML = result.responseText;
                    }
                    catch (e) {
                        console.log('parse error');
                    }
                    if (!doc) {
                        return;
                    }
                    var ml = document.querySelector('#browse-script-list');
                    if(!ml){
                        ml=document.createElement("ol");
                        ml.setAttribute("id","browse-script-list");
                        ml.setAttribute("class","script-list");
                        var list=document.querySelector('body>div.width-constraint');
                        var ps=list.querySelectorAll("p");
                        for(var p of ps){
                            list.removeChild(p);
                        }
                        list.appendChild(ml);
                    }
                    var l = doc.querySelector('#browse-script-list');
                    if (l) {
                        var scs=l.querySelectorAll("li");
                        if(scs){
                            for(var sc of scs){
                                if(!ml.querySelector("li[data-script-id='"+sc.getAttribute("data-script-id")+"']")){
                                    ml.appendChild(sc);
                                }
                            }
                        }
                    }
                },
                onerror: function(e) {
                    console.log(e);
                }
            });
        }else if(/scripts\/\d+/.test(location.href)){
            if(!document.querySelector("#script-info")){
                location.href=location.href.replace(/\/\/([^\.]+\.)?greasyfork\.org/,"//$1sleazyfork\.org");
            }
        }
    }
})();