Greasy Fork

Greasy Fork is available in English.

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

有的视频真的不想点开,比如恐怖的,连预览都不想看到,但却总是出现在首页.点击视频预览图右上角的x,不喜欢的视频会被移除,并记录在localStorage,以后都不会出现在首页了.

当前为 2021-04-03 提交的版本,查看 最新版本

// ==UserScript==
// @name Bilibili屏蔽首页上不想看的视频
// @namespace Max's Scripts
// @version 1.0.7
// @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.card-pic > div.x {position:absolute;width:10px;height:10px;top:0;right:0;color:#fff;cursor:pointer;z-index:1;display:none}
  div.card-pic:hover > div.x {display:block}
</stlye>`);
localStorage.blacklist = localStorage.blacklist || []
localStorage.keywords = localStorage.keywords || []
setInterval(function(){
  let blacklist = localStorage.blacklist.split(',');
  let keywords = localStorage.keywords.split(',');
  let modules = jQuery('div.card-pic');
  modules.each((i, m)=>{
    if(jQuery.find('>div.x', m).length)
      return;
    let x = jQuery('<div class=x>x</div>')
      .click(function(){
        let _x = jQuery(this);
        let a = _x.siblings('a').get(0);
        let id = ((a.dataset.targetUrl || a.href).match(/(av\\d+|BV.+)/) || [null])[0];
        if(!id)return false;
        blacklist.push(id);
        localStorage.setItem('blacklist', blacklist);
        _x.parents('.video-card-common').remove();
        console.log('removed', id.toString())
      });
    jQuery(m).append(x);
  });
  modules.find('>a').each((i, a)=>{
    let id = ((a.dataset.targetUrl || a.href).match(/(av\\d+|BV.+)/) || [null])[0];
    if(!id)return true;
    let title = jQuery('p', a).attr('title') || jQuery(a).parent().siblings('.title').attr('title');
    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('.video-card-common').remove();
      console.log('removed', id.toString());
    }
  })
}, 1000)