Manga Loader

Support for over 70 sites! Loads manga chapter into one page in a long strip format, supports switching chapters, minimal script with no dependencies, easy to implement new sites, loads quickly and works on mobile devices through bookmarklet

06.09.2016 itibariyledir. En son verisyonu görün.

  1. // ==UserScript==
  2. // @name Manga Loader
  3. // @namespace http://www.fuzetsu.com/MangaLoader
  4. // @version 1.10.6
  5. // @description Support for over 70 sites! Loads manga chapter into one page in a long strip format, supports switching chapters, minimal script with no dependencies, easy to implement new sites, loads quickly and works on mobile devices through bookmarklet
  6. // @copyright 2016+, fuzetsu
  7. // @noframes
  8. // @grant GM_getValue
  9. // @grant GM_setValue
  10. // @grant GM_deleteValue
  11. // @match *://bato.to/reader*
  12. // @match *://mangafox.me/manga/*/*/*
  13. // @match *://readms.com/r/*/*/*/*
  14. // @match *://mangastream.com/r/*/*/*/*
  15. // @match *://www.mangareader.net/*/*
  16. // @match *://*.mangahere.co/manga/*/*
  17. // @match *://www.mangapanda.com/*/*
  18. // @match *://mangapark.me/manga/*/*/*/*
  19. // @match *://mngcow.co/*/*
  20. // @match *://centraldemangas.org/online/*/*
  21. // @match *://*.com.br/leitura/online/capitulo/*
  22. // @match *://www.mangatown.com/manga/*/*
  23. // @match *://manga-joy.com/*/*
  24. // @match *://*.dm5.com/m*
  25. // @match *://*.senmanga.com/*/*
  26. // @match *://www.japscan.com/lecture-en-ligne/*
  27. // @match *://www.pecintakomik.com/manga/*/*
  28. // @match *://mangawall.com/manga/*/*
  29. // @match *://manga.animea.net/*
  30. // @match *://kissmanga.com/Manga/*/*
  31. // @match *://view.thespectrum.net/series/*
  32. // @match *://manhua.dmzj.com/*/*
  33. // @match *://hqbr.com.br/hqs/*/capitulo/*/leitor/0
  34. // @match *://www.dmzj.com/view/*/*
  35. // @match *://mangaindo.id/*/*
  36. // @match *://mangadoom.co/*/*
  37. // @match *://www.mangago.me/read-manga/*/*/*/*
  38. // @match *://mangalator.ch/show.php?gallery=*
  39. // @match *://eatmanga.com/Manga-Scan/*/*
  40. // @match *://www.mangacat.me/*/*/*
  41. // @match *://www.mangahen.com/*/*
  42. // @match *://www.readmanga.today/*/*
  43. // @match *://mangatraders.org/read-online/*/*
  44. // @match *://www.mangainn.net/manga/chapter/*
  45. // @match *://*.kukudm.com/comiclist/*/*
  46. // @match *://www.mangamap.com/*/*
  47. // @match *://www.mangachapter.me/*/*/*.html
  48. // @match *://kawaii.ca/reader/*
  49. // @match *://lonemanga.com/manga/*/*
  50. // @match *://read.egscans.com/om/manga/*/*
  51. // @match *://manga.madokami.al/reader/*
  52. // @match *://read.egscans.com/*
  53. // @match *://imperialscans.com/read/*
  54. // @match *://www.chuixue.com/manhua/*/*
  55. // @match *://www.sh-arab.com/manga/*
  56. // @match *://spinybackmanga.com/*
  57. // @match *://br.mangahost.com/manga/*/*
  58. // @match *://www.manga.ae/*/*/*
  59. // @match *://mangaforall.com/manga/*/*/*
  60. // @match *://hellocomic.com/*/*/*
  61. // @match *://www.3asq.info/*/*
  62. // @match *://*.readcomiconline.to/Comic/*
  63. // @match *://*.moonbunnycafe.com/*
  64. // @match *://*.mangaeden.com/*
  65. // @match *://*.comicastle.org/read-*
  66. // @match *://*.mymh8.com/chapter/*
  67. // @match *://*.unionmangas.net/leitor/*
  68. // @match *://*.otakusmash.com/*/*
  69. // -- FOOLSLIDE START
  70. // @match *://manga.redhawkscans.com/reader/read/*
  71. // @match *://reader.s2smanga.com/read/*
  72. // @match *://casanovascans.com/read/*
  73. // @match *://reader.vortex-scans.com/read/*
  74. // @match *://reader.roseliascans.com/read/*
  75. // @match *://mangatopia.net/slide/read/*
  76. // @match *://www.twistedhelscans.com/read/*
  77. // @match *://reader.sensescans.com/reader/read/*
  78. // @match *://reader.kireicake.com/read/*
  79. // @match *://substitutescans.com/reader/read/*
  80. // @match *://mangaichiscans.mokkori.fr/fs/read/*
  81. // @match *://reader.shoujosense.com/read/*
  82. // @match *://www.friendshipscans.com/slide/read/*
  83. // @match *://manga.famatg.com/read/*
  84. // @match *://www.demonicscans.com/FoOlSlide/read/*
  85. // @match *://reader.psscans.info/read/*
  86. // @match *://otscans.com/foolslide/read/*
  87. // @match *://necron99scans.com/reader/read/*
  88. // @match *://manga.inpowerz.com/read/*
  89. // @match *://reader.evilflowers.com/read/*
  90. // @match *://reader.cafeconirst.com/read/*
  91. // @match *://kobato.hologfx.com/reader/read/*
  92. // @match *://abandonedkittenscans.mokkori.fr/reader/read/*
  93. // @match *://jaiminisbox.com/reader/read/*
  94. // @match *://reader.sensescans.com/read/*
  95. // @match *://*.gomanga.co/reader/read/*
  96. // -- FOOLSLIDE END
  97. // ==/UserScript==
  98.  
  99. // short reference to unsafeWindow (or window if unsafeWindow is unavailable e.g. bookmarklet)
  100. var W = (typeof unsafeWindow === 'undefined') ? window : unsafeWindow;
  101.  
  102. var scriptName = 'Manga Loader';
  103. var pageTitle = document.title;
  104.  
  105. var IMAGES = {
  106. refresh_large: '//rgeorgeeb-tilebuttongenerator.googlecode.com/hg-history/c35993682c2d50149976fd7a1f302f8c01a88716/asset-studio/src/res/clipart/icons/refresh.svg'
  107. };
  108.  
  109. // reusable functions to insert in implementations
  110. var reuse = {
  111. encodeChinese: function(xhr) {
  112. xhr.overrideMimeType('text/html;charset=gbk');
  113. },
  114. na: function() {
  115. return 'N/A';
  116. }
  117. };
  118.  
  119. /**
  120. Sample Implementation:
  121. {
  122. name: 'something' // name of the implementation
  123. , match: "^https?://domain.com/.*" // the url to react to for manga loading
  124. , img: '#image' // css selector to get the page's manga image
  125. , next: '#next_page' // css selector to get the link to the next page
  126. , numpages: '#page_select' // css selector to get the number of pages. elements like (select, span, etc)
  127. , curpage: '#page_select' // css selector to get the current page. usually the same as numPages if it's a select element
  128. , numchaps: '#chapters' // css selector to get the number of chapters in manga
  129. , curchap: '#chapters' // css selector to get the number of the current chapter
  130. , nextchap: '#next_chap' // css selector to get the link to the next chapter
  131. , prevchap: '#prev_chap' // same as above except for previous
  132. , wait: 3000 // how many ms to wait before auto loading (to wait for elements to load), or a css selector to keep trying until it returns an elem
  133. , pages: function(next_url, current_page_number, callback, extract_function) {
  134. // gets called requesting a certain page number (current_page_number)
  135. // to continue loading execute callback with img to append as first parameter and next url as second parameter
  136. // only really needs to be used on sites that have really unusual ways of loading images or depend on javascript
  137. }
  138.  
  139. Any of the CSS selectors can be functions instead that return the desired value.
  140. }
  141. */
  142.  
  143. var implementations = [{
  144. name: 'batoto',
  145. match: "^https?://bato.to/reader.*",
  146. img: function(ctx) {
  147. var img = getEl('#comic_page', ctx);
  148. if(img) {
  149. return img.src;
  150. } else {
  151. var imgs = getEls('#content > div:nth-child(8) > img', ctx).map(function(page) {
  152. return page.src;
  153. });
  154. if(imgs.length > 0) {
  155. this.next = function() { return imgs[0]; };
  156. this.numpages = function() { return imgs.length; };
  157. this.pages = function(url, num, cb, ex) {
  158. cb(imgs[num - 1], num);
  159. };
  160. return imgs[0];
  161. }
  162. }
  163. },
  164. next: function() {
  165. if(!this._numpage) {
  166. this._numpage = extractInfo(this.curpage, {type: 'index'});
  167. this._id = location.hash.split('_')[0].slice(1);
  168. }
  169. return '/areader?id=' + this._id + '&p=' + (++this._numpage);
  170. },
  171. numpages: '#page_select',
  172. curpage: '#page_select',
  173. curchap: 'select[name=chapter_select]',
  174. numchaps: 'select[name=chapter_select]',
  175. nextchap: function(prev) {
  176. var link = extractInfo('select[name=chapter_select]', {type: 'value', val: prev ? 1 : -1});
  177. return link && link.replace(/https?/, document.location.href.split(':')[0]); // fix for batotos broken https pages
  178. },
  179. prevchap: function() {
  180. return this.nextchap(true);
  181. },
  182. wait: '#comic_page'
  183. }, {
  184. name: 'manga-panda',
  185. match: "^https?://www.mangapanda.com/.*/[0-9]*",
  186. img: '#img',
  187. next: '.next a',
  188. numpages: '#pageMenu',
  189. curpage: '#pageMenu',
  190. nextchap: 'td.c5 + td a',
  191. prevchap: 'table.c6 tr:last-child td:last-child a'
  192. }, {
  193. name: 'mangafox',
  194. match: "^https?://mangafox.me/manga/[^/]*/[^/]*/[^/]*",
  195. img: function(ctx) {
  196. var img = getEl('#image', ctx);
  197. return img.getAttribute('onerror').match(/'([^']+)'/)[1];
  198. },
  199. next: 'a.next_page',
  200. numpages: function() {
  201. return extractInfo('select.m') - 1;
  202. },
  203. curpage: 'select.m',
  204. nextchap: '#chnav p + p a',
  205. prevchap: '#chnav a'
  206. }, {
  207. name: 'manga-stream',
  208. match: "^https?://(readms|mangastream).com/(r|read)/[^/]*/[^/]*/[^/]*",
  209. img: '#manga-page',
  210. next: '.next a',
  211. numpages: function() {
  212. var lastPage = getEl('.subnav-wrapper .controls .btn-group:last-child ul li:last-child');
  213. return parseInt(lastPage.textContent.match(/[0-9]/g).join(''), 10);
  214. },
  215. nextchap: function(prev) {
  216. var found;
  217. var chapters = [].slice.call(document.querySelectorAll('.controls > div:first-child > .dropdown-menu > li a'));
  218. chapters.pop();
  219. for (var i = 0; i < chapters.length; i++) {
  220. if (window.location.href.indexOf(chapters[i].href) !== -1) {
  221. found = chapters[i + (prev ? 1 : -1)];
  222. if (found) return found.href;
  223. }
  224. }
  225. },
  226. prevchap: function() {
  227. return this.nextchap(true);
  228. }
  229. }, {
  230. name: 'manga-reader',
  231. match: "^https?://www.mangareader.net/.*/.*",
  232. img: '#img',
  233. next: '.next a',
  234. numpages: '#pageMenu',
  235. curpage: '#pageMenu',
  236. nextchap: '#chapterMenu',
  237. prevchap: '#chapterMenu',
  238. wait: '#chapterMenu option'
  239. }, {
  240. name: 'manga-town',
  241. match: "^https?://www.mangatown.com/manga/[^/]+/[^/]+",
  242. img: '#image',
  243. next: '#viewer a',
  244. numpages: '.page_select select',
  245. curpage: '.page_select select',
  246. nextchap: '#top_chapter_list',
  247. prevchap: '#top_chapter_list',
  248. wait: 1000
  249. }, {
  250. name: 'manga-cow, manga-doom, manga-indo, 3asq.info, moonbunnnycafe',
  251. match: "^https?://(mngcow|mangadoom|mangaindo|www\\.3asq|moonbunnycafe)\\.(co|id|info|com)/[^/]+/[0-9.]+",
  252. img: '.prw a > img',
  253. next: '.prw a',
  254. numpages: 'select.cbo_wpm_pag',
  255. curpage: 'select.cbo_wpm_pag',
  256. nextchap: function(prev) {
  257. var next = extractInfo('select.cbo_wpm_chp', {type: 'value', val: (prev ? 1 : -1)});
  258. if(next) return window.location.href.replace(/\/[0-9.]+\/?([0-9]+\/?)?[^/]*$/, '/' + next);
  259. },
  260. prevchap: function() {
  261. return this.nextchap(true);
  262. }
  263. }, {
  264. name: 'manga-here',
  265. match: "^https?://www.mangahere.co/manga/[^/]+/[^/]+",
  266. img: '#viewer img:last-child',
  267. next: '#viewer a',
  268. numpages: 'select.wid60',
  269. curpage: 'select.wid60',
  270. numchaps: '#top_chapter_list',
  271. curchap: '#top_chapter_list',
  272. nextchap: function(prev) {
  273. var chapter = W.chapter_list[W.current_chapter_index + (prev ? -1 : 1)];
  274. return chapter && chapter[1];
  275. },
  276. prevchap: function() {
  277. return this.nextchap(true);
  278. },
  279. wait: function() {
  280. return areDefined(W.current_chapter_index, W.chapter_list, getEl('#top_chapter_list'));
  281. }
  282. }, {
  283. name: 'manga-here mobile',
  284. match: "^https?://m.mangahere.co/manga/[^/]+/[^/]+",
  285. img: '#image',
  286. next: '#viewer a',
  287. numpages: '.mangaread-page',
  288. curpage: '.mangaread-page'
  289. }, {
  290. name: 'manga-park',
  291. match: "^https?://mangapark\\.me/manga/[^/]+/[^/]+/[^/]+",
  292. img: '.img-link > img',
  293. next: '.page > span:last-child > a',
  294. numpages: '#sel_page_1',
  295. curpage: '#sel_page_1',
  296. nextchap: function(prev) {
  297. var next = extractInfo('#sel_book_1', {type: 'value', val: (prev ? -1 : 1)});
  298. if(next) return window.location.href.replace(/\/s[0-9.]+\/c[0-9.]+(\/[^\/]+)?$/, next + '/1');
  299. },
  300. prevchap: function() {
  301. return this.nextchap(true);
  302. },
  303. wait: '#sel_book_1 option'
  304. }, {
  305. name: 'central-de-mangas',
  306. match: "^https?://(centraldemangas\\.org|[^\\.]+\\.com\\.br/leitura)/online/[^/]*/[0-9]*",
  307. img: '#manga-page',
  308. next: '#manga-page',
  309. numpages: '#manga_pages',
  310. curpage: '#manga_pages',
  311. nextchap: function(prev) {
  312. var next = extractInfo('#manga_caps', {type: 'value', val: (prev ? -1 : 1)});
  313. if(next) return window.location.href.replace(/[^\/]+$/, next);
  314. },
  315. prevchap: function() {
  316. return this.nextchap(true);
  317. },
  318. pages: function(url, num, cb, ex) {
  319. url = url.slice(0, url.lastIndexOf('-') + 1) + ("0" + num).slice(-2) + url.slice(url.lastIndexOf('.'));
  320. cb(url, url);
  321. }
  322. }, {
  323. name: 'manga-joy',
  324. match: "^https?://manga-joy.com/[^/]*/[0-9]*",
  325. img: '.prw img',
  326. next: '.nxt',
  327. numpages: '.wpm_nav_rdr li:nth-child(3) > select',
  328. curpage: '.wpm_nav_rdr li:nth-child(3) > select',
  329. nextchap: function(prev) {
  330. var next = extractInfo('.wpm_nav_rdr li:nth-child(2) > select', {type: 'value', val: prev ? 1 : -1});
  331. if(next) return window.location.href.replace(/\/[0-9.]+\/?([0-9]+(\/.*)?)?$/, '/' + next);
  332. },
  333. prevchap: function() {
  334. return this.nextchap(true);
  335. }
  336. }, {
  337. name: 'dm5',
  338. match: "^https?://[^\\.]*\\.dm5\\.com/m[0-9]*",
  339. img: '#cp_image',
  340. next: '#cp_image',
  341. numpages: function () {
  342. return getEls('a', getEl('.pageBar')).length;
  343. },
  344. curpage: function() {
  345. return parseInt(getEl('.pageBar .active').dataset.pgt);
  346. },
  347. pages: function(url, num, cb, ex) {
  348. var cid = window.location.href.match(/m[0-9]*/g)[2].slice(1),
  349. xhr = new XMLHttpRequest();
  350. xhr.open('get', 'chapterfun.ashx?cid=' + cid + '&page=' + num);
  351. xhr.onload = function() {
  352. var images = eval(xhr.responseText);
  353. cb(images[0], images[0]);
  354. };
  355. xhr.send();
  356. },
  357. nextchap: 'a.logo_2',
  358. prevchap: 'a.logo_1',
  359. wait: '#cp_image'
  360. }, {
  361. name: 'senmanga',
  362. match: "^https?://[^\\.]+\\.senmanga\\.com/[^/]*/.+",
  363. img: '#picture',
  364. next: '#reader > a',
  365. numpages: 'select[name=page]',
  366. curpage: 'select[name=page]',
  367. numchaps: 'select[name=chapter]',
  368. curchap: 'select[name=chapter]',
  369. nextchap: function(prev) {
  370. var next = extractInfo('select[name=chapter]', {type: 'value', val: (prev ? 1 : -1)});
  371. if(next) {
  372. var manga = window.location.pathname.slice(1).split('/')[0];
  373. return window.location.origin + '/' + manga + '/' + next + '/1';
  374. }
  375. },
  376. prevchap: function() {
  377. return this.nextchap(true);
  378. }
  379. }, {
  380. name: 'japscan',
  381. match: "^https?://www\\.japscan\\.com/lecture-en-ligne/[^/]*/[0-9]*",
  382. img: '#imgscan',
  383. next: '#next_link',
  384. numpages: '#pages',
  385. curpage: '#pages',
  386. nextchap: '#next_chapter',
  387. prevchap: '#back_chapter'
  388. }, { // pecintakomik
  389. match: "^https?://www\\.pecintakomik\\.com/manga/[^/]*/[^/]*",
  390. img: '.picture',
  391. next: '.pager a:nth-child(3)',
  392. numpages: 'select[name=page]',
  393. curpage: 'select[name=page]',
  394. nextchap: function(prev) {
  395. var next = extractInfo('select[name=chapter]', {type: 'value', val: (prev ? 1 : -1)});
  396. if(next) return window.location.href.replace(/\/([^\/]+)\/[0-9]+\/?$/, '/$1/' + next);
  397. },
  398. prevchap: function() {
  399. return this.nextchap(true);
  400. }
  401. }, {
  402. name: 'manga-kaka',
  403. match: "^https?://www\\.(mangahen|mangamap)\\.com/[^/]+/[0-9]+",
  404. img: 'img.manga-page',
  405. next: '.nav_pag > li:nth-child(1) > a',
  406. numpages: 'select.cbo_wpm_pag',
  407. curpage: 'select.cbo_wpm_pag',
  408. nextchap: function(prev) {
  409. var chapter = extractInfo('select.cbo_wpm_chp', { type: 'value', val: (prev ? 1 : -1) });
  410. if(chapter) return window.location.href.replace(/\/[0-9\.]+\/?([0-9]+\/?)?$/, '/' + chapter);
  411. },
  412. prevchap: function() {
  413. return this.nextchap(true);
  414. }
  415. }, {
  416. name: 'manga-wall',
  417. _page: null,
  418. match: "^https?://mangawall\\.com/manga/[^/]*/[0-9]*",
  419. img: 'img.scan',
  420. next: function() {
  421. if(this._page === null) this._page = W.page;
  422. return W.series_url + '/' + W.chapter + '/' + (this._page += 1);
  423. },
  424. numpages: '.pageselect',
  425. curpage: '.pageselect',
  426. nextchap: function(prev) {
  427. return W.series_url + '/' + (parseInt(W.chapter.slice(1)) + (prev ? -1 : 1)) + '/1';
  428. },
  429. prevchap: function() {
  430. return this.nextchap(true);
  431. }
  432. }, {
  433. name: 'anime-a',
  434. _page: null,
  435. match: "^https?://manga\\.animea.net/.+chapter-[0-9]+(-page-[0-9]+)?.html",
  436. img: '#scanmr',
  437. next: function() {
  438. if(this._page === null) this._page = W.page;
  439. return W.series_url + W.chapter + '-page-' + (this._page += 1) + '.html';
  440. },
  441. numpages: '.pageselect',
  442. curpage: '.pageselect',
  443. nextchap: function(prev) {
  444. return W.series_url + 'chapter-' + (parseInt(W.chapter.match(/[0-9]+/)[0]) + (prev ? -1 : 1)) + '-page-1.html';
  445. },
  446. prevchap: function() {
  447. return this.nextchap(true);
  448. }
  449. }, {
  450. name: 'kiss-manga',
  451. match: "^https?://kissmanga\\.com/Manga/[^/]+/.+",
  452. img: '#divImage img',
  453. next: '#divImage img',
  454. numpages: function() {
  455. return W.lstImages.length;
  456. },
  457. curpage: function() {
  458. if(getEls('#divImage img').length > 1) {
  459. return 1;
  460. } else {
  461. return W.currImage + 1;
  462. }
  463. },
  464. nextchap: '#selectChapter, .selectChapter',
  465. prevchap: '#selectChapter, .selectChapter',
  466. pages: function(url, num, cb, ex) {
  467. cb(W.lstImages[num - 1], num);
  468. }
  469. }, {
  470. name: 'the-spectrum-scans',
  471. match: "^https?://view\\.thespectrum\\.net/series/[^\\.]+\\.html",
  472. img: '#mainimage',
  473. next: function() {
  474. if (++this._page < this._pages.length) {
  475. return this._pages[this._page];
  476. }
  477. },
  478. numpages: '.selectpage',
  479. curpage: '.selectpage',
  480. nextchap: function(prev) {
  481. var ps = document.pageSelector1;
  482. var chnum = ps.ch.selectedIndex + (prev ? -1 : 1);
  483. if (chnum < ps.ch.length && chnum > -1) {
  484. return ps.action.split('?')[0] + '?ch=' + ps.ch[chnum].value + '&page=1';
  485. } else {
  486. return false;
  487. }
  488. },
  489. prevchap: function() {
  490. return this.nextchap(true);
  491. },
  492. wait: function() {
  493. var ps = document.pageSelector1;
  494. this._pages = [];
  495. var base = ps.action.split('?')[0];
  496. for (var i = 0; i < ps.page.length; i++) {
  497. this._pages.push(base + '?ch=' + ps.ch.value + '&page=' + ps.page[i].value);
  498. }
  499. this._page = ps.page[ps.page.selectedIndex].value - 1;
  500. return true;
  501. }
  502. }, {
  503. name: 'manhua-dmzj',
  504. match: "^https?://manhua.dmzj.com/[^/]*/[0-9]+(-[0-9]+)?\\.shtml",
  505. img: '#center_box > img',
  506. next: '#center_box > img',
  507. numpages: function() {
  508. return W.arr_pages.length;
  509. },
  510. curpage: function() {
  511. var match = location.href.match(/page=([0-9]+)/);
  512. return match ? parseInt(match[1]) : 1;
  513. },
  514. nextchap: '#next_chapter',
  515. prevchap: '#prev_chapter',
  516. pages: function(url, num, cb, ex) {
  517. cb(W.img_prefix + W.arr_pages[num - 1], num);
  518. },
  519. wait: '#center_box > img'
  520. }, {
  521. name: 'hqbr',
  522. match: "^https?://hqbr.com.br/hqs/[^/]+/capitulo/[0-9]+/leitor/0",
  523. img: '#hq-page',
  524. next: '#hq-page',
  525. numpages: function() {
  526. return W.pages.length;
  527. },
  528. curpage: function() {
  529. return W.paginaAtual + 1;
  530. },
  531. nextchap: function(prev) {
  532. var chapters = getEls('#chapter-dropdown a'),
  533. current = parseInt(W.capituloIndex),
  534. chapter = chapters[current + (prev ? -1 : 1)];
  535. return chapter && chapter.href;
  536. },
  537. prevchap: function() {
  538. return this.nextchap(true);
  539. },
  540. pages: function(url, num, cb, ex) {
  541. cb(W.pages[num - 1], num);
  542. }
  543. }, {
  544. name: 'dmzj',
  545. match: "^https?://www.dmzj.com/view/[^/]+/.+\\.html",
  546. img: '.comic_wraCon > img',
  547. next: '.comic_wraCon > img',
  548. numpages: function() {
  549. return parseInt(W.pic_total);
  550. },
  551. curpage: function() {
  552. var match = location.href.match(/page=([0-9])/);
  553. return match ? parseInt(match[1]) : 1;
  554. },
  555. nextchap: '.next > a',
  556. prevchap: '.pre > a',
  557. pages: function(url, num, cb, ex) {
  558. cb(W.img_prefix + W.picArry[num - 1], num);
  559. },
  560. wait: '.comic_wraCon > img'
  561. }, {
  562. name: 'mangago',
  563. match: "^https?://www.mangago.me/read-manga/[^/]+/[^/]+/[^/]+",
  564. img: '#page1',
  565. next: '#pic_container',
  566. numpages: '#dropdown-menu-page',
  567. curpage: function() {
  568. return parseInt(getEls('#page-mainer a.btn.dropdown-toggle')[1].textContent.match(/[0-9]+/)[0]);
  569. },
  570. nextchap: function(prev) {
  571. var chapters = getEls('ul.dropdown-menu.chapter a'),
  572. curName = getEls('#page-mainer a.btn.dropdown-toggle')[0].textContent,
  573. curIdx;
  574. chapters.some(function(chap, idx) {
  575. if(chap.textContent.indexOf(curName) === 0) {
  576. curIdx = idx;
  577. return true;
  578. }
  579. });
  580. var chapter = chapters[curIdx + (prev ? 1 : -1)];
  581. return chapter && chapter.href;
  582. },
  583. prevchap: function() {
  584. return this.nextchap(true);
  585. }
  586. }, {
  587. name: 'mangalator',
  588. match: "^https?://mangalator.ch/show.php\\?gallery=[0-9]+",
  589. img: '.image img',
  590. next: '#next',
  591. numpages: 'select[name=image]',
  592. curpage: 'select[name=image]',
  593. nextchap: function(prev) {
  594. var next = extractInfo('select[name=gallery]', {type: 'value', val: (prev ? 1 : -1)});
  595. if(next) return location.href.replace(/\?gallery=[0-9]+/, '?gallery=' + next);
  596. },
  597. prevchap: function() {
  598. return this.nextchap(true);
  599. }
  600. }, {
  601. name: 'eatmanga',
  602. match: "^https?://eatmanga.com/Manga-Scan/[^/]+/.+",
  603. img: '#eatmanga_image, #eatmanga_image_big',
  604. next: '#page_next',
  605. numpages: '#pages',
  606. curpage: '#pages',
  607. nextchap: '#bottom_chapter_list',
  608. prevchap: '#bottom_chapter_list',
  609. invchap: true
  610. }, {
  611. name: 'manga-cat',
  612. match: "^https?://www.mangacat.me/[^/]+/[^/]+/[^\\.]+.html",
  613. img: '.img',
  614. next: '.img-link',
  615. numpages: '#page',
  616. curpage: '#page',
  617. nextchap: '#chapter',
  618. prevchap: '#chapter',
  619. invchap: true,
  620. wait: '#chapter option'
  621. }, {
  622. name: 'readmanga.today',
  623. match: "^https?://www\\.readmanga\\.today/[^/]+/.+",
  624. img: '.page_chapter img',
  625. next: '.list-switcher-2 > li:nth-child(3) > a, .list-switcher-2 > li:nth-child(2) > a',
  626. numpages: '.list-switcher-2 select[name=category_type]',
  627. curpage: '.list-switcher-2 select[name=category_type]',
  628. nextchap: '.jump-menu[name=chapter_list]',
  629. prevchap: '.jump-menu[name=chapter_list]',
  630. invchap: true
  631. }, {
  632. name: 'foolslide',
  633. match: "^https?://(" + [
  634. "manga.redhawkscans.com/reader/read/.+",
  635. "reader.s2smanga.com/read/.+",
  636. "casanovascans.com/read/.+",
  637. "reader.vortex-scans.com/read/.+",
  638. "reader.roseliascans.com/read/.+",
  639. "mangatopia.net/slide/read/.+",
  640. "www.twistedhelscans.com/read/.+",
  641. "reader.sensescans.com/reader/read/.+",
  642. "reader.kireicake.com/read/.+",
  643. "substitutescans.com/reader/read/.+",
  644. "mangaichiscans.mokkori.fr/fs/read/.+",
  645. "reader.shoujosense.com/read/.+",
  646. "www.friendshipscans.com/slide/read/.+",
  647. "manga.famatg.com/read/.+",
  648. "www.demonicscans.com/FoOlSlide/read/.+",
  649. "necron99scans.com/reader/read/.+",
  650. "www.demonicscans.com/FoOlSlide/read/.+",
  651. "reader.psscans.info/read/.+",
  652. "otscans.com/foolslide/read/.+",
  653. "necron99scans.com/reader/read/.+",
  654. "manga.inpowerz.com/read/.+",
  655. "reader.evilflowers.com/read/.+",
  656. "reader.cafeconirst.com/read/.+",
  657. "kobato.hologfx.com/reader/read/.+",
  658. "jaiminisbox.com/reader/read/.+",
  659. "abandonedkittenscans.mokkori.fr/reader/read/.+",
  660. "reader.sensescans.com/read/.+",
  661. "gomanga.co/reader/read/.+"
  662. ].join('|') + ")",
  663. img: function() {
  664. return W.pages[W.current_page].url;
  665. },
  666. next: function() {
  667. return 'N/A';
  668. },
  669. numpages: function() {
  670. return W.pages.length;
  671. },
  672. curpage: function() {
  673. return W.current_page + 1;
  674. },
  675. nextchap: function(prev) {
  676. var desired;
  677. var dropdown = getEls('ul.dropdown')[1] || getEls('ul.uk-nav')[1];
  678. if(!dropdown) return;
  679. getEls('a', dropdown).forEach(function(chap, idx, arr) {
  680. if(location.href.indexOf(chap.href) === 0) desired = arr[idx + (prev ? 1 : -1)];
  681. });
  682. return desired && desired.href;
  683. },
  684. prevchap: function() {
  685. return this.nextchap(true);
  686. },
  687. pages: function(url, num, cb, ex) {
  688. cb(W.pages[num - 1].url, num);
  689. },
  690. wait: function() {
  691. if(W.location.href.indexOf('gomanga.co') !== -1) {
  692. var match = document.body.innerHTML.match(/(\w+)\[id\]\.url/);
  693. W.pages = match && match[1] && W[match[1]];
  694. }
  695. return W.pages;
  696. }
  697. }, {
  698. name: 'mangatraders',
  699. match: "^https?://mangatraders\\.org/read-online/[^/]+/.+",
  700. img: function(ctx) {
  701. var imgs = getEls('img', ctx);
  702. var found;
  703. imgs.some(function(img) {
  704. if(img.src.indexOf('http://2.bp.blogspot') > -1) {
  705. found = img.src;
  706. return true;
  707. }
  708. });
  709. return found;
  710. },
  711. next: 'body > div.container.mainPageContainer > ol > li:nth-child(4) > a',
  712. numpages: '#changePageSelect',
  713. curpage: '#changePageSelect',
  714. nextchap: function(prev) {
  715. var next = extractInfo('#changeChapterSelect', {type:'value', val: (prev ? -1 : 1)});
  716. if(next) {
  717. var chapter = next.split(';')[0];
  718. return location.href.replace(/chapter-[0-9]+/, 'chapter-' + chapter).replace(/page-[0-9]+/, 'page-1');
  719. }
  720. },
  721. prevchap: function() {
  722. return this.nextchap(true);
  723. }
  724. }, {
  725. name: 'mangainn',
  726. match: "^https?://www.mangainn.net/manga/chapter/.+",
  727. img: '#imgPage',
  728. next: function() {
  729. if(!this._count) this._count = extractInfo(this.curpage, {type: 'value'});
  730. var url = location.href;
  731. if(!/page_[0-9]+/.test(url)) url += '/page_1';
  732. return url.replace(/page_[0-9]+/, 'page_' + (++this._count));
  733. },
  734. numpages: '#cmbpages',
  735. curpage: '#cmbpages',
  736. nextchap: function(prev) {
  737. var next = extractInfo('#chapters', {type:'value', val: (prev ? -1 : 1)});
  738. if(next) return location.href.replace(/\/chapter\/.+$/, '/chapter/' + next + '/page_1');
  739. },
  740. prevchap: function() {
  741. return this.nextchap(true);
  742. }
  743. }, {
  744. name: 'kukudm',
  745. match: "^https?://(www|comic|comic2|comic3).kukudm.com/comiclist/[0-9]+/[0-9]+/[0-9]+.htm",
  746. img: function(ctx) {
  747. var script = getEl('td > script[language=javascript]', ctx);
  748. if(script) {
  749. return 'http://n.kukudm.com/' + script.textContent.match(/\+"([^']+)/)[1];
  750. }
  751. },
  752. next: function(ctx) {
  753. var links = getEls('td > a', ctx);
  754. return links[links.length - 1].getAttribute('href');
  755. },
  756. numpages: function(cur) {
  757. return parseInt(document.body.textContent.match(/共([0-9]+)页/)[1]);
  758. },
  759. curpage: function() {
  760. return parseInt(document.body.textContent.match(/第([0-9]+)页/)[1]);
  761. },
  762. beforexhr: reuse.encodeChinese
  763. }, {
  764. name: 'mangachapter',
  765. match: "^https?://www\\.mangachapter\\.me/[^/]+/[^/]+/[^/]+.html",
  766. img: '#mangaImg, #viewer > table > tbody > tr > td:nth-child(1) > a:nth-child(2) > img',
  767. next: '.page-select + a.button-page',
  768. numpages: '.page-select select',
  769. curpage: '.page-select select',
  770. invchap: true,
  771. nextchap: '#top_chapter_list',
  772. prevchap: '#top_chapter_list',
  773. wait: '#top_chapter_list'
  774. }, {
  775. name: 'kawaii',
  776. match: "^https://kawaii.ca/reader/.+",
  777. img: '.picture',
  778. next: 'select[name=page] + a',
  779. numpages: 'select[name=page]',
  780. curpage: 'select[name=page]',
  781. nextchap: function(prev) {
  782. var next = extractInfo('select[name=chapter]', {type:'value', val: (prev ? -1 : 1)});
  783. if(next) return location.href.replace(/\/reader\/([^/]+)(\/.+)?$/, '/reader/$1/' + next);
  784. },
  785. prevchap: function() {
  786. return this.nextchap(true);
  787. }
  788. }, {
  789. name: 'lonemanga',
  790. match: "^https?://lonemanga.com/manga/[^/]+/[^/]+",
  791. img: '#imageWrapper img',
  792. next: '#imageWrapper a',
  793. numpages: '.viewerPage',
  794. curpage: '.viewerPage',
  795. nextchap: function(prev) {
  796. var next = extractInfo('.viewerChapter', {type:'value', val: (prev ? 1 : -1)});
  797. if(next) return location.href.replace(/\/manga\/([^/]+)\/.+$/, '/manga/$1/' + next);
  798. },
  799. prevchap: function() {
  800. return this.nextchap(true);
  801. }
  802. }, {
  803. name: 'madokami',
  804. match: "^https?://manga\\.madokami\\.al/reader/.+",
  805. img: 'img',
  806. next: 'img',
  807. curpage: function() {
  808. return parseInt(query().index) + 1;
  809. },
  810. numpages: function() {
  811. if(!this._pages) {
  812. this._pages = JSON.parse(getEl('#reader').dataset.files);
  813. }
  814. return this._pages.length;
  815. },
  816. pages: function(url, num, cb, ex) {
  817. url = url.replace(/file=.+$/, 'file=' + this._pages[num - 1]);
  818. cb(url, url);
  819. },
  820. wait: '#reader'
  821. }, {
  822. name: 'egscans',
  823. match: '^https?://read.egscans.com/.+',
  824. img: '#image_frame img',
  825. next: '#image_frame img',
  826. curpage: 'select[name=page]',
  827. numpages: 'select[name=page]',
  828. nextchap: function(prev) {
  829. var data = getEl(this.curchap).getAttribute('onchange').match(/'[^']+'/g);
  830. var next = extractInfo(this.curchap, { type: 'value', val: (prev ? -1 : 1) });
  831. if(next) return location.origin + '/' + data[0].slice(1, -1) + '/' + next;
  832. },
  833. prevchap: function() {
  834. return this.nextchap(true);
  835. },
  836. curchap: 'select[name=chapter]',
  837. numchaps: 'select[name=chapter]',
  838. pages: function(url, num, cb, ex) {
  839. cb('/' + W.img_url[num], num);
  840. }
  841. }, {
  842. name: 'imperialscans',
  843. match: '^https?://imperialscans.com/read/.+',
  844. img: '#page-img',
  845. next: '#page-url',
  846. curpage: function() {
  847. return extractInfo('#page-select', { type: 'index', val: -1 });
  848. },
  849. numpages: function() {
  850. return extractInfo('#page-select') - 1;
  851. },
  852. curchap: function() {
  853. var options = getEls('#chapter-select option:not([disabled])');
  854. var chapter = 1;
  855. options.some(function(value, index) {
  856. if (location.pathname === value.value) {
  857. chapter = options.length - index;
  858. return true;
  859. }
  860. });
  861. return chapter;
  862. },
  863. numchaps: function() {
  864. return extractInfo('#chapter-select');
  865. },
  866. nextchap: '#page-control > li:nth-child(5) > a',
  867. prevchap: '#page-control > li:nth-child(1) > a'
  868. }, {
  869. name: 'chuixue',
  870. match: "^https?://www.chuixue.com/manhua/[0-9]+/[0-9]+.html",
  871. img: '#qTcms_pic',
  872. next: '#qTcms_pic',
  873. curpage: '#qTcms_select_i',
  874. numpages: '#qTcms_select_i',
  875. pages: function(url, num, cb, ex) {
  876. if(!this._pages) {
  877. this._pages = W.qTcms_S_m_murl.split('$qingtiandy$');
  878. }
  879. cb(this._pages[num - 1], num);
  880. },
  881. nextchap: function() {
  882. return W.qTcms_Pic_nextArr;
  883. },
  884. wait: '#qTcms_pic'
  885. }, {
  886. name: 'sh-arab',
  887. match: '^https?://www.sh-arab.com/manga/.+',
  888. img: 'img.picture',
  889. next: '#omv td > a',
  890. curpage: 'select[name=page]',
  891. numpages: 'select[name=page]',
  892. curchap: 'select[name=chapter]',
  893. numchaps: 'select[name=chapter]',
  894. nextchap: function(prev) {
  895. var next = extractInfo('select[name=chapter]', {type:'value', val: (prev ? -1 : 1)});
  896. if (next) return location.href.replace(/[^\/]+$/, next);
  897. },
  898. prevchap: function() {
  899. return this.nextchap(true);
  900. }
  901. }, {
  902. name: 'br.mangahost.com',
  903. match: "^http(s)?://br.mangahost.com/manga/[^/]+/.+",
  904. img: 'img.open',
  905. next: '.image-content > a',
  906. curpage: '.viewerPage',
  907. numpages: '.viewerPage'
  908. }, {
  909. name: 'spinybackmanga',
  910. match: '^https?://spinybackmanga.com/\\?manga=[^&]+&chapter=.+',
  911. img: '#thePicLink img',
  912. next: '#thePicLink img',
  913. curpage: function() {
  914. return W.current;
  915. },
  916. numpages: function() {
  917. return getEl('#loadingbar tr').children.length;
  918. },
  919. curchap: function() {
  920. return parseInt(getEls('.selector')[1].firstChild.textContent.match(/[0-9]+/)[0]);
  921. },
  922. numchaps: function() {
  923. return getEls('.selector .options')[1].children.length;
  924. },
  925. nextchap: function(prev) {
  926. var nextChap = document.scripts[2].textContent.match(/location.href = "([^"]+)"/)[1];
  927. if(prev) {
  928. [].some.call(getEls('.selector .options')[1].children, function(child, index, children) {
  929. if(child.href === nextChap) {
  930. nextChap = children[index - 2] && children[index - 2].href;
  931. return true;
  932. }
  933. });
  934. }
  935. return nextChap;
  936. },
  937. prevchap: function() {
  938. return this.nextchap(true);
  939. },
  940. pages: function(url, num, cb, ex) {
  941. cb(W.imageArray[num - 1], num);
  942. }
  943. }, {
  944. name: 'manga.ae',
  945. match: "https?://www.manga.ae/[^/]+/[^/]+/",
  946. img: '#showchaptercontainer img',
  947. next: '#showchaptercontainer a',
  948. curpage: 'a.chpage',
  949. nextchap: '.chapter:last-child',
  950. prevchap: '.chapter:first-child'
  951. }, {
  952. name: 'mangaforall',
  953. match: "https?://mangaforall.com/manga/[^/]+/[^/]+/",
  954. img: '#page > img',
  955. next: '#page > img',
  956. numpages: '#chapter > div:nth-child(1) > div > div.uk-width-large-1-3.uk-width-medium-1-3.uk-width-small-1-1.uk-text-left.uk-text-center-small > div > div > div > ul',
  957. curpage: '#chapter > div:nth-child(1) > div > div.uk-width-large-1-3.uk-width-medium-1-3.uk-width-small-1-1.uk-text-left.uk-text-center-small > div > a.uk-button.uk-button-primary.number.uk-button-danger',
  958. nextchap: '#chapter > div:nth-child(5) > div.uk-grid.uk-grid-collapse.uk-margin-top > div.uk-width-large-1-3.uk-width-medium-1-3.uk-width-small-1-1.uk-text-left.uk-text-center-small > a',
  959. prevchap: '#chapter > div:nth-child(5) > div.uk-grid.uk-grid-collapse.uk-margin-top > div.uk-width-large-1-3.uk-width-medium-1-3.uk-width-small-1-1.uk-text-right.uk-text-center-small > a',
  960. pages: function(url, num, cb, ex) {
  961. cb(W.pages[num - 1].url, num);
  962. }
  963. }, {
  964. name: 'hellocomic',
  965. match: "https?://hellocomic.com/[^/]+/[^/]+/p[0-9]+",
  966. img: '.coverIssue img',
  967. next: '.coverIssue a',
  968. numpages: '#e1',
  969. curpage: '#e1',
  970. nextchap: '#e2',
  971. prevchap: '#e2',
  972. curchap: '#e2',
  973. numchaps: '#e2'
  974. }, {
  975. name: 'read-comic-online',
  976. match: "^https?://readcomiconline\\.to/Comic/[^/]+/.+",
  977. img: '#divImage img',
  978. next: '#divImage img',
  979. numpages: function() {
  980. return W.lstImages.length;
  981. },
  982. curpage: function() {
  983. return getEls('#divImage img').length > 1 ? 1 : W.currImage + 1;
  984. },
  985. nextchap: '#selectEpisode, .selectEpisode',
  986. prevchap: '#selectEpisode, .selectEpisode',
  987. pages: function(url, num, cb, ex) {
  988. cb(W.lstImages[num - 1], num);
  989. }
  990. }, {
  991. name: 'mangaeden',
  992. match: "^https?://(www\\.)?mangaeden\\.com/(en|it)/(en|it)-manga/.+",
  993. img: '#mainImg',
  994. next: '#nextA',
  995. numpages: '#pageSelect',
  996. curpage: '#pageSelect',
  997. numchaps: '#combobox',
  998. curchap: '#combobox',
  999. invchap: true,
  1000. nextchap: function (prev) {
  1001. var cbox = getEl('#combobox');
  1002. var opt = cbox[prev ? cbox.selectedIndex + 1 : cbox.selectedIndex - 1];
  1003. var span = getEl('span.hideM0 a');
  1004. return opt && span && span.href + parseInt(opt.value) + '/1/';
  1005. },
  1006. prevchap: function () {
  1007. return this.nextchap(true);
  1008. }
  1009. }, {
  1010. name: 'comicastle',
  1011. match: "^https?://comicastle\\.org/read-.+",
  1012. img: '.chapter-img',
  1013. next: '.chapter-content > select + a.label',
  1014. numpages: '.chapter-content > select',
  1015. curpage: '.chapter-content > select',
  1016. numchaps: '.form-control',
  1017. curchap: '.form-control',
  1018. nextchap: '.form-control',
  1019. prevchap: '.form-control',
  1020. invchap: true
  1021. }, {
  1022. name: 'mymh8',
  1023. match: "^https?://(www\\.)?mymh8\\.com/chapter/.+",
  1024. img: '#viewimg',
  1025. next: reuse.na,
  1026. numpages: function() {
  1027. return W.maxpages;
  1028. },
  1029. curpage: '#J_showpage > span',
  1030. nextchap: function(prev) {
  1031. var button = prev ? getEl('div.m3p > input:first-of-type') : getEl('div.m3p > input:last-of-type');
  1032. return button && button.attributes.onclick.value.match(/\.href='([^']+)'/)[1];
  1033. },
  1034. prevchap: function() {
  1035. return this.nextchap(true);
  1036. },
  1037. pages: function(url, num, cb, ex) {
  1038. cb(W.WebimgServerURL[0] + W.imageslist[num], num);
  1039. },
  1040. wait: function() {
  1041. return W.imageslist.length > 0;
  1042. }
  1043. }, {
  1044. name: 'unionmangas',
  1045. match: "https?://(www\\.)?unionmangas\\.net/leitor/.+",
  1046. img: '.slick-active img.real',
  1047. next: reuse.na,
  1048. numpages: '.selectPage',
  1049. curpage: '.selectPage',
  1050. numchaps: '#cap_manga1',
  1051. curchap: '#cap_manga1',
  1052. nextchap: '#cap_manga1',
  1053. prevchap: '#cap_manga1',
  1054. pages: function(url, num, cb, ex) {
  1055. cb(W.pages[num - 1], num);
  1056. },
  1057. wait: function() {
  1058. W.pages = getEls('img.real').map(function(el) {
  1059. return el.src || el.dataset.lazy;
  1060. });
  1061. return W.pages && W.pages.length > 0;
  1062. }
  1063. }, {
  1064. name: 'otakusmash',
  1065. match: "https?://www\\.otakusmash\\.com/(read-comics|read-manga)/.+",
  1066. img: 'img.picture',
  1067. next: 'select[name=page] + a',
  1068. curpage: 'select[name=page]',
  1069. numpages: 'select[name=page]',
  1070. nextchap: function(prev) {
  1071. var nextChap = extractInfo('select[name=chapter]', {type: 'value', val: prev ? 1 : -1});
  1072. return nextChap ? location.href.replace(/(read-(comics|manga)\/[^\/]+).*/, '$1/' + nextChap) : null;
  1073. },
  1074. prevchap: function() {
  1075. return this.nextchap(true);
  1076. },
  1077. numchaps: 'select[name=chapter]',
  1078. curchap: 'select[name=chapter]',
  1079. invchap: true
  1080. }];
  1081. // END OF IMPL
  1082.  
  1083. var log = function(msg, type) {
  1084. type = type || 'log';
  1085. if (type === 'exit') {
  1086. log('exit: ' + msg, 'error');
  1087. throw 'mloader error';
  1088. } else {
  1089. try {
  1090. console[type]('%c' + scriptName + ' ' + type + ':', 'font-weight:bold;color:green;', msg);
  1091. } catch(e) { }
  1092. }
  1093. };
  1094.  
  1095. var getEl = function(q, c) {
  1096. if (!q) return;
  1097. return (c || document).querySelector(q);
  1098. };
  1099.  
  1100. var getEls = function(q, c) {
  1101. return [].slice.call((c || document).querySelectorAll(q));
  1102. };
  1103.  
  1104. var ajax = function(obj) {
  1105. var xhr = new XMLHttpRequest();
  1106. xhr.open(obj.method || 'get', obj.url, obj.async || true);
  1107. xhr.onload = obj.onload;
  1108. xhr.onerror = obj.onerror;
  1109. xhr.responseType = obj.responseType || 'text';
  1110. if(obj.beforeSend) obj.beforeSend(xhr);
  1111. xhr.send(obj.data);
  1112. };
  1113.  
  1114. var storeGet = function(key) {
  1115. var res;
  1116. if (typeof GM_getValue === "undefined") {
  1117. res = localStorage.getItem(key);
  1118. } else {
  1119. res = GM_getValue(key);
  1120. }
  1121. try {
  1122. return JSON.parse(res);
  1123. } catch(e) {
  1124. return res;
  1125. }
  1126. };
  1127.  
  1128. var storeSet = function(key, value) {
  1129. value = JSON.stringify(value);
  1130. if (typeof GM_setValue === "undefined") {
  1131. return localStorage.setItem(key, value);
  1132. }
  1133. return GM_setValue(key, value);
  1134. };
  1135.  
  1136. var storeDel = function(key) {
  1137. if (typeof GM_deleteValue === "undefined") {
  1138. return localStorage.removeItem(key);
  1139. }
  1140. return GM_deleteValue(key);
  1141. };
  1142.  
  1143. var areDefined = function() {
  1144. return [].every.call(arguments, function(arg) {
  1145. return arg !== undefined && arg !== null;
  1146. });
  1147. };
  1148.  
  1149. var updateObj = function(orig, ext) {
  1150. var key;
  1151. for (key in ext) {
  1152. if (orig.hasOwnProperty(key) && ext.hasOwnProperty(key)) {
  1153. orig[key] = ext[key];
  1154. }
  1155. }
  1156. return orig;
  1157. };
  1158.  
  1159. var extractInfo = function(selector, mod, context) {
  1160. selector = this[selector] || selector;
  1161. if (typeof selector === 'function') {
  1162. return selector.call(this, context);
  1163. }
  1164. var elem = getEl(selector, context),
  1165. option;
  1166. mod = mod || {};
  1167. if (elem) {
  1168. switch (elem.nodeName.toLowerCase()) {
  1169. case 'img':
  1170. return (mod.altProp && elem.getAttribute(mod.altProp)) || elem.src || elem.getAttribute('src');
  1171. case 'a':
  1172. if(mod.type === 'index')
  1173. return parseInt(elem.textContent);
  1174. return elem.href || elem.getAttribute('href');
  1175. case 'ul':
  1176. return elem.children.length;
  1177. case 'select':
  1178. switch (mod.type) {
  1179. case 'index':
  1180. var idx = elem.options.selectedIndex + 1 + (mod.val || 0);
  1181. if(mod.invIdx) idx = elem.options.length - idx + 1;
  1182. return idx;
  1183. case 'value':
  1184. option = elem.options[elem.options.selectedIndex + (mod.val || 0)] || {};
  1185. return option.value;
  1186. default:
  1187. return elem.options.length;
  1188. }
  1189. break;
  1190. default:
  1191. switch (mod.type) {
  1192. case 'index':
  1193. return parseInt(elem.textContent);
  1194. default:
  1195. return elem.textContent;
  1196. }
  1197. }
  1198. }
  1199. return null;
  1200. };
  1201.  
  1202. var addStyle = function(id, replace) {
  1203. if(!this.MLStyles) this.MLStyles = {};
  1204. if(!this.MLStyles[id]) {
  1205. this.MLStyles[id] = document.createElement('style');
  1206. this.MLStyles[id].dataset.name = 'ml-style-' + id;
  1207. document.head.appendChild(this.MLStyles[id]);
  1208. }
  1209. var style = this.MLStyles[id];
  1210. var css = [].slice.call(arguments, 2).join('\n');
  1211. if(replace) {
  1212. style.textContent = css;
  1213. } else {
  1214. style.textContent += css;
  1215. }
  1216. };
  1217.  
  1218. var toStyleStr = function(obj, selector) {
  1219. var stack = [],
  1220. key;
  1221. for (key in obj) {
  1222. if (obj.hasOwnProperty(key)) {
  1223. stack.push(key + ':' + obj[key]);
  1224. }
  1225. }
  1226. if (selector) {
  1227. return selector + '{' + stack.join(';') + '}';
  1228. } else {
  1229. return stack.join(';');
  1230. }
  1231. };
  1232.  
  1233. var throttle = function(callback, limit) {
  1234. var wait = false;
  1235. return function() {
  1236. if (!wait) {
  1237. callback();
  1238. wait = true;
  1239. setTimeout(function() {
  1240. wait = false;
  1241. }, limit);
  1242. }
  1243. };
  1244. };
  1245.  
  1246. var query = function() {
  1247. var map = {};
  1248. location.search.slice(1).split('&').forEach(function(pair) {
  1249. pair = pair.split('=');
  1250. map[pair[0]] = pair[1];
  1251. });
  1252. return map;
  1253. };
  1254.  
  1255. var createButton = function(text, action, styleStr) {
  1256. var button = document.createElement('button');
  1257. button.textContent = text;
  1258. button.onclick = action;
  1259. button.setAttribute('style', styleStr || '');
  1260. return button;
  1261. };
  1262.  
  1263. var getViewer = function(prevChapter, nextChapter) {
  1264. var viewerCss = toStyleStr({
  1265. 'background-color': 'black !important',
  1266. 'font': '0.813em courier !important',
  1267. 'text-align': 'center',
  1268. }, 'body'),
  1269. imagesCss = toStyleStr({
  1270. 'margin-top': '10px',
  1271. 'margin-bottom': '10px'
  1272. }, '.ml-images'),
  1273. imageCss = toStyleStr({
  1274. 'max-width': '100%',
  1275. 'display': 'block',
  1276. 'margin': '3px auto'
  1277. }, '.ml-images img'),
  1278. counterCss = toStyleStr({
  1279. 'background-color': '#222',
  1280. 'color': 'white',
  1281. 'border-radius': '10px',
  1282. 'width': '30px',
  1283. 'margin-left': 'auto',
  1284. 'margin-right': 'auto',
  1285. 'margin-top': '-12px',
  1286. 'padding-left': '5px',
  1287. 'padding-right': '5px',
  1288. 'border': '1px solid white',
  1289. 'z-index': '100',
  1290. 'position': 'relative'
  1291. }, '.ml-counter'),
  1292. navCss = toStyleStr({
  1293. 'text-decoration': 'none',
  1294. 'color': 'white',
  1295. 'background-color': '#444',
  1296. 'padding': '3px 10px',
  1297. 'border-radius': '5px',
  1298. 'transition': '250ms'
  1299. }, '.ml-chap-nav a'),
  1300. navHoverCss = toStyleStr({
  1301. 'background-color': '#555'
  1302. }, '.ml-chap-nav a:hover'),
  1303. boxCss = toStyleStr({
  1304. 'position': 'fixed',
  1305. 'background-color': '#222',
  1306. 'color': 'white',
  1307. 'padding': '7px',
  1308. 'border-top-left-radius': '5px',
  1309. 'cursor': 'default'
  1310. }, '.ml-box'),
  1311. statsCss = toStyleStr({
  1312. 'bottom': '0',
  1313. 'right': '0',
  1314. 'opacity': '0.4',
  1315. 'transition': '250ms'
  1316. }, '.ml-stats'),
  1317. statsCollapseCss = toStyleStr({
  1318. 'color': 'orange',
  1319. 'cursor': 'pointer'
  1320. }, '.ml-stats-collapse'),
  1321. statsHoverCss = toStyleStr({
  1322. 'opacity': '1'
  1323. }, '.ml-stats:hover'),
  1324. floatingMsgCss = toStyleStr({
  1325. 'bottom': '30px',
  1326. 'right': '0',
  1327. 'border-bottom-left-radius': '5px',
  1328. 'text-align': 'left',
  1329. 'font': 'inherit',
  1330. 'max-width': '95%',
  1331. 'z-index': '101',
  1332. 'white-space': 'pre-wrap'
  1333. }, '.ml-floating-msg'),
  1334. floatingMsgAnchorCss = toStyleStr({
  1335. 'color': 'orange'
  1336. }, '.ml-floating-msg a'),
  1337. buttonCss = toStyleStr({
  1338. 'cursor': 'pointer'
  1339. }, '.ml-button'),
  1340. keySettingCss = toStyleStr({
  1341. 'width': '35px'
  1342. }, '.ml-setting-key input'),
  1343. autoloadSettingCss = toStyleStr({
  1344. 'vertical-align': 'middle'
  1345. }, '.ml-setting-autoload');
  1346. // clear all styles and scripts
  1347. var title = document.title;
  1348. document.head.innerHTML = '<meta name="viewport" content="width=device-width, initial-scale=1"><link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">';
  1349. document.title = title;
  1350. document.body.className = '';
  1351. document.body.style = '';
  1352. // navigation
  1353. var nav = '<div class="ml-chap-nav">' + (prevChapter ? '<a class="ml-chap-prev" href="' + prevChapter + '">Prev Chapter</a> ' : '') +
  1354. '<a class="ml-exit" href="' + location.href + '" data-exit="true">Exit</a> ' +
  1355. (nextChapter ? '<a class="ml-chap-next" href="' + nextChapter + '">Next Chapter</a>' : '') + '</div>';
  1356. // message area
  1357. var floatingMsg = '<pre class="ml-box ml-floating-msg"></pre>';
  1358. // stats
  1359. var stats = '<div class="ml-box ml-stats"><span title="hide stats" class="ml-stats-collapse">&gt;&gt;</span><span class="ml-stats-content"><span class="ml-stats-pages"></span> ' +
  1360. '<i class="fa fa-info ml-button ml-info-button" title="See userscript information and help"></i> ' +
  1361. '<i class="fa fa-bar-chart ml-button ml-more-stats-button" title="See page stats"></i> ' +
  1362. '<i class="fa fa-cog ml-button ml-settings-button" title="Adjust userscript settings"></i> ' +
  1363. '<i class="fa fa-refresh ml-button ml-manual-reload" title="Manually refresh next clicked image."></i></span></div>';
  1364. // combine ui elements
  1365. document.body.innerHTML = nav + '<div class="ml-images"></div>' + nav + floatingMsg + stats;
  1366. // add main styles
  1367. addStyle('main', true, viewerCss, imagesCss, imageCss, counterCss, navCss, navHoverCss, statsCss, statsCollapseCss, statsHoverCss, boxCss, floatingMsgCss, buttonCss, keySettingCss, autoloadSettingCss, floatingMsgAnchorCss);
  1368. // add user styles
  1369. var userCss = storeGet('ml-setting-css-profiles');
  1370. var curProf = storeGet('ml-setting-css-current') || '';
  1371. if(userCss && userCss.length > 0) userCss = userCss.filter(function(p) { return p.name === curProf; });
  1372. userCss = userCss && userCss.length > 0 ? userCss[0].css : (storeGet('ml-setting-css') || '');
  1373. addStyle('user', true, userCss);
  1374. // set up return UI object
  1375. var UI = {
  1376. images: getEl('.ml-images'),
  1377. statsContent: getEl('.ml-stats-content'),
  1378. statsPages: getEl('.ml-stats-pages'),
  1379. statsCollapse: getEl('.ml-stats-collapse'),
  1380. btnManualReload: getEl('.ml-manual-reload'),
  1381. btnInfo: getEl('.ml-info-button'),
  1382. btnMoreStats: getEl('.ml-more-stats-button'),
  1383. floatingMsg: getEl('.ml-floating-msg'),
  1384. btnNextChap: getEl('.ml-chap-next'),
  1385. btnPrevChap: getEl('.ml-chap-prev'),
  1386. btnExit: getEl('.ml-exit'),
  1387. btnSettings: getEl('.ml-settings-button'),
  1388. isTyping: false,
  1389. ignore: false,
  1390. moreStats: false,
  1391. currentProfile: storeGet('ml-setting-css-current') || ''
  1392. };
  1393. // message func
  1394. var messageId = null;
  1395. var showFloatingMsg = function(msg, timeout, html) {
  1396. clearTimeout(messageId);
  1397. log(msg);
  1398. if(html) {
  1399. UI.floatingMsg.innerHTML = msg;
  1400. } else {
  1401. UI.floatingMsg.textContent = msg;
  1402. }
  1403. if(!msg) UI.moreStats = false;
  1404. UI.floatingMsg.style.display = msg ? '' : 'none';
  1405. if(timeout) {
  1406. messageId = setTimeout(function() {
  1407. showFloatingMsg('');
  1408. }, timeout);
  1409. }
  1410. };
  1411. var isMessageFloating = function() {
  1412. return !!UI.floatingMsg.innerHTML;
  1413. };
  1414. // configure initial state
  1415. UI.floatingMsg.style.display = 'none';
  1416. // set up listeners
  1417. document.addEventListener('click', function(evt) {
  1418. if (evt.target.nodeName === 'A' && evt.button !== 2) {
  1419. var shouldReload = evt.target.href.indexOf('#') !== -1 && evt.target.href.split('#')[0] === document.location.href.split('#')[0] && evt.button === 0; // fix for batoto https weirdness
  1420. if(evt.target.className.indexOf('ml-chap') !== -1) {
  1421. log('next chapter will autoload');
  1422. storeSet('autoload', 'yes');
  1423. if(shouldReload) {
  1424. evt.preventDefault();
  1425. location.href = evt.target.href;
  1426. location.reload(true);
  1427. }
  1428. } else if(evt.target.className.indexOf('ml-exit') !== -1) {
  1429. log('exiting chapter, stop autoload');
  1430. storeSet('autoload', 'no');
  1431. if(shouldReload) {
  1432. evt.preventDefault();
  1433. location.reload(true);
  1434. }
  1435. }
  1436. }
  1437. });
  1438. UI.btnMoreStats.addEventListener('click', function(evt) {
  1439. if(isMessageFloating() && UI.lastFloat === evt.target) {
  1440. showFloatingMsg('');
  1441. } else {
  1442. UI.lastFloat = evt.target;
  1443. UI.moreStats = true;
  1444. showFloatingMsg([
  1445. '<strong>Stats:</strong>',
  1446. pageStats.loadLimit + ' pages parsed',
  1447. pageStats.numLoaded + ' images loaded',
  1448. (pageStats.loadLimit - pageStats.numLoaded) + ' images loading',
  1449. (pageStats.numPages || 'Unknown number of') + ' pages in chapter',
  1450. (pageStats.curChap !== null && pageStats.numChaps !== null ? ((pageStats.curChap - 1) + '/' + pageStats.numChaps + ' chapters read ' + (((pageStats.curChap - 1) / pageStats.numChaps * 100).toFixed(2) + '%') + ' of series') : ''),
  1451. ].join('<br>'), null, true);
  1452. }
  1453. });
  1454. UI.btnManualReload.addEventListener('click', function(evt) {
  1455. var imgClick = function(e) {
  1456. var target = e.target;
  1457. UI.images.removeEventListener('click', imgClick, false);
  1458. UI.images.style.cursor = '';
  1459. if(target.nodeName === 'IMG' && target.parentNode.className === 'ml-images') {
  1460. showFloatingMsg('');
  1461. if(!target.title) {
  1462. showFloatingMsg('Reloading "' + target.src + '"', 3000);
  1463. if(target.complete) target.onload = null;
  1464. target.src = target.src + (target.src.indexOf('?') !== -1 ? '&' : '?') + new Date().getTime();
  1465. }
  1466. } else {
  1467. showFloatingMsg('Cancelled manual reload...', 3000);
  1468. }
  1469. };
  1470. showFloatingMsg('Left click the image you would like to reload.\nClick on the page margin to cancel.');
  1471. UI.images.style.cursor = 'pointer';
  1472. UI.images.addEventListener('click', imgClick, false);
  1473. });
  1474. UI.statsCollapse.addEventListener('click', function(evt) {
  1475. var test = UI.statsCollapse.textContent === '>>';
  1476. storeSet('ml-stats-collapsed', test);
  1477. UI.statsContent.style.display = test ? 'none' : '';
  1478. UI.statsCollapse.textContent = test ? '<<' : '>>';
  1479. });
  1480. // restore collapse state
  1481. if(storeGet('ml-stats-collapsed')) UI.statsCollapse.click();
  1482. UI.floatingMsg.addEventListener('focus', function(evt) {
  1483. var target = evt.target;
  1484. if(target.dataset.ignore) UI.ignore = true;
  1485. if((target.nodeName === 'INPUT' && target.type === 'text') || target.nodeName === 'TEXTAREA') UI.isTyping = true;
  1486. }, true);
  1487. UI.floatingMsg.addEventListener('blur', function(evt) {
  1488. var target = evt.target;
  1489. if(target.dataset.ignore) UI.ignore = false;
  1490. if((target.nodeName === 'INPUT' && target.type === 'text') || target.nodeName === 'TEXTAREA') UI.isTyping = false;
  1491. }, true);
  1492. UI.btnInfo.addEventListener('click', function(evt) {
  1493. if(isMessageFloating() && UI.lastFloat === evt.target) {
  1494. showFloatingMsg('');
  1495. } else {
  1496. UI.lastFloat = evt.target;
  1497. showFloatingMsg([
  1498. '<strong>Information:</strong>',
  1499. '<strong>IMPORTANT:</strong> The script has been updated to exclude NSFW sites',
  1500. 'in order to gain access to that functionality you\'ll have to install the following addon script.',
  1501. '<a href="https://sleazyfork.org/en/scripts/12657-manga-loader-nsfw" target="_blank">https://sleazyfork.org/en/scripts/12657-manga-loader-nsfw</a>',
  1502. '',
  1503. 'New feature! You can now define custom CSS in the new settings panel (accessible through the gear icon at the bottom left).',
  1504. 'The CSS will be saved and reapplied each time the script loads. You can change the background color of the page,',
  1505. 'the width of the images and pretty much anything else.',
  1506. '',
  1507. 'CSS feature has now been enhanced to support multiple profiles you can switch between.',
  1508. '',
  1509. '<strong>Keybindings:</strong>',
  1510. 'Z - previous chapter',
  1511. 'X - exit',
  1512. 'C - next chapter',
  1513. 'W - scroll up',
  1514. 'S - scroll down',
  1515. 'Click the info button again to close this message.'
  1516. ].join('<br>'), null, true);
  1517. }
  1518. });
  1519. UI.btnSettings.addEventListener('click', function(evt) {
  1520. if(isMessageFloating() && UI.lastFloat === evt.target) {
  1521. showFloatingMsg('');
  1522. } else {
  1523. UI.lastFloat = evt.target;
  1524. // start grid and first column
  1525. var settings = '<table><tr><td>';
  1526. // Custom CSS
  1527. var cssProfiles = storeGet('ml-setting-css-profiles');
  1528. if(!cssProfiles || cssProfiles.length === 0) {
  1529. cssProfiles = [{name: 'Default', css: storeGet('ml-setting-css') || ''}];
  1530. storeSet('ml-setting-css-profiles', cssProfiles);
  1531. }
  1532. cssProfiles.push({ name: 'New Profile...', addNew: true });
  1533. var prof = cssProfiles.filter(function(p) { return p.name === UI.currentProfile; })[0] || cssProfiles[0];
  1534. settings += 'CSS (custom css for Manga Loader):<br>' +
  1535. '<select class="ml-setting-css-profile">' +
  1536. cssProfiles.map(function(profile) { return '<option ' + (profile.name === prof.name ? 'selected' : '') + '>' + profile.name + '</option>'; }).join('') +
  1537. '</select><button class="ml-setting-delete-profile">x</button><br>' +
  1538. '<textarea style="width: 300px; height: 300px;" type="text" class="ml-setting-css">' + prof.css + '</textarea><br><br>';
  1539. // start new column
  1540. settings += '</td><td>';
  1541. // Keybindings
  1542. var keyTableHtml = Object.keys(UI.keys).map(function(action) {
  1543. return '<tr><td>' + action + '</td><td><input data-ignore="true" data-key="' + action + '" type="text" value="' + UI.keys[action] + '"></td></tr>';
  1544. }).join('');
  1545. settings += 'Keybindings:<br><table class="ml-setting-key">' + keyTableHtml + '</table><br>';
  1546. // Autoload
  1547. settings += 'Auto-load: <input class="ml-setting-autoload" type="checkbox" ' + (storeGet('mAutoload') && 'checked' || '') + '><br><br>';
  1548. // Load all or just N pages
  1549. settings += "# of pages to load:<br>" +
  1550. 'Type "all" to load all<br>default is 10<br>' +
  1551. '<input class="ml-setting-loadnum" size="3" type="text" value="' + (storeGet('mLoadNum') || 10) + '" /><br><br>';
  1552. // close grid and column
  1553. settings += '</td></tr></table>';
  1554. // Save button
  1555. settings += '<button class="ml-setting-save">Save</button> <button class="ml-setting-close">Close</button> <span class="ml-setting-save-flash"></span>';
  1556. showFloatingMsg(settings, null, true);
  1557. // handle keybinding detection
  1558. getEl('.ml-setting-key').onkeydown = function(e) {
  1559. var target = e.target;
  1560. if(target.nodeName.toUpperCase() === 'INPUT') {
  1561. e.preventDefault();
  1562. e.stopPropagation();
  1563. target.value = e.keyCode || e.which;
  1564. }
  1565. };
  1566. // delete css profile
  1567. getEl('.ml-setting-delete-profile', UI.floatingMsg).onclick = function(e) {
  1568. if(['Default', 'New Profile...'].indexOf(prof.name) === -1) {
  1569. if(confirm('Are you sure you want to delete profile "' + prof.name + '"?')) {
  1570. var index = cssProfiles.indexOf(prof);
  1571. cssProfiles.splice(index, 1);
  1572. var sel = getEl('.ml-setting-css-profile');
  1573. sel.remove(index);
  1574. sel.selectedIndex = 0;
  1575. sel.onchange({target: sel});
  1576. }
  1577. } else {
  1578. alert('Cannot delete profile: "' + prof.name + '"');
  1579. }
  1580. };
  1581. // change selected css profile
  1582. getEl('.ml-setting-css-profile', UI.floatingMsg).onchange = function(e) {
  1583. var cssBox = getEl('.ml-setting-css');
  1584. prof.css = cssBox.value;
  1585. prof = cssProfiles[e.target.selectedIndex];
  1586. if(prof.addNew) {
  1587. // enter new name
  1588. var newName = '';
  1589. while(!newName || cssProfiles.filter(function(p) { return p.name === newName; }).length > 0) {
  1590. newName = prompt('Enter the name for the new profile (must be unique)');
  1591. if(!newName) {
  1592. e.target.selectedIndex = 0;
  1593. e.target.onchange({target: e.target});
  1594. return;
  1595. }
  1596. }
  1597. // add new profile to array
  1598. var last = cssProfiles.pop();
  1599. cssProfiles.push({name: newName, css: ''}, last);
  1600. prof = cssProfiles[cssProfiles.length - 2];
  1601. // add new profile to select box
  1602. var option = document.createElement('option');
  1603. option.text = newName;
  1604. e.target.add(option, e.target.options.length - 1);
  1605. e.target.selectedIndex = e.target.options.length - 2;
  1606. }
  1607. cssBox.value = prof.css;
  1608. UI.currentProfile = prof.name;
  1609. addStyle('user', true, prof.css);
  1610. };
  1611. // handle save button
  1612. getEl('.ml-setting-save', UI.floatingMsg).onclick = function() {
  1613. // persist css
  1614. var css = getEl('.ml-setting-css', UI.floatingMsg).value.trim();
  1615. prof.css = css;
  1616. addStyle('user', true, css);
  1617. var last = cssProfiles.pop();
  1618. storeSet('ml-setting-css-profiles', cssProfiles);
  1619. cssProfiles.push(last);
  1620. storeSet('ml-setting-css-current', UI.currentProfile);
  1621. // keybindings
  1622. getEls('.ml-setting-key input').forEach(function(input) {
  1623. UI.keys[input.dataset.key] = parseInt(input.value);
  1624. });
  1625. storeSet('ml-setting-key', UI.keys);
  1626. // autoload
  1627. storeSet('mAutoload', getEl('.ml-setting-autoload').checked);
  1628. // loadnum
  1629. var loadnum = getEl('.ml-setting-loadnum').value;
  1630. mLoadNum = getEl('.ml-setting-loadnum').value = loadnum.toLowerCase() === 'all' ? 'all' : (parseInt(loadnum) || 10);
  1631. storeSet('mLoadNum', mLoadNum);
  1632. // flash notify
  1633. var flash = getEl('.ml-setting-save-flash');
  1634. flash.textContent = 'Saved!';
  1635. setTimeout(function() { flash.textContent = ''; }, 1000);
  1636. };
  1637. // handle close button
  1638. getEl('.ml-setting-close', UI.floatingMsg).onclick = function() {
  1639. showFloatingMsg('');
  1640. };
  1641. }
  1642. });
  1643. // keybindings
  1644. UI.keys = {
  1645. PREV_CHAP: 90, EXIT: 88, NEXT_CHAP: 67,
  1646. SCROLL_UP: 87, SCROLL_DOWN: 83
  1647. };
  1648. UI.scrollAmt = 50;
  1649. // override the defaults with the user defined ones
  1650. updateObj(UI.keys, storeGet('ml-setting-key') || {});
  1651. UI._keys = {};
  1652. Object.keys(UI.keys).forEach(function(action) {
  1653. UI._keys[UI.keys[action]] = action;
  1654. });
  1655. window.addEventListener('keydown', function(evt) {
  1656. // ignore keybindings when text input is focused
  1657. if(UI.isTyping) {
  1658. if(!UI.ignore) evt.stopPropagation();
  1659. return;
  1660. }
  1661. // perform action
  1662. switch(evt.keyCode) {
  1663. case UI.keys.PREV_CHAP:
  1664. if(UI.btnPrevChap) {
  1665. UI.btnPrevChap.click();
  1666. }
  1667. break;
  1668. case UI.keys.EXIT:
  1669. UI.btnExit.click();
  1670. break;
  1671. case UI.keys.NEXT_CHAP:
  1672. if(UI.btnNextChap) {
  1673. UI.btnNextChap.click();
  1674. }
  1675. break;
  1676. case UI.keys.SCROLL_UP:
  1677. window.scrollBy(0, -UI.scrollAmt);
  1678. break;
  1679. case UI.keys.SCROLL_DOWN:
  1680. window.scrollBy(0, UI.scrollAmt);
  1681. break;
  1682. default:
  1683. evt.stopPropagation();
  1684. break;
  1685. }
  1686. }, true);
  1687. return UI;
  1688. };
  1689.  
  1690. var getCounter = function(imgNum) {
  1691. var counter = document.createElement('div');
  1692. counter.classList.add('ml-counter');
  1693. counter.textContent = imgNum;
  1694. return counter;
  1695. };
  1696.  
  1697. var addImage = function(src, loc, imgNum, callback) {
  1698. var image = new Image(),
  1699. counter = getCounter(imgNum);
  1700. image.onerror = function() {
  1701. log('failed to load ' + src);
  1702. image.onload = null;
  1703. image.style.backgroundColor = 'white';
  1704. image.style.cursor = 'pointer';
  1705. image.title = 'Reload "' + src + '"?';
  1706. image.src = IMAGES.refresh_large;
  1707. image.onclick = function() {
  1708. image.onload = callback;
  1709. image.title = '';
  1710. image.style.cursor = '';
  1711. image.src = src;
  1712. };
  1713. };
  1714. image.onload = callback;
  1715. image.src = src;
  1716. loc.appendChild(image);
  1717. loc.appendChild(counter);
  1718. };
  1719.  
  1720. var loadManga = function(imp) {
  1721. var ex = extractInfo.bind(imp),
  1722. imgUrl = ex('img', imp.imgmod),
  1723. nextUrl = ex('next'),
  1724. numPages = ex('numpages'),
  1725. curPage = ex('curpage', {
  1726. type: 'index'
  1727. }) || 1,
  1728. nextChapter = ex('nextchap', {
  1729. type: 'value',
  1730. val: (imp.invchap && -1) || 1
  1731. }),
  1732. prevChapter = ex('prevchap', {
  1733. type: 'value',
  1734. val: (imp.invchap && 1) || -1
  1735. }),
  1736. xhr = new XMLHttpRequest(),
  1737. d = document.implementation.createHTMLDocument(),
  1738. addAndLoad = function(img, next) {
  1739. if(!img) throw new Error('failed to retrieve img for page ' + curPage);
  1740. updateStats();
  1741. addImage(img, UI.images, curPage, function() {
  1742. pagesLoaded += 1;
  1743. updateStats();
  1744. });
  1745. if(!next && curPage < numPages) throw new Error('failed to retrieve next url for page ' + curPage);
  1746. loadNextPage(next);
  1747. },
  1748. updateStats = function() {
  1749. updateObj(pageStats, {
  1750. numLoaded: pagesLoaded,
  1751. loadLimit: curPage,
  1752. numPages: numPages
  1753. });
  1754. if(UI.moreStats) {
  1755. for(var i=2;i--;) UI.btnMoreStats.click();
  1756. }
  1757. UI.statsPages.textContent = ' ' + pagesLoaded + (numPages ? '/' + numPages : '') + ' loaded';
  1758. },
  1759. getPageInfo = function() {
  1760. var page = d.body;
  1761. d.body.innerHTML = xhr.response;
  1762. try {
  1763. // find image and link to next page
  1764. addAndLoad(ex('img', imp.imgmod, page), ex('next', null, page));
  1765. } catch (e) {
  1766. log(e);
  1767. log('error getting details from next page, assuming end of chapter.');
  1768. }
  1769. },
  1770. loadNextPage = function(url) {
  1771. if (mLoadNum !== 'all' && count % mLoadNum === 0) {
  1772. if (resumeUrl) {
  1773. resumeUrl = null;
  1774. } else {
  1775. resumeUrl = url;
  1776. log('waiting for user to scroll further before loading more images, loaded ' + count + ' pages so far, next url is ' + resumeUrl);
  1777. return;
  1778. }
  1779. }
  1780. if (numPages && curPage + 1 > numPages) {
  1781. log('reached "numPages" ' + numPages + ', assuming end of chapter');
  1782. return;
  1783. }
  1784. if (lastUrl === url) {
  1785. log('last url (' + lastUrl + ') is the same as current (' + url + '), assuming end of chapter');
  1786. return;
  1787. }
  1788. curPage += 1;
  1789. count += 1;
  1790. lastUrl = url;
  1791. if (imp.pages) {
  1792. imp.pages(url, curPage, addAndLoad, ex, getPageInfo);
  1793. } else {
  1794. var colonIdx = url.indexOf(':');
  1795. if(colonIdx > -1) {
  1796. url = location.protocol + url.slice(colonIdx + 1);
  1797. }
  1798. xhr.open('get', url);
  1799. imp.beforexhr && imp.beforexhr(xhr);
  1800. xhr.onload = getPageInfo;
  1801. xhr.onerror = function() {
  1802. log('failed to load page, aborting', 'error');
  1803. };
  1804. xhr.send();
  1805. }
  1806. },
  1807. count = 1,
  1808. pagesLoaded = curPage - 1,
  1809. lastUrl, UI, resumeUrl;
  1810. if (!imgUrl || (!nextUrl && curPage < numPages)) {
  1811. log('failed to retrieve ' + (!imgUrl ? 'image url' : 'next page url'), 'exit');
  1812. }
  1813.  
  1814. // gather chapter stats
  1815. pageStats.curChap = ex('curchap', {
  1816. type: 'index',
  1817. invIdx: !!imp.invchap
  1818. });
  1819. pageStats.numChaps = ex('numchaps');
  1820.  
  1821. // do some checks on the chapter urls
  1822. nextChapter = (nextChapter && nextChapter.trim() === location.href + '#' ? null : nextChapter);
  1823. prevChapter = (prevChapter && prevChapter.trim() === location.href + '#' ? null : prevChapter);
  1824.  
  1825. UI = getViewer(prevChapter, nextChapter);
  1826.  
  1827. UI.statsPages.textContent = ' 0/1 loaded, ' + numPages + ' total';
  1828.  
  1829. if (mLoadNum !== 'all') {
  1830. window.addEventListener('scroll', throttle(function(e) {
  1831. if (!resumeUrl) return; // exit early if we don't have a position to resume at
  1832. if(!UI.imageHeight) {
  1833. UI.imageHeight = getEl('.ml-images img').clientHeight;
  1834. }
  1835. var scrollBottom = document.body.scrollHeight - ((document.body.scrollTop || document.documentElement.scrollTop) + window.innerHeight);
  1836. if (scrollBottom < UI.imageHeight * 2) {
  1837. log('user scroll nearing end, loading more images starting from ' + resumeUrl);
  1838. loadNextPage(resumeUrl);
  1839. }
  1840. }, 100));
  1841. }
  1842.  
  1843. addAndLoad(imgUrl, nextUrl);
  1844.  
  1845. };
  1846.  
  1847. var waitAndLoad = function(imp) {
  1848. isLoaded = true;
  1849. if(imp.wait) {
  1850. var waitType = typeof imp.wait;
  1851. if(waitType === 'number') {
  1852. setTimeout(loadManga.bind(null, imp), imp.wait || 0);
  1853. } else {
  1854. var isReady = waitType === 'function' ? imp.wait.bind(imp) : function() {
  1855. return getEl(imp.wait);
  1856. };
  1857. var intervalId = setInterval(function() {
  1858. if(isReady()) {
  1859. log('Condition fulfilled, loading');
  1860. clearInterval(intervalId);
  1861. loadManga(imp);
  1862. }
  1863. }, 200);
  1864. }
  1865. } else {
  1866. loadManga(imp);
  1867. }
  1868. };
  1869.  
  1870. var MLoaderLoadImps = function(imps) {
  1871. var success = imps.some(function(imp) {
  1872. if (imp.match && (new RegExp(imp.match, 'i')).test(pageUrl)) {
  1873. currentImpName = imp.name;
  1874. if (W.BM_MODE || (autoload !== 'no' && (mAutoload || autoload))) {
  1875. log('autoloading...');
  1876. waitAndLoad(imp);
  1877. return true;
  1878. }
  1879. // setup load hotkey
  1880. var loadHotKey = function(e) {
  1881. if(e.ctrlKey && e.keyCode == 188) {
  1882. e.preventDefault();
  1883. btnLoad.click();
  1884. window.removeEventListener('keydown', loadHotKey);
  1885. }
  1886. };
  1887. window.addEventListener('keydown', loadHotKey);
  1888. // append button to dom that will trigger the page load
  1889. btnLoad = createButton('Load Manga', function(evt) {
  1890. waitAndLoad(imp);
  1891. this.remove();
  1892. }, btnLoadCss);
  1893. document.body.appendChild(btnLoad);
  1894. return true;
  1895. }
  1896. });
  1897.  
  1898. if (!success) {
  1899. log('no implementation for ' + pageUrl, 'error');
  1900. }
  1901. };
  1902.  
  1903. var pageUrl = window.location.href,
  1904. btnLoadCss = toStyleStr({
  1905. 'position': 'fixed',
  1906. 'bottom': 0,
  1907. 'right': 0,
  1908. 'padding': '5px',
  1909. 'margin': '0 10px 10px 0',
  1910. 'z-index': '9999999999'
  1911. }),
  1912. currentImpName, btnLoad;
  1913.  
  1914. // indicates whether UI loaded
  1915. var isLoaded = false;
  1916. // used when switching chapters
  1917. var autoload = storeGet('autoload');
  1918. // manually set by user in menu
  1919. var mAutoload = storeGet('mAutoload') || false;
  1920. // should we load less pages at a time?
  1921. var mLoadNum = storeGet('mLoadNum') || 10;
  1922. // holder for statistics
  1923. var pageStats = {
  1924. numPages: null, numLoaded: null, loadLimit: null, curChap: null, numChaps: null
  1925. };
  1926.  
  1927. // clear autoload
  1928. storeDel('autoload');
  1929.  
  1930. log('starting...');
  1931.  
  1932. // extra check for settings (hack) on dumb firefox/scriptish, settings aren't udpated until document end
  1933. W.document.addEventListener('DOMContentLoaded', function(e) {
  1934. if(!isLoaded) return;
  1935. // used when switching chapters
  1936. autoload = storeGet('autoload');
  1937. // manually set by user in menu
  1938. mAutoload = storeGet('mAutoload') || false;
  1939. // should we load less pages at a time?
  1940. mLoadNum = storeGet('mLoadNum') || 10;
  1941. if(autoload || mAutoload) {
  1942. btnLoad.click();
  1943. }
  1944. });
  1945. MLoaderLoadImps(implementations);