Greasemonkey删除li元素

时间:2016-05-04 18:23:57

标签: greasemonkey

使用greasemonkey如何从youtube页面删除'li'节点:

...
    <li class="guide-channel guide-notification-item overflowable-list-item " id="create_channel-guide-item" data-visibility-tracking="" role="menuitem">

      <a class="guide-item yt-uix-sessionlink yt-valign spf-nolink   " href="/create_channel" title="My Channel" data-sessionlink="ei=CzwqV8TfL8KqWpTMrqgN&amp;feature=g-personal&amp;ved=CJUCELUsGAEiEwiEkeuVg8HMAhVClRYKHRSmC9Uojh4" data-visibility-tracking="" data-external-id="create_channel" data-serialized-endpoint="8qHduQECCAE%3D">
        <span class="yt-valign-container">
            <span class="thumb guide-my-channel-icon yt-sprite"></span>
            <span class="display-name  no-count">
              <span>
                My Channel
              </span>
            </span>
        </span>
      </a>
....

1 个答案:

答案 0 :(得分:1)

你可以这样做:

var li = document.getElementById('create_channel-guide-item');
li.parentNode.removeChild(li);

但是,如果异步加载该内容,则需要重复此操作直到它起作用:

(function removeLi(try) {
    if (!try) return; // give up
    var li = document.getElementById('create_channel-guide-item');
    if (li) { // found!
        li.parentNode.removeChild(li);
        return;
    }
    setTimeout(removeLi.bind(null, try-1), 100);
})(100); // try 100 times