Nico Excluder

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

目前為 2020-06-17 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

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

(() => {
  'use strict';

  GM_setValue();

  /*
   * 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);
      },
    })
  });
})();