【问题标题】:Remove "Watch Youtube videos in Chrome" bar with Tampermonkey使用 Tampermonkey 删除“在 Chrome 中观看 Youtube 视频”栏
【发布时间】:2017-08-02 21:21:05
【问题描述】:

我正在尝试为 Tampermonkey 制作一个脚本,该脚本会删除 Youtube 页面顶部的蓝条。

这是蓝条的源代码:

 <div id="ticker-content">
        <div class="yt-alert yt-alert-default yt-alert-info  " id="ticker">  <div class="yt-alert-icon">
        <span class="icon master-sprite yt-sprite"></span>
      </div>
    <div class="yt-alert-content" role="alert">    <div tabindex="0" class="yt-alert-message">
                Watch YouTube videos with Chrome. &nbsp; &nbsp; <a href="https://www.google.com/chrome/browser/desktop/index.html?brand=NDCM&amp;utm_source=all-pushdown-yt&amp;utm_medium=yt-pushdown&amp;utm_campaign=yt-watch">Yes, get Chrome now</a>.
        </div>
    </div><div class="yt-alert-buttons"><button class="yt-uix-button yt-uix-button-size-default yt-uix-button-close close yt-uix-close" aria-label="Close" onclick="yt.www.masthead.dismissChromeAlert();return false;" type="button" data-close-parent-class="yt-alert"><span class="yt-uix-button-content">Close</span></button></div></div>
      </div>

如果我对 this post 的理解正确,我必须使用 badDivs 以及包含选择器。

我的代码看起来像这样,但它不起作用:

(function() {
    'use strict';
var badDivs = $("div div:contains('ticker-content')");

badDivs.parent ().remove ();

})();

有人可以帮忙完成这项工作吗?

【问题讨论】:

    标签: javascript html youtube tampermonkey


    【解决方案1】:

    您可以像这样简单地删除它:

    (function() {
        'use strict';
        var ticker = document.getElementById('ticker-content');
        ticker.parentElement.removeChild(ticker);
    })();
    

    【讨论】:

      猜你喜欢
      • 2012-05-17
      • 2017-02-27
      • 2021-08-15
      • 1970-01-01
      • 1970-01-01
      • 2011-04-08
      • 2019-09-08
      • 2023-03-17
      • 2018-09-02
      相关资源
      最近更新 更多