Sleazy Fork is available in English.

nhentai show Tag in search page

nhentai show Tag in search page, and highlight block function

目前为 2020-02-17 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name nhentai show Tag in search page
  3. // @name:ja nhentai show Tag in search page
  4. // @name:zh-TW nhentai show Tag in search page
  5. // @name:zh-CN nhentai show Tag in search page
  6. // @namespace nhentai_display_and_highlight_tag_with_thumbnail
  7. // @supportURL https://github.com/zhuzemin
  8. // @description nhentai show Tag in search page, and highlight block function
  9. // @description:zh-CN nhentai show Tag in search page, and highlight block function
  10. // @description:zh-TW nhentai show Tag in search page, and highlight block function
  11. // @description:ja nhentai show Tag in search page, and highlight block function
  12. // @include https://nhentai.net/*
  13. // @include https://en.nyahentai3.com/*
  14. // @include https://zh.nyahentai.co/*
  15. // @include https://ja.nyahentai.net/*
  16. // @include https://zh.nyahentai.pro/*
  17. // @include https://ja.nyahentai.org/g/*
  18. // @include https://zh.nyahentai4.com/g/*
  19. // @version 1.5
  20. // @grant GM_xmlhttpRequest
  21. // @grant GM_registerMenuCommand
  22. // @grant GM_setValue
  23. // @grant GM_getValue
  24. // @run-at document-start
  25. // @author zhuzemin
  26. // @license Mozilla Public License 2.0; http://www.mozilla.org/MPL/2.0/
  27. // @license CC Attribution-ShareAlike 4.0 International; http://creativecommons.org/licenses/by-sa/4.0/
  28. // ==/UserScript==
  29. var config = {
  30. 'debug': false
  31. }
  32. var debug = config.debug ? console.log.bind(console) : function () {
  33. };
  34.  
  35. // setting User Preferences
  36. function setUserPref(varName, defaultVal, menuText, promtText, sep){
  37. GM_registerMenuCommand(menuText, function() {
  38. var val = prompt(promtText, GM_getValue(varName, defaultVal));
  39. if (val === null) { return; } // end execution if clicked CANCEL
  40. // prepare string of variables separated by the separator
  41. if (sep && val){
  42. var pat1 = new RegExp('\\s*' + sep + '+\\s*', 'g'); // trim space/s around separator & trim repeated separator
  43. var pat2 = new RegExp('(?:^' + sep + '+|' + sep + '+$)', 'g'); // trim starting & trailing separator
  44. //val = val.replace(pat1, sep).replace(pat2, '');
  45. }
  46. //val = val.replace(/\s{2,}/g, ' ').trim(); // remove multiple spaces and trim
  47. GM_setValue(varName, val);
  48. // Apply changes (immediately if there are no existing highlights, or upon reload to clear the old ones)
  49. //if(!document.body.querySelector(".THmo")) THmo_doHighlight(document.body);
  50. //else location.reload();
  51. });
  52. }
  53.  
  54. // prepare UserPrefs
  55. setUserPref(
  56. 'highlights',
  57. 'chinese;',
  58. 'Set Highlight Tags',
  59. `Set highlights, split with ";". Example: "mmf threesome; chinese"`,
  60. ','
  61. );
  62. setUserPref(
  63. 'BlackList',
  64. 'english;',
  65. 'Set BlackList',
  66. `Set BlackList, split with ";". Example: "chinese; yaoi"`,
  67. ','
  68. );
  69.  
  70.  
  71. CreateStyle=function(){
  72. debug("Start: CreateStyle");
  73. var style=document.createElement("style");
  74. style.setAttribute("type","text/css");
  75. style.innerHTML=`
  76. .glowbox {
  77. background: #4c4c4c;
  78. //width: 400px;
  79. //margin: 40px 0 0 40px;
  80. //padding: 10px;
  81. -moz-box-shadow: 0 0 5px 5px #FFFF00;
  82. -webkit-box-shadow: 0 0 5px 5px #FFFF00;
  83. box-shadow: 0 0 5px 5px #FFFF00;
  84. }
  85. `;
  86. debug("Processing: CreateStyle");
  87. var head=document.querySelector("head");
  88. head.insertBefore(style,null);
  89. debug("End: CreateStyle");
  90. }
  91. class Gallery{
  92. constructor(href,other=null) {
  93. this.method = 'GET';
  94. this.url = href;
  95. this.headers = {
  96. 'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey',
  97. 'Accept': 'application/atom+xml,application/xml,text/xml',
  98. 'Referer': window.location.href,
  99. };
  100. this.charset = 'text/plain;charset=utf8';
  101. this.other=other;
  102. }
  103. }
  104. var BlackListLast=[];
  105. var highlightsLast=[];
  106. var DivCount;
  107. function HighlightTag(responseDetails,divs){
  108. //debug("HighlightTag");
  109. var dom;
  110. if(responseDetails!=null){
  111. var responseText=responseDetails.responseText;
  112. dom = new DOMParser().parseFromString(responseText, "text/html");
  113.  
  114. }
  115. var highlights;
  116. var BlackList;
  117. try{
  118. highlights=GM_getValue("highlights").trim().replace(/;$/,"").split(";");
  119. BlackList=GM_getValue("BlackList").trim().replace(/;$/,"").split(";");
  120. }catch(e){
  121. debug("Not set GM_Value.");
  122. }
  123. if (BlackList == undefined||BlackList.length ==0) {
  124. BlackList = [];
  125. }
  126. if (highlights == undefined||highlights.length ==0) {
  127. highlights = [];
  128. }
  129. debug("BlackList: " + BlackList);
  130. if(responseDetails!=null||JSON.stringify(BlackList)!=JSON.stringify(BlackListLast)||JSON.stringify(highlights)!=JSON.stringify(highlightsLast)){
  131.  
  132. var taglist;
  133. var NewDivs;
  134. if(responseDetails==null){
  135. NewDivs = divs;
  136. }
  137. else{
  138. NewDivs=[0];
  139. }
  140. //debug("NewDivs.length: "+NewDivs.length);
  141. for(var i=0;i<NewDivs.length;i++){
  142. var Break=false;
  143. var div;
  144. if(responseDetails!=null){
  145. div=divs[DivCount];
  146. taglist = dom.querySelector('#tags');
  147. }
  148. else{
  149. div=divs[i];
  150. taglist = div.querySelector('#tags');
  151.  
  152. }
  153. //debug(taglist);
  154. var links = taglist.querySelectorAll("a.tag");
  155. //debug(links);
  156. if(responseDetails!=null||JSON.stringify(BlackList)!=JSON.stringify(BlackListLast)){
  157. for (var link of links) {
  158. var tag = link.innerText.toLowerCase().match(/([\w\s]*)/)[1].trim();
  159. //debug("Tag: "+tag);
  160. for (var BlackWord of BlackList) {
  161. if (BlackWord.length > 1) {
  162. if (tag == BlackWord.trim()) {
  163. debug("BlackWord: " + link.innerText);
  164. div.className += " blacklisted";
  165. Break=true;
  166. break;
  167. }
  168. else if (link==links[links.length-1]&&BlackWord == BlackList[BlackList.length - 1]) {
  169. div.className = div.className.replace(" blacklisted", "");
  170. }
  171. }
  172. else{
  173. div.className = div.className.replace(" blacklisted", "");
  174.  
  175. }
  176. }
  177. if (Break) {
  178. break;
  179. }
  180. }
  181.  
  182. }
  183. if(responseDetails!=null||JSON.stringify(highlights)!=JSON.stringify(highlightsLast)){
  184. for (var link of links) {
  185. var tag = link.innerText.toLowerCase().match(/([\w\s]*)/)[1].trim();
  186. //debug("Tag: "+tag);
  187. for (var highlight of highlights) {
  188. if (highlight.length > 1) {
  189. //debug("Highlight: "+highlight);
  190. if (tag == highlight.trim()) {
  191. debug("highlight: " + link.innerText);
  192. link.className += " glowbox";
  193. break;
  194. }
  195. else if (highlight == highlights[highlights.length - 1]) {
  196. link.className = link.className.replace(" glowbox", "");
  197. }
  198. }
  199. else{
  200. link.className = link.className.replace(" glowbox", "");
  201.  
  202. }
  203. }
  204. }
  205.  
  206. }
  207.  
  208. if(responseDetails!=null) {
  209. var a = div.querySelector("a");
  210. a.replaceChild(taglist, a.querySelector("#tags"));
  211. DivCount++;
  212. }
  213. }
  214. if(responseDetails!=null) {
  215.  
  216. if (DivCount < divs.length) {
  217. MainWoker(divs);
  218. }
  219. }
  220. debug("BlackListLast: "+BlackListLast);
  221. debug("highlightsLast: "+highlightsLast);
  222. highlightsLast=highlights;
  223. BlackListLast=BlackList;
  224. }
  225.  
  226. }
  227.  
  228. function MainWoker(divs){
  229. debug("MainWoker");
  230. var div=divs[DivCount];
  231. div.style.maxHeight = "900px";
  232. div.style.height = "900px";
  233. var a = div.querySelector("a");
  234. var img = a.querySelector("img");
  235. var data_src=img.getAttribute("data-src");
  236. img.setAttribute("src",data_src);
  237. div.insertBefore(img, a);
  238. a.style.overflow = "auto";
  239. a.style.maxHeight = 900 - img.offsetHeight + "px";
  240. var caption = a.querySelector("div.caption");
  241. caption.style.position = "static";
  242. var taglist = document.createElement("section");
  243. taglist.setAttribute("id", "tags");
  244. a.insertBefore(taglist, null);
  245. var href = div.querySelector('a').href;
  246. //debug(href);
  247. var gallery = new Gallery(href);
  248. gallery.other=divs;
  249. request(gallery,HighlightTag);
  250.  
  251. }
  252. var init = function () {
  253. var LastDivNum=0;
  254. CreateStyle();
  255. DivCount=0;
  256. var html = document.querySelector('html');
  257. setInterval(function(){
  258. var divs = html.querySelectorAll('div.gallery');
  259. //debug("DivNum: "+divs.length);
  260. if(LastDivNum<divs.length) {
  261. html.style.height=divs.length/5*900+"px";
  262. debug("html.style.height: "+html.style.height);
  263. MainWoker(divs);
  264. }
  265. LastDivNum=divs.length;
  266. HighlightTag(null,divs);
  267. }, 2000)
  268. }
  269. function request(object,func) {
  270. var retries = 10;
  271. GM_xmlhttpRequest({
  272. method: object.method,
  273. url: object.url,
  274. headers: object.headers,
  275. overrideMimeType: object.charset,
  276. //synchronous: true
  277. onload: function (responseDetails) {
  278. if (responseDetails.status != 200) {
  279. // retry
  280. if (retries--) { // *** Recurse if we still have retries
  281. setTimeout(request,2000);
  282. return;
  283. }
  284. }
  285. //debug(responseDetails);
  286. //Dowork
  287. func(responseDetails,object.other);
  288. }
  289. })
  290. }
  291.  
  292. window.addEventListener('DOMContentLoaded', init);