Nico Excluder

ユーザ拒否リストに引っかかった動画を非表示にする

当前为 2020-06-17 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Nico Excluder
// @namespace    https://i544c.github.io
// @version      0.1.2
// @description  ユーザ拒否リストに引っかかった動画を非表示にする
// @author       i544c
// @match        https://www.nicovideo.jp/ranking/*
// @grant        GM_getValue
// @grant        GM_xmlhttpRequest
// @run-at       document-end
// @license      MIT
// ==/UserScript==

(() => {
  'use strict';

  /*
   * Hi!
   * You must set `denyUserList` to UserScript Manager.
   */
  const denyUserList = GM_getValue('denyUserList', []);
  const contentIdQueue = [];

  window.setInterval(async () => {
    if (contentIdQueue.length === 0) return;

    const contentId = contentIdQueue.shift();
    const userId = await getVideoMeta(contentId);
    console.log(contentId, userId);
    if (denyUserList.includes(userId)) {
      console.log('Goodbye!', `https://ext.nicovideo.jp/api/getthumbinfo/${contentId}`);
      document.querySelector(`div.MediaObject[data-video-id=${contentId}`).remove();
    }
  }, 1000);

  const observer = new MutationObserver(mutations => {
    mutations.forEach(mutation => {
      if (mutation.type === 'attributes') {
        const contentId = mutation.target.parentElement.getAttribute('data-deflist-item-id');
        if (!contentId || contentIdQueue.includes(contentId)) return;

        contentIdQueue.push(contentId);
      }
    });
  });

  const thumbs = document.querySelectorAll('div.Thumbnail-image');
  thumbs.forEach(thumb => {
    observer.observe(thumb, { attributes: true });
  });

  const getVideoMeta = contentId => new Promise((resolve, _reject) => {
    const url = encodeURI(`https://ext.nicovideo.jp/api/getthumbinfo/${contentId}`);
    GM_xmlhttpRequest({
      url,
      onload: meta => {
        const { responseText } = meta;
        const domparser = new DOMParser();
        const response = domparser.parseFromString(responseText, 'text/xml');
        const userId = response.getElementsByTagName('user_id')[0].textContent;
        resolve(userId);
      },
    })
  });
})();