yasama018 / 斗鱼主播BANLIST

// ==UserScript==
// @namespace     https://openuserjs.org/users/yasama018
// @name          斗鱼主播BANLIST
// @description   点击右下角拉黑可把主播拉进黑名单,黑名单展开时点击对应主播可以把他从黑名单中删除
// @copyright     2018, yasama018 (https://openuserjs.org/users/yasama018)
// @license       MIT
// @version       0.1.0 
// @match        https://www.douyu.com/*
// @updateURL https://openuserjs.org/meta/yasama018/斗鱼主播BANLIST.meta.js
// ==/UserScript==

// ==OpenUserJS==
// @author yasama018
// ==/OpenUserJS==

(function () {
  //BASE
  Array.prototype.indexOf = function (val) {
    for (var i = 0; i < this.length; i++) {
      if (this[i] == val) return i;
    }
    return -1;
  };
  Array.prototype.remove = function (val) {
    var index = this.indexOf(val);
    if (index > -1) {
      this.splice(index, 1);
    }
  };

  $("head").append("<style>#banlistui ul li{text-align:center;width:80px;}  .bnlb{color:white;border-radius: 10px;background-color:#1dd388;text-align:center;cursor:default;}#banlistui ul{background-color:white;color:white;display:none;position:absolute;top:36px;z-index:255;left:0px}#banlistui{z-index:250;}#blist_sw{background-color: #ff4960;border-radius: 12px;color: #fff;padding: 0 15px;line-height: 24px;font-size: 14px;cursor:default;}</style>");
  //加载 初始化BANLIST
  var banlist = [];
  if (localStorage.banlist) {
    banlist = JSON.parse(localStorage.banlist)
  }
  else {
    banlist = [];
    localStorage.banlist = JSON.stringify(banlist);
  }
  //屏蔽黑名单用户
  for (var i = 0; i < banlist.length; i++) {
    $(".video-nickname[title='" + banlist[i] + "']").parent().parent().parent().hide();
  }
  //for(var i=0;i<banlist.length;i++)
  //{ 
  //    $(".video-nickname[title='"+banlist[i]+"']").parent().parent().parent().remove();
  // } 
  //创建拉黑操作UI 
  var vk = 0;
  $(".video-label").each(function () {
    $(this).append('<a id="ban_' + vk + '" class="ban video-label-item label-color-3" style="postion:absolute;right:0px;top:0px;z-index:255;float:right;display: inline-block;font-size: 12px;border-radius: 100px;margin-right: 10px;cursor: pointer;margin-top: -10px;padding: 2px 11px;">拉黑</a>');

    $("#ban_" + vk).click(function () {
      var bn = $(this).parent().prev().find(".video-nickname").attr("title");
      banlist.push(bn);
      localStorage.banlist = JSON.stringify(banlist);
      $("#banlistui ul").append("<li><button class='bnlb'>" + bn + "</button></li>");

      $(this).parent().parent().hide();
    });

    vk++;
  });
  //创建 显示黑名单UI
  $(".main-header").append('<div id="banlistui" class="wonder-time-entrance"></div>');
  var html_blist = "<button id='blist_sw'>黑名单</button><ul>";
  for (var j = 0; j < banlist.length; j++) {
    html_blist += "<li><button class='bnlb'>" + banlist[j] + "</button></li>"
  }
  html_blist += "</ul>";
  $("#banlistui").html(html_blist);
  $("#blist_sw").click(function () {
    if ($("#banlistui ul").css('display') == 'none') {
      $("#banlistui ul").show();

    }
    else {

      $("#banlistui ul").hide();
    }
  });
  $(document).on("click", '.bnlb', function () {
    $(".video-nickname[title='" + $(this).html() + "']").parent().parent().parent().show();
    banlist.remove($(this).html());
    localStorage.banlist = JSON.stringify(banlist);
    $(this).parent().remove();
  });
})();