我可以成功安装userscript [1];最终启用了greasemonkey和usercript;检查错误控制台看到没有异常。但是下面的脚本没有按预期运行(页面准备好后没有警报)。任何想法将不胜感激。
// ==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
答案 0 :(得分:0)
原来应该使用
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
某些版本的jQuery不会在Greasemonkey沙箱中运行。在撰写本文时,1.3.2确实有效,但1.4.1没有。有可能修补1.4版本的jQuery,请参阅jQuery论坛:将jQuery 1.4.1导入到greasemonkey脚本中会产生错误