userscript did run on greasemonkey addon
I could install the userscript[1] successfully;Both greasemonkey and the userscript are definitively enabled ; checking the Errors console see nothing unusual. But the script below did not running as expected (no alert after a page is ready). Any idea will be appr开发者_高级运维eciated.
// ==UserScript==
// @name clicksave
// @namespace http://userscripts.org/users/pierr
// @description click the words and it will be saved
// @copyright pierr chen
// @contributor pierr chen
// @include http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js
// @license GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
// @license Creative Commons; http://creativecommons.org/licenses/by-nc-nd/3.0/
// @version 0.0.1
// ==/UserScript==
function getSelText()
{
var txt = '';
if (window.getSelection)
{
txt = window.getSelection();
}
else if (document.getSelection)
{
txt = document.getSelection();
}
else if (document.selection)
{
txt = document.selection.createRange().text;
}
else return;
return txt
}
function saveSelText()
{
var selText = getSelText()
if (selText != "")
{
var url = "http://localhost:3000/auto_create?content="+getSelText();
$.get(url,{},false);
}
}
$(document).ready(function(){
$(document).mouseup(function(){
alert('Handler for .mouseup called.'); //even this alert will not jump out
saveSelText()
})
})
[1]http://userscripts.org/scripts/show/96771
Turns out should use
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
Some versions of jQuery will not run inside the Greasemonkey sandbox. As of this writing, 1.3.2 does work, but 1.4.1 does not. It is possible to patch 1.4 versions of jQuery to work, see jQuery Forum: Importing jQuery 1.4.1 into greasemonkey scripts generates an error
精彩评论