Manga cleaner & loader

img:click/arrow-key, back:top-left, width:top-right/w-key, load:bottom-right, remove crap

  1. // ==UserScript==
  2. // @name Manga cleaner & loader
  3. // @version 1.0.9
  4. // @description img:click/arrow-key, back:top-left, width:top-right/w-key, load:bottom-right, remove crap
  5. // @namespace https://greasyfork.org/users/3159
  6. // @grant GM_getValue
  7. // @grant GM_setValue
  8. // @include http*://*e-hentai.org/s/*
  9. // @include http*://exhentai.org/s/*
  10. // @include http*://*hentairules.net/galleries*/picture.php?/*
  11. // ==/UserScript==
  12.  
  13. //startup
  14. var loc = location.hostname.indexOf('hentairules.net') > -1 ? 1 : 2;
  15. var next,o,t;
  16. if (loc == 1) {
  17. location.href = document.getElementById('derivativeSwitchBox').children[5].href; //need to reload page for this to take effect
  18.  
  19. //next = document.getElementById('linkNext').href;
  20. next = document.getElementsByClassName('pwg-button-icon-right')[0].href;
  21.  
  22. o = document.getElementById('theMainImage').src;
  23. t = document.getElementsByClassName('browsePath')[0].children[1].innerText;
  24. }
  25. else if (loc == 2) {
  26. var a = document.getElementsByTagName('a');
  27. next = a[2].href;
  28. var last = a[3].href;
  29. o = a[4].children[0].src;
  30. t = document.title;
  31. }
  32. var array = [o];
  33. var w = 0;
  34. var i = 0;
  35. var y = 0;
  36. document.head.innerHTML = '<title>' + t + '</title><style>html{height:100%}body{height:100%;margin:0}img{width:100%;max-width:100%;margin-left:auto;margin-right:auto;display:block}div{width:100px;height:100px;position:fixed}div:hover{background:rgba(0,0,0,.5)}</style>';
  37. document.body.innerHTML = '';
  38. var img = new Image();
  39. img.src = o;
  40. document.body.appendChild(img);
  41.  
  42. //background
  43. var gi;
  44. function current() {
  45. gi = document.getElementsByTagName('img');
  46. for (var a = 0; a < gi.length; a++) {
  47. if (window.pageYOffset + window.innerHeight >= gi[a].offsetTop) {
  48. o = a;
  49. }
  50. }
  51. return o;
  52. }
  53.  
  54. function cnimage(i) {
  55. if (!gi[i] && array[i]) {
  56. var bimg = new Image();
  57. bimg.src = array[i];
  58. document.body.appendChild(bimg);
  59. }
  60. }
  61.  
  62. var onScrollStart = function () {
  63. if (y) {
  64. var x = current();
  65. cnimage(x + 1);
  66. cnimage(x + 2);
  67. cnimage(x + 3);
  68. cnimage(x + 4);
  69. }
  70. };
  71.  
  72. window.addEventListener("scroll", onScrollStart, false);
  73.  
  74. function parray() {
  75. var r = document.implementation.createHTMLDocument("temp");
  76. var x = new XMLHttpRequest();
  77. x.onreadystatechange = function () {
  78. if (x.readyState == 4 && x.status == 200) {
  79. var a = x.responseText;
  80. r.documentElement.innerHTML = a;
  81. if (loc == 1) {
  82. var ti = r.getElementsByTagName('img')[0].outerHTML.split('src="')[1].split('"')[0];
  83. var nn = r.getElementsByClassName('pwg-button-icon-right')[0].outerHTML;
  84. next = nn.split('href="')[1] ? nn.split('href="')[1].split('"')[0] : "";
  85. if (next === "") {
  86. w = 2;
  87. }
  88. }
  89. else if (loc == 2) {
  90. var aa = r.getElementsByTagName('a');
  91. ti = aa[4].children[0].src;
  92. next = aa[2].href;
  93. if (next == last) {
  94. w++;
  95. }
  96. }
  97. array.push(ti);
  98. if (w < 2) {
  99. parray();
  100. }
  101. }
  102. };
  103. x.open('GET', next, true);
  104. x.send();
  105. return;
  106. }
  107. parray();
  108.  
  109. img.onclick = function () {
  110. if ((i + 1) < array.length) {
  111. img.src = array[++i];
  112. }
  113. };
  114.  
  115. window.document.onkeydown = function () {};
  116. document.addEventListener("keydown", function (e) {
  117. switch (e.which) {
  118. case 39:
  119. if ((i + 1) < array.length) {
  120. img.src = array[++i];
  121. }
  122. break;
  123. case 37:
  124. if (i > 0) {
  125. img.src = array[--i];
  126. }
  127. break;
  128. case 87:
  129. cwidth();
  130. break;
  131. }
  132. });
  133.  
  134. var timg1 = new Image();
  135. var timg2 = new Image();
  136. var timg3 = new Image();
  137. var timg4 = new Image();
  138. var timg5 = new Image();
  139. var timg6 = new Image();
  140. var timg7 = new Image();
  141. var timg8 = new Image();
  142.  
  143. img.onload = function () {
  144. window.scrollTo(0, 0);
  145. array[i + 1] ? timg1.src = array[i + 1] : null;
  146. array[i + 2] ? timg2.src = array[i + 2] : null;
  147. array[i + 3] ? timg3.src = array[i + 3] : null;
  148. array[i + 4] ? timg4.src = array[i + 4] : null;
  149. array[i - 1] ? timg5.src = array[i - 1] : null;
  150. array[i - 2] ? timg6.src = array[i - 2] : null;
  151. array[i - 3] ? timg7.src = array[i - 3] : null;
  152. array[i - 4] ? timg8.src = array[i - 4] : null;
  153. };
  154.  
  155. //buttons
  156.  
  157. var load = document.createElement("div");
  158. load.style.cssText = "right:0;bottom:0";
  159. load.onclick = function () {
  160. y = 1;
  161. load.style.display = "none";
  162. width.style.position = back.style.position = "absolute";
  163. if (array[1]) {
  164. var aimg = new Image();
  165. aimg.src = array[1];
  166. document.body.appendChild(aimg);
  167. }
  168. };
  169.  
  170. var back = document.createElement("div");
  171. back.style.cssText = "top:0;left:0";
  172. back.onclick = function () {
  173. if (i > 0) {
  174. img.src = array[--i];
  175. }
  176. };
  177.  
  178. var sstyle = document.createElement("style");
  179. document.head.appendChild(sstyle);
  180.  
  181. if (GM_getValue("magsave")) {
  182. sstyle.innerText = "img{max-height:100%;width:inherit}";
  183. }
  184.  
  185. function cwidth() {
  186. if (GM_getValue("magsave")) {
  187. sstyle.innerText = "img{max-height:inherit;width:100%}";
  188. GM_setValue("magsave", 0);
  189. } else {
  190. sstyle.innerText = "img{max-height:100%;width:inherit}";
  191. GM_setValue("magsave", 1);
  192. }
  193. }
  194.  
  195. var width = document.createElement("div");
  196. width.style.cssText = "top:0;right:0";
  197. width.onclick = function () {
  198. cwidth();
  199. };
  200.  
  201. var down = document.createElement("div");
  202. down.style.cssText = "bottom:0;left:0";
  203. down.onclick = function () {
  204. var images = document.getElementsByTagName("img");
  205. var urls = '';
  206. for (i = 0; i < images.length; i++) {
  207. urls += images[i].src;
  208. urls += "<br />";
  209. }
  210. urls += "copy links<br />in terminal use nano to create a file called urls<br />run the command:<br />mkdir a && cd a && xargs -n 1 curl -O < ../urls && echo 'done'";
  211. document.body.innerHTML = urls;
  212. };
  213.  
  214. document.body.appendChild(back);
  215. document.body.appendChild(width);
  216. document.body.appendChild(load);
  217. document.body.appendChild(down);