我正在尝试构建一个 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>
在获得更多指导后,我在此处包含了我的清单、脚本和内容文件
清单.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",
]
}
脚本.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);
});
内容.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);