我正在尝试通过点击Chrome扩展程序中的页面操作图标将youtube.com上的视频播放器移到最左侧,但我不确定如何使用 document.body.innerHTML 更改播放器参数的功能(当我在观看YouTube视频时检查元素时,其id =“播放器”)将其移动到屏幕的最左侧。
的manifest.json
{
"name": "Youtube Extension",
"version": "0.0.1",
"manifest_version": 2,
"description": "Move YouTube player",
"icons": {
"16": "icons/icon16.png",
"48": "icons/icon48.png",
"128": "icons/icon128.png"
},
"default_locale": "en",
"background": {
"page": "src/bg/background.html",
"persistent": true
},
"page_action": {
"default_icon": "icons/icon19.png",
"default_title": "Youtube Extension",
"default_popup": "src/page_action/page_action.html"
},
"permissions": [
"tabs",
"activeTab"
],
"content_scripts": [
{
"matches": [
"https://www.youtube.com/*"
],
"js": [
"src/inject/inject.js"
]
}
]
}
这是我的 inject.js 文件:
chrome.pageAction.onClicked.addListener(function(tab) {
// Prints in the console if the click is working correctly
console.log("Hello. This message was sent from scripts/inject.js");
var movePlayer = document.getElementById("player");
// Not sure what to do next
})
当我进入任何YouTube视频时,我也会收到此错误消息: 未捕获的TypeError:无法读取未定义的属性'onClicked'(匿名函数) 所以我的onClick功能还有问题。
这是我的第一个chrome扩展和问题,所以请保持温和。
提前致谢!