nHentai Spam Cleaner

Removes non standard characters from nHentai comments

  1. // ==UserScript==
  2. // @name nHentai Spam Cleaner
  3. // @namespace http://silentspud.com/
  4. // @version 1.1
  5. // @description Removes non standard characters from nHentai comments
  6. // @author Silent UwU
  7. // @match https://nhentai.net/g/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function () {
  12. 'use strict';
  13. if (!document.getElementById('comment-container')) return false;
  14.  
  15. // Time in milliseconds between hitting the bottom of the page and murdering this script
  16. // If it takes more than a second to load the comments for you, increase this
  17. const killPause = 1000;
  18.  
  19. const cleaner = new MutationObserver((mutationList, cleaner) => {
  20. for (const mutation of mutationList) {
  21. if (mutation.type == 'childList') {
  22. mutation.addedNodes.forEach(el => {
  23. if (typeof el == 'object' && el.innerHTML) {
  24. el.innerHTML = el.innerHTML.replace(/[\u0080-\uFFFF]/g, '');
  25. // Dirty fix for breaking nHentai's lazy loader
  26. if (el.querySelector('img[data-src]')) el.querySelector('img[data-src]').src = el.querySelector('img[data-src]').dataset.src;
  27. }
  28. });
  29. }
  30. }
  31. });
  32. cleaner.observe(document.getElementById('comment-container'), { childList: true, subtree: true });
  33.  
  34. const killMe = () => {
  35. if (!(document.scrollingElement.scrollHeight - window.innerHeight - document.scrollingElement.scrollTop > 0.1 * window.innerHeight)) {
  36. window.setTimeout(() => cleaner.disconnect(), killPause);
  37. window.removeEventListener('scroll', killMe);
  38. }
  39. };
  40. window.addEventListener('scroll', killMe);
  41. killMe();
  42. })();