Greasemonkey入门.

1. 如何将网页(http://jokedata.blogspot.com/2013/06/blog-post_6.html)中的alert去掉

注意:把里面的if(0)改为if(1)能达到同样效果,但是在html view里面看到是不同的

if(0) :会在页面的body加上我们的script

if(1): 直接野蛮的修改网页(不推荐)

// ==UserScript==
// @name        Select-click-copy Enabler
// @namespace   cutepig
// @include     *
// @version     1
// ==/UserScript==


GM_log('Select-click-copy Enabler\n');

function fixElem(elem){
    elem.onkeydown =null;
    elem.onkeyup =null;
    elem.oncopy = null;
    elem.onmouseup = null;
    elem.onmousedown = null;
    elem.oncontextmenu = null;
    elem.onselect = null;
    elem.onselectstart = null;
}

function MyLog(s)
{
    if(typeof GM_log != 'undefined')
        GM_log(s);
}

function enableSelectClickCopy(window) { 

    MyLog('Select-click-copy enableSelectClickCopy enter\n');
    
    fixElem(document);
    
    element = document.getElementsByTagName('*');
    for(i = 0; i < element.length; i++) {
        fixElem(element[i])
    }
    
    MyLog('Select-click-copy window '+window);
    MyLog('Select-click-copy window.$ '+window.$);
    
    if (window)
    {
        fixElem(window)
    }
    
    MyLog('Select-click-copy enableSelectClickCopy exit\n');
}

if(0)
    enableSelectClickCopy(window);
else
{
    var scrip = document.createElement("script");
    scrip.innerHTML = fixElem.toString() + '\n' 
    scrip.innerHTML += MyLog.toString() +'\n'
    scrip.innerHTML += enableSelectClickCopy.toString() +'\n'
    scrip.innerHTML += 'enableSelectClickCopy(window);\n'
    document.head.appendChild(scrip);
}
View Code

 



2. -如何debug greasemonkey脚本

note: 俺试了一下1,2,4,和html版面(显示的是修改之后的网页)用起来都不错

3.1. 用错误控制台追踪错误
3.2. 用 GM_log 记日志
3.3. 用 DOM 查看器查看元素
3.4. 用 Javascript Shell 计算表达式

3. -Greasemonkey 脚本应用在本地文件的办法
在about:config页面设置greasemonkey.fileIsGreaseable =true

Powered by Jekyll and Theme by solid

本站总访问量