Greasy Fork is available in English.

ニコニコ動画(Re:仮)コメントフィルター(仮)

Filter out specific comments from JSON response

질문, 리뷰하거나, 이 스크립트를 신고하세요.
  1. // ==UserScript==
  2. // @name ニコニコ動画(Re:仮)コメントフィルター(仮)
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.11
  5. // @description Filter out specific comments from JSON response
  6. // @author Velgail
  7. // @match https://www.nicovideo.jp/watch_tmp/*
  8. // @grant none
  9. // @license The Unlicense
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // List of NG comments
  16. const ngComments = [
  17. "んん~まかァァウッッ!!!!🤏😎",
  18. "にょ、にょまれ~~✋🐮🤚💦",
  19. // ここに他のNGコメントを追加
  20. ];
  21.  
  22. // Intercept the fetch function
  23. const originalFetch = window.fetch;
  24. window.fetch = function(url, options) {
  25. if (url.startsWith('https://nvapi.nicovideo.jp/v1/tmp/comments/')) {
  26. return originalFetch(url, options).then(response => {
  27. return response.json().then(data => {
  28. // Filter the comments here
  29. if (data.data && data.data.comments) {
  30. data.data.comments = data.data.comments.filter(comment => !ngComments.includes(comment.message));
  31. }
  32. // Create a new Response object with the modified data
  33. const modifiedResponse = new Response(JSON.stringify(data), {
  34. status: response.status,
  35. statusText: response.statusText,
  36. headers: response.headers
  37. });
  38. return modifiedResponse;
  39. });
  40. });
  41. }
  42. return originalFetch(url, options);
  43. };
  44.  
  45. // Intercept the XMLHttpRequest
  46. const originalOpen = XMLHttpRequest.prototype.open;
  47. XMLHttpRequest.prototype.open = function(method, url) {
  48. this._url = url;
  49. return originalOpen.apply(this, arguments);
  50. };
  51.  
  52. const originalSend = XMLHttpRequest.prototype.send;
  53. XMLHttpRequest.prototype.send = function() {
  54. this.addEventListener('readystatechange', function() {
  55. if (this.readyState === 4 && this._url.startsWith('https://nvapi.nicovideo.jp/v1/tmp/comments/')) {
  56. try {
  57. const jsonResponse = JSON.parse(this.responseText);
  58. // Filter the comments here
  59. if (jsonResponse.data && jsonResponse.data.comments) {
  60. jsonResponse.data.comments = jsonResponse.data.comments.filter(comment => !ngComments.includes(comment.message));
  61. }
  62. // Override the responseText property
  63. Object.defineProperty(this, 'responseText', { value: JSON.stringify(jsonResponse) });
  64. } catch (e) {
  65. console.error('Failed to modify JSON response', e);
  66. }
  67. }
  68. });
  69. return originalSend.apply(this, arguments);
  70. };
  71. })();