使用'%s'时如何摆脱省略号?引用所选文字?

时间:2017-07-21 16:39:55

标签: javascript firefox-webextensions

目前开始学习为Firefox制作Webextensions的一些基础知识。

当用户选择了一些文本时,我试图在上下文菜单中添加一个简单的选项。没有什么花哨的,将选择输出到控制台按预期工作。但是,上下文菜单中的文本不是什么。

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来截断,但似乎字符串在create函数的最末端进行了求值。例如。从%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规则。

帮助这位新手赞赏!

2 个答案:

答案 0 :(得分:2)

不幸的是,您必须等待修复相关的Firefox bug。如果此刻正在进行此操作的人很快就无法解决问题,请自行修复。

答案 1 :(得分:0)

更新后期,忘了我也在这里发布了。

要点: 在mozilla dev论坛上发送了很多。之后的许多错误报告似乎都是Firefox at the moment中的错误。