大人的Greasy Fork(Greasfork Search with Sleazyfork Results include)

访问匿名不可用内容时跳转至sleazyfork,未登录状态下尝试在sleazyfork查找内容后合并至greasyfork,并添加评分与版本号 | Merge sleazyfork results into greasyfork when the script is no longer anonymously available,add rating score and version for scripts then

目前為 2016-10-09 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         大人的Greasy Fork(Greasfork Search with Sleazyfork Results include)
// @namespace    hoothin
// @version      0.4
// @description  访问匿名不可用内容时跳转至sleazyfork,未登录状态下尝试在sleazyfork查找内容后合并至greasyfork,并添加评分与版本号 | Merge sleazyfork results into greasyfork when the script is no longer anonymously available,add rating score and version for scripts then
// @author       hoothin
// @include      http*://greatest.deepsurf.us/*
// @match        http*://www.greatest.deepsurf.us/*
// @grant        GM_xmlhttpRequest
// ==/UserScript==

(function() {
    'use strict';
    if(document.querySelector('span.sign-in-link')){
        if(/scripts\/\d+/.test(location.href)){
            if(!document.querySelector("#script-info")){
                location.href=location.href.replace(/\/\/([^\.]+\.)?greasyfork\.org/,"//$1sleazyfork\.org");
            }
        }else if(/(scripts|users)\//.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('ol.script-list');
                    if(!ml){
                        ml=document.createElement("ol");
                        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('ol.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")+"']")){
                                    addScore(sc);
                                    ml.appendChild(sc);
                                }
                            }
                        }
                    }
                },
                onerror: function(e) {
                    console.log(e);
                }
            });
        }
    }
    function addScore(script){
        var separator=script.querySelector('h2>span.name-description-separator');
        var description=script.querySelector('h2>span.description');
        if(separator)separator.innerHTML="<strong style='color:#e09015'>"+script.getAttribute("data-script-rating-score")+"</strong>"+separator.innerHTML;
        if(description)description.innerHTML+="<strong>Ver."+script.getAttribute("data-script-version")+"</strong>";
    }
    var scripts=document.querySelectorAll('ol.script-list>li');
    for(var script of scripts){
        addScore(script);
    }
})();