Javascript JIRA.bind()在Greasemonkey中不起作用
正如标题所说,我无法从我的Greasemonkey脚本中获得JIRA.bind()调用,并且我已经没有了其他方法的想法 我在Firefox 50.1.0中运行JIRA 6.4.14和Greasemonkey 3.9 如果我打开JIRA并在Firefox内置控制台中执行这一行,它会工作,并且在提交内联更改后显示“GO”:Javascript JIRA.bind()在Greasemonkey中不起作用,javascript,jira,greasemonkey,Javascript,Jira,Greasemonkey,正如标题所说,我无法从我的Greasemonkey脚本中获得JIRA.bind()调用,并且我已经没有了其他方法的想法 我在Firefox 50.1.0中运行JIRA 6.4.14和Greasemonkey 3.9 如果我打开JIRA并在Firefox内置控制台中执行这一行,它会工作,并且在提交内联更改后显示“GO”: JIRA.bind(JIRA.Events.INLINE_EDIT_SAVE_COMPLETE, function(e, context, reason){alert("GO")
JIRA.bind(JIRA.Events.INLINE_EDIT_SAVE_COMPLETE, function(e, context, reason){alert("GO");})
因此,我认为将此命令移植到Greasemonkey中应该没有问题:
unsafeWindow.JIRA.bind(unsafeWindow.JIRA.Events.INLINE_EDIT_SAVE_COMPLETE, function(e, context, reason){alert("GO");})
但当我进行完全相同的内联编辑时,什么也没有发生。
行本身被执行,我在前后“提醒”,两个弹出窗口都出现了
我尝试了电话的其他变体,但都没有成功
unsafeWindow.JIRA.bind(unsafeWindow.JIRA.Events.INLINE_EDIT_SAVE_COMPLETE, function(e, context, reason){ unsafeWindow.alert("GO");})
unsafeWindow.AJS.$(unsafeWindow.JIRA.bind(unsafeWindow.JIRA.Events.INLINE_EDIT_SAVE_COMPLETE, function(e, context, reason){alert("GO");}))
unsafeWindow.JIRA.bind(unsafeWindow.JIRA.Events.INLINE_EDIT_SAVE_COMPLETE, function(){ alert("GO");})
// While 'fooBar' is a simple function doing the alert("go")
unsafeWindow.JIRA.bind(unsafeWindow.JIRA.Events.INLINE_EDIT_SAVE_COMPLETE, function(){ fooBar })
有人知道如何装订吗
尝试exportFunction并没有解决问题:
$(document).ready(function() {
unsafeWindow.JIRA.bind(unsafeWindow.JIRA.Events.INLINE_EDIT_SAVE_COMPLETE, function(e, context, reason){ foobar });
});
function foobar()
{
alert("GO");
}
exportFunction(foobar, unsafeWindow);
解决方案: 感谢Brock Adams和wOxxOm的帮助 这个被剪断的功能很好,可以打印“绑定”和“转到”两条消息 参考
.bind()
调用中的所有内容都必须驻留在目标页面范围内,因此不能使用动态函数(){…}
这样的代码
像这样绑定回调:
函数mySaveComplete(e、上下文、原因){
//警惕(“围棋”);
console.log(“Go”);
}
unsafeWindow.mySaveComplete=exportFunction(mySaveComplete,unsafeWindow);
unsafeWindow.JIRA.bind(
unsafeWindow.JIRA.Events.INLINE_编辑_保存_完成,
unsafeWindow.mySaveComplete
);
但是,我无法使用JIRA试验台。在某些情况下,您可能需要注入代码,如链接的答案所示。在这种情况下,请参见:您需要
exportFunction(function(){blablabla},unsafeWindow)
将函数导出到不安全的上下文中。我尝试了exportFunction,但没有成功。exportFunction是一个创建函数的包装器,因此您应该将其传递给bind。
$(document).ready(function() {
// Write a log message from inside of the GM script
anotherMethod("Binding");
// Bind the exported foobar to the JIRA event
unsafeWindow.JIRA.bind(
unsafeWindow.JIRA.Events.INLINE_EDIT_SAVE_COMPLETE,
unsafeWindow.foobar
);
});
// Implementation of the foobar function
function foobar(e, context, reason)
{
anotherMethod("Go");
}
// Another method, that will get called from the GM script and the exported foobar
function anotherMethod(msg)
{
console.log(msg);
}
// Export foobar to the unsafeWindow to make it accessible for JIRA
unsafeWindow.foobar = exportFunction(foobar, unsafeWindow);