Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google chrome extension 使用页面操作Chrome扩展将Youtube播放器移到最左侧_Google Chrome Extension_Youtube_Youtube Api - Fatal编程技术网

Google chrome extension 使用页面操作Chrome扩展将Youtube播放器移到最左侧

Google chrome extension 使用页面操作Chrome扩展将Youtube播放器移到最左侧,google-chrome-extension,youtube,youtube-api,Google Chrome Extension,Youtube,Youtube Api,我试图通过单击我的chrome扩展中的页面操作图标,将youtube.com上的视频播放器移到最左边,但我不知道如何使用document.body.innerHTML函数来更改播放器的参数,当我在观看youtube视频时检查元素以将其移动到屏幕最左侧时,该播放器的id=player Manifest.json 这是我的inject.js文件: 当我进入任何youtube视频时,也会出现以下错误: 未捕获的TypeError:无法读取未定义匿名函数的属性“onClicked” 所以我的onClic

我试图通过单击我的chrome扩展中的页面操作图标,将youtube.com上的视频播放器移到最左边,但我不知道如何使用document.body.innerHTML函数来更改播放器的参数,当我在观看youtube视频时检查元素以将其移动到屏幕最左侧时,该播放器的id=player

Manifest.json

这是我的inject.js文件:

当我进入任何youtube视频时,也会出现以下错误: 未捕获的TypeError:无法读取未定义匿名函数的属性“onClicked” 所以我的onClick函数也有问题

这是我在SO的第一个chrome扩展和问题,所以请温柔一点


提前谢谢

例如,inject.js不能使用大多数扩展API。将chrome.pageAction.onClicked事件放在后台页面中,插入内容脚本或使用消息传递来执行任何您想要的操作。移动YouTube播放器的部分是你自己必须弄清楚的。我没有使用点击功能,我只是像你说的那样插入了一个内容脚本,使用CSS文件,只需几行代码
{
  "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"
      ]
    }
  ]
}
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
})