nhentai show Tag in main page

nhentai show Tag in main page, and highlight/block tag

Od 09.07.2020.. Pogledajte najnovija verzija.

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