Nico Excluder

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

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

  1. // ==UserScript==
  2. // @name Nico Excluder
  3. // @namespace https://i544c.github.io
  4. // @version 0.1.2
  5. // @description ユーザ拒否リストに引っかかった動画を非表示にする
  6. // @author i544c
  7. // @match https://www.nicovideo.jp/ranking/*
  8. // @grant GM_getValue
  9. // @grant GM_xmlhttpRequest
  10. // @run-at document-end
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. (() => {
  15. 'use strict';
  16.  
  17. /*
  18. * Hi!
  19. * You must set `denyUserList` to UserScript Manager.
  20. */
  21. const denyUserList = GM_getValue('denyUserList', []);
  22. const contentIdQueue = [];
  23.  
  24. window.setInterval(async () => {
  25. if (contentIdQueue.length === 0) return;
  26.  
  27. const contentId = contentIdQueue.shift();
  28. const userId = await getVideoMeta(contentId);
  29. console.log(contentId, userId);
  30. if (denyUserList.includes(userId)) {
  31. console.log('Goodbye!', `https://ext.nicovideo.jp/api/getthumbinfo/${contentId}`);
  32. document.querySelector(`div.MediaObject[data-video-id=${contentId}`).remove();
  33. }
  34. }, 1000);
  35.  
  36. const observer = new MutationObserver(mutations => {
  37. mutations.forEach(mutation => {
  38. if (mutation.type === 'attributes') {
  39. const contentId = mutation.target.parentElement.getAttribute('data-deflist-item-id');
  40. if (!contentId || contentIdQueue.includes(contentId)) return;
  41.  
  42. contentIdQueue.push(contentId);
  43. }
  44. });
  45. });
  46.  
  47. const thumbs = document.querySelectorAll('div.Thumbnail-image');
  48. thumbs.forEach(thumb => {
  49. observer.observe(thumb, { attributes: true });
  50. });
  51.  
  52. const getVideoMeta = contentId => new Promise((resolve, _reject) => {
  53. const url = encodeURI(`https://ext.nicovideo.jp/api/getthumbinfo/${contentId}`);
  54. GM_xmlhttpRequest({
  55. url,
  56. onload: meta => {
  57. const { responseText } = meta;
  58. const domparser = new DOMParser();
  59. const response = domparser.parseFromString(responseText, 'text/xml');
  60. const userId = response.getElementsByTagName('user_id')[0].textContent;
  61. resolve(userId);
  62. },
  63. })
  64. });
  65. })();