2017-07-21 27 views
2

目前開始學習製作Webextensions for Firefox的一些基礎知識。如何在使用'%s'引用選定文本時擺脫省略號?

我想添加一個簡單的選項,當用戶選擇了一些文本的上下文菜單。沒有什麼奇特的,輸出選擇到控制檯按預期工作。然而,不是,上下文菜單中的文本本身。

當輸入爲background.js此代碼:如在https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/contextMenus/create

描述

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); 
    } 
}); 

應該添加

"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": "[email protected]" 
    } 
    } 

} 

如何我的任何想法可以擺脫橢圓/ 3點?我試過創建一個內聯函數,但它對我也不起作用。

title: function(){ return "test"; }, 

沒有工作,我敢肯定違反了一些JS規則。

幫助這個新手讚賞!

回答

0

最新更新,忘了我也發佈在這裏。

摘要: 在mozilla開發論壇上發了很多。後來發現了很多錯誤報告,看起來它是Firefox at the moment中的一個錯誤。

2

不幸的是,您必須等待相關的Firefox bug被修復。或者,如果目前正在從事此項工作的人員很快就無法解決問題,請自行解決。