Greasy Fork

Greasy Fork is available in English.

Bilibili屏蔽首页上不想看的视频

有的视频真的不想点开,比如恐怖的,连预览都不想看到,但却总是出现在首页上。现在点击视频预览图右上角的x,不喜欢的视频就会被移除,并被记录在localStorage里,以后都不会再出现在首页了(除非删除了浏览器缓存)。

当前为 2021-10-02 提交的版本,查看 最新版本

// ==UserScript==
// @name Bilibili屏蔽首页上不想看的视频
// @namespace Max's Scripts
// @version 1.0.9.1
// @author Max
// @include https://www.bilibili.com/*
// @require http://libs.baidu.com/jquery/2.0.0/jquery.min.js
// @grant none
// @description 有的视频真的不想点开,比如恐怖的,连预览都不想看到,但却总是出现在首页上。现在点击视频预览图右上角的x,不喜欢的视频就会被移除,并被记录在localStorage里,以后都不会再出现在首页了(除非删除了浏览器缓存)。
// ==/UserScript==
$('head').append(`<style>
  div.bili-x-card {position: relative;}
  div.bili-x-card > div.x {position:absolute;width:15px;height:15px;top:0;right:0;font-size:15px;text-align:center;line-height:12px;color:#fff;cursor:pointer;z-index:99;display:none}
  div.bili-x-card:hover > div.x {display:block}
</stlye>`);
localStorage.blacklist = localStorage.blacklist || []
localStorage.keywords = localStorage.keywords || []
setInterval(function(){
  $('.bili-live-card,.bili-video-card,.bili-cheese-card,.bili-bangumi-card,.bili-movie-card,.bili-manga-card').addClass('bili-x-card');
  let blacklist = localStorage.blacklist.split(',');
  let keywords = localStorage.keywords.split(',');
  let modules = jQuery('div.bili-x-card');
  modules.each((i, m)=>{
    if(jQuery.find('>div.x', m).length)
      return;
    let x = jQuery('<div class=x>x</div>')
      .click(function(e){
        let _x = jQuery(this);
        let a = $('a', this.parentNode.childNodes[1]).get(0);
        let id = ((a.dataset && a.dataset['data-target-url'] || a.href).match(/(av\\d+|BV.+)/) || [null])[0];
        if(!id)return false;
        if(id.match(/\\?/))
          id = id.slice(0, id.indexOf('?'))
        blacklist.push(id);
        localStorage.setItem('blacklist', blacklist);
        _x.parent().remove();
        console.log('removed', id.toString())
        e.stopPropagation()
      });
    jQuery(m).append(x);
  });
  modules.find('>div:eq(1) a:eq(0)').each((i, a)=>{
    let id = ((a.dataset && a.dataset['data-target-url'] || a.href).match(/(av\\d+|BV.+)/) || [null])[0];
    if(!id)return true;
    if(id.match(/\\?/))
      id = id.slice(0, id.indexOf('\?'))
    let title = jQuery('h3', a.parentNode).text();
    if(keywords.find((keyword) => title.match(keyword))){
      blacklist.push(id);
      localStorage.setItem('blacklist', blacklist);
      console.log('keyword matched');
    }
    if(blacklist.includes(id)){
      jQuery(a).parents('.bili-x-card').remove();
      console.log('removed', id.toString());
    }
  })
}, 1000)