使用“%s”引用所选文本时如何去掉省略号?
How do I get rid of the Ellipsis when using '%s' to refer to the selected text?
目前正在学习为 Firefox 制作 Web 扩展的一些基础知识。
我正在尝试在用户选择了一些文本时向上下文菜单添加一个简单的选项。没什么特别的,将选择输出到控制台按预期工作。然而,上下文菜单中的文本本身没有。
为 background.js 输入此代码时:
browser.contextMenus.create({
id: "log-selection",
title: "Log '%s' to the console",
contexts: ["selection"]
});
browser.contextMenus.onClicked.addListener(function(info, tab) {
if (info.menuItemId == "log-selection") {
console.log(info.selectionText);
}
});
如https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/contextMenus/create
所述
应该加上
"Log 'selected text bla' to the console"
作为上下文菜单(右键单击菜单)的选项。
但是显示为:
"Log 'selected text bla...' to the console"
(该 MDN 页面现已更新以反映我的发现)
我已经尝试通过从 %s 中减去 3 来截断,但似乎字符串是在创建函数的最后计算的。例如。从 %s 截断 3 会给我
""
而不是想要的
selected text bla
如果需要额外信息 - 我的 manifest.json:
{
"manifest_version": 2,
"name": "Selection Logger",
"version": "1.0",
"description": "Add selection to context menu to print with console",
"background": {
"scripts": [
"background.js"
]
},
"permissions": [
"contextMenus"
],
"applications": {
"gecko": {
"id": "myTest@tester.com"
}
}
}
关于如何摆脱 Ellipses/3 点的任何想法?我也试过创建一个内联函数,但它对我也不起作用。
title: function(){ return "test"; },
没有用,我很确定违反了一些 JS 规则。
感谢对这位新手的帮助!
很遗憾,您必须等待相关 Firefox bug 得到修复。或者,如果目前正在处理它的人没有尽快解决它,请自行修复它。
更新晚了,忘了我也发在这里了。
总结:
在 mozilla 开发论坛上发送了很多。后来报告了许多错误,这似乎是 Firefox at the moment.
中的错误
目前正在学习为 Firefox 制作 Web 扩展的一些基础知识。
我正在尝试在用户选择了一些文本时向上下文菜单添加一个简单的选项。没什么特别的,将选择输出到控制台按预期工作。然而,上下文菜单中的文本本身没有。
为 background.js 输入此代码时:
browser.contextMenus.create({
id: "log-selection",
title: "Log '%s' to the console",
contexts: ["selection"]
});
browser.contextMenus.onClicked.addListener(function(info, tab) {
if (info.menuItemId == "log-selection") {
console.log(info.selectionText);
}
});
如https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/contextMenus/create
所述应该加上
"Log 'selected text bla' to the console"
作为上下文菜单(右键单击菜单)的选项。
但是显示为:
"Log 'selected text bla...' to the console"
(该 MDN 页面现已更新以反映我的发现)
我已经尝试通过从 %s 中减去 3 来截断,但似乎字符串是在创建函数的最后计算的。例如。从 %s 截断 3 会给我
""
而不是想要的
selected text bla
如果需要额外信息 - 我的 manifest.json:
{
"manifest_version": 2,
"name": "Selection Logger",
"version": "1.0",
"description": "Add selection to context menu to print with console",
"background": {
"scripts": [
"background.js"
]
},
"permissions": [
"contextMenus"
],
"applications": {
"gecko": {
"id": "myTest@tester.com"
}
}
}
关于如何摆脱 Ellipses/3 点的任何想法?我也试过创建一个内联函数,但它对我也不起作用。
title: function(){ return "test"; },
没有用,我很确定违反了一些 JS 规则。
感谢对这位新手的帮助!
很遗憾,您必须等待相关 Firefox bug 得到修复。或者,如果目前正在处理它的人没有尽快解决它,请自行修复它。
更新晚了,忘了我也发在这里了。
总结: 在 mozilla 开发论坛上发送了很多。后来报告了许多错误,这似乎是 Firefox at the moment.
中的错误