Greasy Fork

Greasy Fork is available in English.

bilibili大会员削除

去除“成为大会员”链接,将红名替换为原始格式,替换表情为纯文字

目前为 2016-12-18 提交的版本。查看 最新版本

// ==UserScript==
// @name         bilibili vip remover
// @name:zh-CN   bilibili大会员削除
// @namespace    myfreeer
// @version      0.5
// @description  remove the 'become-vip' link, repalce red names to original, and replace emoji to pure text
// @description:zh-CN  去除“成为大会员”链接,将红名替换为原始格式,替换表情为纯文字
// @author       myfreeer
// @match        http://*.bilibili.com/*
// @match        http://*.bilibili.com/
// @license      MIT
// @grant        none
// ==/UserScript==

//code from http://javascript.ruanyifeng.com/dom/mutationobserver.html
(function(win){
  'use strict';

  var listeners = [];
  var doc = window.document;
  var MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
  var observer;

  function ready(selector, fn){
    // 储存选择器和回调函数
    listeners.push({
      selector: selector,
      fn: fn
    });
    if(!observer){
      // 监听document变化
      observer = new MutationObserver(check);

observer.observe(doc.documentElement, {
        childList: true,
        subtree: true
      });
    }
    // 检查该节点是否已经在DOM中
    check();
  }

  function check(){
  // 检查是否匹配已储存的节点
    for(var i = 0; i < listeners.length; i++){
      var listener = listeners[i];
      // 检查指定节点是否有匹配
      var elements = doc.querySelectorAll(listener.selector);
      for(var j = 0; j < elements.length; j++){
        var element = elements[j];
        // 确保回调函数只会对该元素调用一次
        if(!element.ready){
          element.ready = true;
          // 对该节点调用回调函数
          listener.fn.call(element, element);
        }
      }
    }
  }

  // 对外暴露ready
  win.ready = ready;

})(this);

//from https://lvwenhan.com/web-front/374.html
function removeClass(obj, cls){
    var obj_class = ' '+obj.className+' ';//获取 class 内容, 并在首尾各加一个空格. ex) 'abc        bcd' -> ' abc        bcd '
    obj_class = obj_class.replace(/(\s+)/gi, ' ');//将多余的空字符替换成一个空格. ex) ' abc        bcd ' -> ' abc bcd '
    var removed = obj_class.replace(' '+cls+' ', ' ');//在原来的 class 替换掉首尾加了空格的 class. ex) ' abc bcd ' -> 'bcd '
    removed = removed.replace(/(^\s+)|(\s+$)/g, '');//去掉首尾空格. ex) 'bcd ' -> 'bcd'
    obj.className = removed;//替换原来的 class.
}

function addStyle(css) {
    if (!css) return false;
    var head = document.head || document.getElementsByTagName('head')[0],
        style = document.createElement('style');
    style.type = 'text/css';
    if (style.styleSheet) {
        style.styleSheet.cssText = css;
    } else {
        style.appendChild(document.createTextNode(css));
    }
    head.appendChild(style);
}

var becomevip=document.getElementById('i_menu_become_vip');
if (becomevip) becomevip.remove();
var vip=document.getElementsByClassName('b-vip-red');
for (var i in vip) removeClass(vip[i], 'b-vip-red');
var vip2=document.getElementsByClassName('b-vip-emoji');
for (var i in vip2) vip2[i].outerHTML=vip2[i].alt;
var vip3=document.getElementsByClassName('h-vipType');
for (var i in vip3) if (vip3[i].remove) vip3[i].remove();
var vip4=document.querySelectorAll('span.user-auth-subscript');
for (var i in vip4) if (vip4[i].remove) if (vip4[i].title==="大会员") vip4[i].remove();

ready('.b-vip-red', function (e) {
  removeClass(e, 'b-vip-red');
});
ready('.b-vip-emoji', function (e) {
  e.outerHTML = e.alt;
});
ready('.h-vipType', function (e) {
  if (e.remove) e.remove();
});
ready('span.user-auth-subscript', function (e) {
  if (e.remove) if (e.title==="大会员") e.remove();
});

addStyle('.user-auth-subscript{background-image: url(http://static.hdslb.com/spacev2/1/img/user-auth.png) !important}.h-vipType,#i_menu_become_vip{display:none !important}');