Greasemonkey 根本不工作

Greasemonkey not working at all

我不完全确定这是否与我的另一台计算机 运行 Vista 以及其他版本中使用的代码相同,因为它已经死了,但主要是。它似乎不起作用,即使我设计用于其他站点。

// ==UserScript==
// @name          hide youtube element
// @namespace     computerarea
// @description   hide div
// @include       https://www.youtube.com/watch?v=*
// @include       https://www.youtube.com/watch?*
// @version       1
// @grant         metadata
// @require       http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.js
// ==/UserScript==


function addJQuery(callback) {
    var script = document.createElement("script");
    script.setAttribute("src", "https://code.jquery.com/jquery-2.0.3.min.js");
    script.addEventListener('load', function() {
        var script = document.createElement("script");
        script.textContent = "window.jQQ=jQuery.noConflict(true);(" + callback.toString() + ")();";
        document.body.appendChild(script);
    }, false);
    document.body.appendChild(script);
}


$(document).ready(function {
$('#watch7-sidebar-contents').hide(0).delay(3000).show(0);
});

版本 1:

// ==UserScript==
// @name          hide youtube element
// @namespace     computerarea
// @description   hide div
// @include       https://www.youtube.com/watch?*
// @version       1
// @grant         GM_addStyle
// @require       http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js
// ==/UserScript==

$('#watch7-sidebar-contents').hide(0).delay(3000).show(0);

版本 2:

// ==UserScript==
// @name          hide youtube element
// @namespace     computerarea
// @description   hide div
// @include       https://www.youtube.com/watch?*
// @version       2
// @grant         GM_addStyle
// @require       http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js
// @noframes
// ==/UserScript==

//test link example: https://www.youtube.com/watch?v=wygy721nzRc
console.log('working on test link: ' + location.href);
if(window.$) {
    console.log('jQuery loaded; version: ' + window.$.fn.jquery);
    var $sidebar = $('#watch7-sidebar-contents');
    if(!hideAndShow()) {
        console.log('try again after 5sec');
        setTimeout(function() {
            $sidebar = $('#watch7-sidebar-contents');
            hideAndShow();
        }, 5000);
    }
}
else {
    console.log('missing jQuery');
}

function hideAndShow() {
    if($sidebar.length) {
        console.log('hide sidebar, wait for 3sec, and show sidebar again');
        $sidebar.hide(0).delay(3000).show(0);
        return true;
    }
    else {
        console.log('missing sidebar');
    }
    return false;
}

现在,我相信旧版本可以在我的另一台计算机上正常工作,但列出的 'NEW' 允许 Jquery 再次与 Tampermonkey 一起工作。

http://userscripts-mirror.org/scripts/review/157028

/*NEW Jquery inject*/
var script = unsafeWindow.document.createElement("SCRIPT");
    script.src = 'https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js';
    script.type = 'text/javascript';
    unsafeWindow.document.getElementsByTagName("head")[0].appendChild(script);
    script.addEventListener('load', function(){ 
        jQuery = unsafeWindow['jQuery'];
        unsafeWindow['$_'] = jQuery.noConflict(true);
    }, false);

/*OLD Jquery inject*/
/*function addJQuery(callback) {
    var script = document.createElement("script");
    script.setAttribute("src", "https://code.jquery.com/jquery-2.0.3.min.js");
    script.addEventListener('load', function() {
        var script = document.createElement("script");
        script.textContent = "window.jQQ=jQuery.noConflict(true);(" + callback.toString() + ")();";
        document.body.appendChild(script);
    }, false);
    document.body.appendChild(script);
}*/