【问题标题】:Turning Off Annotations for YouTube Videos by Javascript in Chrome Extensions在 Chrome 扩展程序中通过 Javascript 关闭 YouTube 视频的注释
【发布时间】:2014-07-28 03:16:25
【问题描述】:

对于我的 Chrome 扩展程序,我想关闭/打开 YouTube 视频的注释。这是一个包含注释的示例视频:

http://www.youtube.com/watch?v=87kezJTpyMI

我搜索了很多。 YouTube 提供了许多 API 方法来修改视频,但我找不到任何 JavaScript 函数来关闭注释。最有希望的解决方案似乎是 url 参数 (iv_load_policy) hack,但它不再起作用了。

http://www.youtube.com/watch?v=87kezJTpyMI&hd=1&iv_load_policy=3

如何在 Chrome 扩展程序中关闭 JavaScript 对 YouTube 视频的注释?

【问题讨论】:

标签: google-chrome google-chrome-extension youtube youtube-api youtube-javascript-api


【解决方案1】:

使用this solution。它工作得很好并且保持最新(我是作者)。我也会在此处粘贴当前代码,但我只会尝试在此处保持最新:

var settings_button = document.querySelector(".ytp-settings-button");
settings_button.click(); settings_button.click(); // open and close settings, so annotations label is created

var all_labels = document.getElementsByClassName("ytp-menuitem-label");
for (var i = 0; i < all_labels.length; i++) {
  if ((all_labels[i].innerHTML == "Annotations") && (all_labels[i].parentNode.getAttribute("aria-checked") == "true")) { // find the correct label and see if it is active
    all_labels[i].click(); // and in that case, click it
  }
}

【讨论】:

    【解决方案2】:

    我用这个:$("div.video-annotations").css("display", "none");

    不确定它是否适用于 Flash 播放器!

    【讨论】:

      【解决方案3】:

      也许你手动触发点击注释关闭按钮,使用 jquery 这似乎工作:

      $(".ytp-segmented-control-deselected").click()
      

      【讨论】:

      • 谢谢,但它似乎只适用于 HTML5 视频播放器。我还需要 Flash Player。
      猜你喜欢
      • 2016-09-05
      • 1970-01-01
      • 2013-10-21
      • 1970-01-01
      • 2010-09-05
      • 2020-11-21
      • 1970-01-01
      • 2017-03-11
      • 1970-01-01
      相关资源
      最近更新 更多