1

我正在努力让用户脚本在 chrome 上工作。我知道这个问题已经被问了数百次,但我仍然无法让它发挥作用......

// ==UserScript==
// @name        SRH hide closed cases
// @namespace   srhhideclosed
// @description For hiding appeals and reports that have been closed
// @include     http://www.seriousroleplayinghell.com*
// @include     http://seriousroleplayinghell.com*
// @include     http://www.srh.im.com*
// @include     http://srh.im.com*
// @version     1
// @require     http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js
// ==/UserScript==

// Insert GM API for chrome
if (typeof GM_deleteValue == 'undefined') {
    GM_addStyle = function(css) {
        var style = document.createElement('style');
        style.textContent = css;
        document.getElementsByTagName('head')[0].appendChild(style);
    }

    GM_deleteValue = function(name) {
        localStorage.removeItem(name);
    }

    GM_getValue = function(name, defaultValue) {
        var value = localStorage.getItem(name);
        if (!value)
            return defaultValue;
        var type = value[0];
        value = value.substring(1);
        switch (type) {
            case 'b':
                return value == 'true';
            case 'n':
                return Number(value);
            default:
                return value;
        }
    }

    GM_log = function(message) {
        console.log(message);
    }

    GM_openInTab = function(url) {
        return window.open(url, "_blank");
    }

     GM_registerMenuCommand = function(name, funk) {
    //todo
    }

    GM_setValue = function(name, value) {
        value = (typeof value)[0] + value;
        localStorage.setItem(name, value);
    }
}

function toggleHidden(){
    if(GM_getValue("SRHhidden",0) == 1){
        GM_setValue("SRHhidden", 0);
    }else{
        GM_setValue("SRHhidden", 1);
    }
    hide(1000)
}

function hide(speed){
    if(GM_getValue("SRHhidden",0) == 1){
        $('s').closest('tr').fadeIn(speed);
    }else{
        $('s').closest('tr').fadeOut(speed);
    }
}

if(document.title == "Serious Roleplaying Hell - Appeals" || document.title == "Serious Roleplaying Hell - Admin/Player Abuse Reports" ){
    var TDHeads = document.getElementsByClassName("thead");
    var Head = TDHeads[1];
    var sp1 = document.createElement("div");
    sp1.style.cssFloat = "right";
    sp1.style.margin = "0 0 0 6px";
    sp1.innerHTML = "<span class='smalltext'><strong>| <a id='hideToggle'>Hide/Show closed threads</a></strong></span>";
    Head.insertBefore(sp1, Head.firstChild);
    var toggle = document.getElementById('hideToggle');
    toggle.addEventListener('click',toggleHidden,true);
    var style = "#hideToggle:hover{cursor:pointer} #hideToggle{color:#ffffff;}"
    GM_addStyle(style);

    hide(0);
}


那么它需要做什么,如果线程关闭,这个论坛会显示线程主题条纹。出于某种原因,我需要隐藏所有已关闭的线程,以便仅查看打开的线程。我在 Firefox 上运行此脚本,但@requireChrome 不支持。

我试过如何在 Google Chrome 的 Greasemonkey 脚本中使用 jQuery?以及如何很好地使用 jQuery 和 Greasemonkey。但是,我不能在 Chrome 中工作。有人有什么建议吗?

4

1 回答 1

1

使用 Tampermonkey 而不是将其作为扩展程序打开

于 2013-01-31T14:18:54.757 回答