我正在尝试构建Chrome扩展程序,以便在Trix中的消息/评论结尾添加个性化签名/消息
从阅读文档和其他类似问题我发现它看起来非常简单。我的content.js
文件......
'use strict'
var sig = '<p>Testing 1,2</p>';
//chrome.storage.sync.get(null, function (data) {
// sig = data.signature;
//});
document.addEventListener("trix-initialize", function (event) {
event.target.editor.loadHTML(sig);
});
......应该做的伎俩。但我一直收到这个错误...
Uncaught TypeError: Cannot read property 'loadHTML' of undefined at HTMLDocument.<anonymous>
在获得更多指导后,我已将此清单,脚本和内容文件包括在内
的manifest.json
{
"manifest_version": 2,
"name": "BaseCamp Signature",
"description": "This extension adds signature to Basecamp",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html",
"default_title": "Title!"
},
"permissions": [
"storage",
"activeTab",
"tabs",
"https://3.basecamp.com/*"
],
"content_scripts": [
{
"matches": ["https://3.basecamp.com/*/*"],
"all_frames": true,
"js": ["content.js"],
"run_at": "document_end"
}
],
"web_accessible_resources": [
"script.js",
]
}
的script.js
'use strict'
var sig = '<p>Testing 1,2</p>';
//chrome.storage.sync.get(null, function (data) {
// sig = data.signature;
//});
document.addEventListener("trix-initialize", function (event) {
event.target.editor.loadHTML(sig);
});
content.js
var s = document.createElement('script');
// TODO: add "script.js" to web_accessible_resources in manifest.json
s.src = chrome.extension.getURL('script.js');
s.onload = function() {
this.remove();
};
(document.head || document.documentElement).appendChild(s);