MyAnimeList(MAL) - Search Filter

This script hides search results that you already have on your list

  1. // MAL Search Filter!
  2. // version 1.2
  3. // 2010-06-14
  4. // Copyright (c) 2009, Bastvera <bastvera@gmail.com>
  5. // Released under the GPL license
  6. // http://www.gnu.org/copyleft/gpl.html
  7.  
  8. // ==UserScript==
  9. // @name MyAnimeList(MAL) - Search Filter
  10. // @match *://myanimelist.net/anime.php*
  11. // @match *://myanimelist.net/manga.php*
  12. // @match *://myanimelist.net/topanime.php*
  13. // @match *://myanimelist.net/topmanga.php*
  14. // @match *://myanimelist.net/anime/genre/*
  15. // @match *://myanimelist.net/manga/genre/*
  16. // @match *://myanimelist.net/manga/magazine/*
  17. // @exclude *://myanimelist.net/anime/producer/*
  18. // @exclude *://myanimelist.net/anime.php
  19. // @exclude *://myanimelist.net/manga.php
  20. // @exclude *://myanimelist.net/anime.php?id=*
  21. // @exclude *://myanimelist.net/manga.php?id=*
  22. // @description This script hides search results that you already have on your list
  23. // @version 1.4.6
  24. // @author Bastvera <bastvera@gmail.com>, Cpt_mathix <fixed script>
  25. // @license GPL-2.0-or-later; http://www.gnu.org/licenses/gpl-2.0.txt
  26. // @namespace https://greasyfork.org/users/16080
  27. // ==/UserScript==
  28.  
  29. //Anchor for checkbox
  30. let anchor = document.querySelector("#content > div.normal_header") || document.querySelector("#content h2");
  31.  
  32. if(anchor !== null){
  33. injectCSS();
  34.  
  35. //Element Placing
  36. var newElement;
  37. newElement = document.createElement('BR');
  38. anchor.appendChild(newElement);
  39.  
  40. var checkbox1 = document.createElement('input');
  41. checkbox1.type = 'checkbox';
  42. checkbox1.className = 'filterbox';
  43. anchor.appendChild(checkbox1);
  44.  
  45. newElement = document.createElement('label');
  46. newElement.setAttribute('for','firstName');
  47. var url = document.location.href;
  48. if (/myanimelist.net\/manga/.test(url)) {
  49. newElement.appendChild(document.createTextNode('Hide Search Results that you have on your list. (Show PTR:'));
  50. } else {
  51. newElement.appendChild(document.createTextNode('Hide Search Results that you have on your list. (Show PTW:'));
  52. }
  53. anchor.appendChild(newElement);
  54. newElement.style.fontWeight="normal";
  55. newElement.style.fontSize="10px";
  56.  
  57. var checkbox2 = document.createElement('input');
  58. checkbox2.type = 'checkbox';
  59. checkbox2.className = 'filterbox';
  60. anchor.appendChild(checkbox2);
  61.  
  62. newElement = document.createElement('label');
  63. newElement.setAttribute('for','firstName');
  64. newElement.appendChild(document.createTextNode(')'));
  65. anchor.appendChild(newElement);
  66. newElement.style.fontWeight="normal";
  67. newElement.style.fontSize="10px";
  68.  
  69. //Anime list entries search
  70. var allElements = document.evaluate(
  71. "//a[(contains(@class,'js-anime-watch-status') or contains(@class, 'button_edit')) and not(contains(@class,'notinmylist'))]",
  72. document,
  73. null,
  74. XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
  75. null);
  76.  
  77. var ptwElements = document.evaluate(
  78. "//a[contains(@class,'plantowatch') or contains(@class,'plantoread')]",
  79. document,
  80. null,
  81. XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
  82. null);
  83.  
  84. //Get or Set status of checkbox
  85. var activate = true;
  86. var checkboxmem1 = (localStorage.getItem('checkboxmem1_search') === "true"); //Get checkbox status
  87. if(checkboxmem1 === null){
  88. checkboxmem1 = false;
  89. localStorage.setItem('checkboxmem1_search', checkboxmem1);
  90. checkbox1.checked = checkboxmem1;
  91. activate = false;
  92. }
  93. var checkboxmem2 = (localStorage.getItem('checkboxmem2_search') === "true"); //Get checkbox status PTW
  94. if(checkboxmem2 === null){
  95. checkboxmem2 = false;
  96. localStorage.setItem('checkboxmem2_search', checkboxmem2);
  97. checkbox2.checked = checkboxmem2;
  98. activate = false;
  99. }
  100.  
  101. if (activate) {
  102. checkbox1.checked = checkboxmem1;
  103. checkbox2.checked = checkboxmem2;
  104. if(checkbox1.checked === true) {
  105. HideDivs(checkboxmem2, allElements);
  106. }
  107. }
  108.  
  109. //Listener 1
  110. checkbox1.addEventListener('change',function () {
  111.  
  112. if(checkbox1.checked === true){
  113. checkbox2.disabled = false;
  114. HideDivs(checkbox2.checked, allElements);
  115. }
  116.  
  117. if(checkbox1.checked === false){
  118. checkbox2.disabled = true;
  119. ShowDivs(checkbox2.checked, allElements);
  120. }
  121.  
  122. localStorage.setItem('checkboxmem1_search', checkbox1.checked);
  123.  
  124. },false);
  125.  
  126. //Listener 2
  127. checkbox2.addEventListener('change',function () {
  128.  
  129. if(checkbox2.checked === true && checkbox1.checked === true){
  130. ShowDivs(false, ptwElements);
  131. }
  132.  
  133. if(checkbox2.checked === false && checkbox1.checked === true){
  134. HideDivs(false, ptwElements);
  135. }
  136.  
  137. localStorage.setItem('checkboxmem2_search', checkbox2.checked);
  138.  
  139. },false);
  140. }
  141.  
  142. function HideDivs(showPTW, elements){
  143. var gridLayout = !!document.querySelector(".js-block-list > .seasonal-anime-list");
  144. var tableLayout = !!document.querySelector(".js-block-list > table") || !!document.querySelector("table.top-ranking-table");
  145. var tableAnimeSearchLayout = !!document.querySelector(".js-block-list.js-categories-seasonal > table") && document.querySelector("h1").innerText.indexOf("Anime") > -1;
  146.  
  147. for (var i = 0; i < elements.snapshotLength; i++) {
  148. var EditLink = elements.snapshotItem(i);
  149. var showIfPTW = showPTW ? !EditLink.classList.contains("plantowatch") && !EditLink.classList.contains("plantoread") : true;
  150.  
  151. if ((gridLayout || tableAnimeSearchLayout) && showIfPTW) {
  152. EditLink.parentNode.parentNode.parentNode.style.display="none";
  153. } else if (tableLayout && showIfPTW) {
  154. EditLink.parentNode.parentNode.style.display="none";
  155. }
  156. }
  157.  
  158. var article = document.querySelector("#content article");
  159. if (article) {
  160. article.style.display="none";
  161. }
  162.  
  163. var ad = document.querySelector(".js-middle_ad.seasonal-middle");
  164. if (ad) {
  165. ad.style.display="none";
  166. }
  167. }
  168.  
  169. function ShowDivs(showPTW, elements){
  170. var gridLayout = !!document.querySelector(".js-block-list > .seasonal-anime-list");
  171. var tableLayout = !!document.querySelector(".js-block-list > table") || !!document.querySelector("table.top-ranking-table");
  172. var tableAnimeSearchLayout = !!document.querySelector(".js-block-list.js-categories-seasonal > table") && document.querySelector("h1").innerText.indexOf("Anime") > -1;
  173.  
  174. for (var i = 0; i < elements.snapshotLength; i++){
  175. var EditLink = elements.snapshotItem(i);
  176. var showIfPTW = showPTW ? !EditLink.classList.contains("plantowatch") && !EditLink.classList.contains("plantoread") : true;
  177.  
  178. if ((gridLayout || tableAnimeSearchLayout) && showIfPTW) {
  179. EditLink.parentNode.parentNode.parentNode.removeAttribute('style');
  180. } else if (tableLayout && showIfPTW) {
  181. EditLink.parentNode.parentNode.removeAttribute('style');
  182. }
  183. }
  184.  
  185. var article = document.querySelector("#content article");
  186. if (article) {
  187. article.removeAttribute('style');
  188. }
  189. }
  190.  
  191. function injectCSS() {
  192. var css = `
  193. input.filterbox {
  194. width: 13px;
  195. height: 13px;
  196. padding: 0;
  197. margin: 6px 2px 0 2px;
  198. vertical-align: bottom;
  199. }
  200. `;
  201.  
  202. var style = document.createElement("style");
  203. style.type = "text/css";
  204. if (style.styleSheet){
  205. style.styleSheet.cssText = css;
  206. } else {
  207. style.appendChild(document.createTextNode(css));
  208. }
  209.  
  210. document.documentElement.appendChild(style);
  211. }