Rule34 AI Detector

Highlight AI generated images and add a toggle button to show/hide AI images

  1. // ==UserScript==
  2. // @name Rule34 AI Detector
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Highlight AI generated images and add a toggle button to show/hide AI images
  6. // @author Librake
  7. // @match https://rule34.xxx/index.php?page=post&s=list*
  8. // @icon https://goo.su/Hiqi7
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15. let scriptWorked = false;
  16.  
  17. function highlightAIGeneratedImages() {
  18. console.log(scriptWorked);
  19. if(!scriptWorked) {
  20. scriptWorked = true;
  21. const imageListDivs = document.querySelectorAll('div.image-list');
  22.  
  23. imageListDivs.forEach(imageListDiv => {
  24. const thumbs = imageListDiv.querySelectorAll('span.thumb');
  25.  
  26. thumbs.forEach(thumb => {
  27. const images = thumb.querySelectorAll('img');
  28.  
  29. images.forEach(img => {
  30. if (img.alt.includes('ai_generated')) {
  31. img.style.border = '3px solid #e5c100';
  32. }
  33. });
  34. });
  35. });
  36. }
  37. }
  38.  
  39. window.addEventListener('load', highlightAIGeneratedImages);
  40. setTimeout(highlightAIGeneratedImages, 1000);
  41.  
  42. addCustomButton();
  43.  
  44.  
  45. function addCustomButton() {
  46. let searchButton = document.getElementsByName("commit")[0];
  47. const container = document.querySelector('div.awesomplete');
  48. if (container) {
  49. const input = container.querySelector('input[name="tags"]');
  50. if (input) {
  51. const button = document.createElement('button');
  52.  
  53. function checkAiGenerated() {
  54. return input.value.includes('-ai_generated');
  55. }
  56.  
  57. function updateButtonState() {
  58. if (checkAiGenerated()) {
  59. button.textContent = 'Show AI';
  60. button.style.backgroundColor = '#A6F4FF';
  61. button.style.color = '#000000';
  62. button.dataset.state = 'visible';
  63. } else {
  64. button.textContent = 'Hide AI';
  65. button.style.backgroundColor = '#F2F2F2';
  66. button.style.color = '#000000';
  67. button.dataset.state = 'hidden';
  68. }
  69. }
  70.  
  71. function toggleAiGenerated() {
  72. if (checkAiGenerated()) {
  73. input.value = input.value.replace(/\s*-ai_generated/g, '');
  74. updateButtonState();
  75. } else {
  76. input.value = input.value + ' -ai_generated';
  77. updateButtonState();
  78. }
  79. }
  80.  
  81. updateButtonState();
  82.  
  83. button.style.cursor = 'pointer';
  84. button.style.display = 'block';
  85. button.style.margin = '3px 0';
  86. button.style.width = '50vw';
  87. button.style.maxWidth = '100px';
  88. button.style.padding = '2px 10px';
  89. button.style.border = '1px solid #636363';
  90. button.style.borderRadius = '5px';
  91. button.style.transition = 'background-color 0.3s';
  92. button.style.marginLeft = '0px';
  93.  
  94. button.addEventListener('mouseenter', () => {
  95. if (button.dataset.state === 'visible') {
  96. button.style.backgroundColor = '#90D2DB';
  97. } else {
  98. button.style.backgroundColor = '#A6F4FF';
  99. }
  100. });
  101. button.addEventListener('mouseleave', () => {
  102. if (checkAiGenerated()) {
  103. button.style.backgroundColor = '#A6F4FF';
  104. } else {
  105. button.style.backgroundColor = '#F2F2F2';
  106. }
  107. });
  108.  
  109. button.addEventListener('click', (event) => {
  110. event.preventDefault();
  111. toggleAiGenerated();
  112. searchButton.click();
  113. });
  114.  
  115. input.insertAdjacentElement('afterend', button);
  116. }
  117. }
  118. }
  119. })();