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

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

// ==UserScript==
// @name Bilibili屏蔽首页上不想看的视频
// @namespace Max's Scripts
// @version 1.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>
  .bili-x-card {position: relative;}
  .bili-x-card > .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}
  .bili-x-card:hover > .x {display:block}
</stlye>`);
localStorage.blacklist = localStorage.blacklist || []
localStorage.keywords = localStorage.keywords || []
var findId = (module) => {
  let a = $('> .card-pic > a',module).get(0) || $('> .info-box > a',module).get(0) || $('>a',module).get(0) || module.href && module;
  let id = ((a.dataset && a.dataset['data-target-url'] || a.href).match(/(BV[0-9a-zA-Z]+|space\.bilibili\.com\/\d+|live\.bilibili\.com\/\d+|manga\.bilibili\.com\/detail\/mc\d+)/g) || [null])[0];
  return id
}
setInterval(function(){
  let cards = $('.video-card-common,.video-card-reco,.live-card,.manga-card');
  let blacklist = localStorage.blacklist.split(',');
  let keywords = localStorage.keywords.split(',');
  cards.each((i, c)=>{
    let card = $(c);
    if(card.is(':empty'))
      return;
    let xid = card.attr('xid');
    if(xid){
      if(blacklist.includes(xid)){
        card.remove();
        console.log('removed', xid.toString());
      }
    } else {
      let x = $('<div class=x>x</div>')
        .click(function(e){
          let card = this.parentNode;
          let id = findId(card);
          if(!id)return false;
          if(id.match(/\?/))
            id = id.slice(0, id.indexOf('?'))
          blacklist.push(id);
          localStorage.setItem('blacklist', blacklist);
          $(this).parent().remove();
          console.log('removed', id.toString())
          e.stopPropagation();
          if(card.href){
            card.href = 'javascript:void(0)'
            card.target = '_self'
          }
        });
     card.append(x).attr('xid', findId(card.get(0))).addClass('bili-x-card');
    }
  });
}, 1000)