Manga Loader

Load all manga in current page, only available on 178.com and dm5.com

  1. // ==UserScript==
  2. // @name Manga Loader
  3. // @description Load all manga in current page, only available on 178.com and dm5.com
  4. // @author Chris (http://chrisyip.im)
  5. // @include http://*.178.com/*
  6. // @include http://*.dm5.com/*
  7. // @include http://*.dmzj.com/*
  8. // @include http://www.manhua8.com/manhua/*
  9. // @include http://www.manhua8.net/manhua/*
  10. // @include http://www.manhua1.com/manhua/*
  11. // @include http://www.manhua2.com/manhua/*
  12. // @version 1.3.8.4
  13. // @namespace https://gf.qytechs.cn/users/96
  14. // ==/UserScript==
  15.  
  16. ;(function(window){
  17. var style, script, init, resize
  18.  
  19. resize = function(){
  20. document.body.style.width = getComputedStyle(document.querySelector('html')).width
  21. }
  22.  
  23. init = function(){
  24. var load_dm5, load_178, load_manhua8, selector, callback
  25.  
  26. load_dm5 = function(){
  27. var image_div = document.querySelector( selector )
  28. if (!image_div) return;
  29.  
  30. // make image clickable when there's only a image
  31. image_div.id = ''
  32. image_div.innerHTML = ''
  33.  
  34. var pid = DM5_CID
  35. , current_page = DM5_PAGE
  36. , last_page = DM5_IMAGE_COUNT
  37. , key = document.getElementById('dm5_key').value
  38. , url = 'chapterimagefun.ashx'
  39. , img = document.createElement('img')
  40. , page_index = DM5_PAGE + 1
  41. , new_img, jump_to_page, _showNext, _showPre, _setURL, _showEnd
  42. , load_image, next_chapter_box, set_bookmark
  43.  
  44. jump_to_page = function(e){
  45. var page = parseInt(this.getAttribute('data-index'), 10) - 1
  46. if (e.button == 0 || e.button == 1) {
  47. _showNext(page)
  48. } else if (e.button == 2) {
  49. _showPre(page)
  50. }
  51. }
  52.  
  53. _setURL = function(page){
  54. var _url = GetUrlFormat(window.location.href), next_url
  55. if (page < 1) {
  56. next_url = false
  57. } else {
  58. next_url = _url.replace("{0}", "-p" + (page))
  59. }
  60. !!next_url && (location.href = next_url)
  61. }
  62.  
  63. _showPre = function(page) {
  64. if (page > 1) {
  65. _setURL(page - 1)
  66. getimage()
  67. SetFace()
  68. SetReadHistory(DM5_CID, DM5_MID, page - 1, DM5_USERID)
  69. } else {
  70. alert("当前已经是第一页");
  71. }
  72. }
  73.  
  74. _showNext = function(page){
  75. if (page < DM5_IMAGE_COUNT) {
  76. _setURL(page + 1)
  77. SetReadHistory(DM5_CID, DM5_MID, page, DM5_USERID)
  78. getimage()
  79. SetFace()
  80. } else _showEnd()
  81. }
  82.  
  83. _showEnd = function(){
  84. if (!next_chapter_box.hasAttribute('data-show')) {
  85. $.ajax({
  86. url: DM5_CURL_END,
  87. dataType: 'html',
  88. success: function (data) {
  89. var div = $(data).find('#index_mian a[href="javascript:addfavorite();"]').get(0).parentElement
  90. , link = div.querySelector('a[href*=m]')
  91. , s, rect
  92. s = link ? '继续观看:' + link.outerHTML : '这已经是最新章节。'
  93. next_chapter_box.innerHTML += s;
  94. document.body.appendChild(next_chapter_box)
  95. next_chapter_box.style.display = 'block'
  96. rect = next_chapter_box.getBoundingClientRect()
  97. next_chapter_box.style.marginTop = '-' + (rect.height / 2) + 'px'
  98. next_chapter_box.style.marginLeft = '-' + (rect.width / 2) + 'px'
  99. next_chapter_box.setAttribute('data-show', true)
  100. },
  101. error: function(){
  102. location.href = DM5_CURL_END
  103. }
  104. })
  105. } else {
  106. 'none' === next_chapter_box.style.display && (next_chapter_box.style.display = 'block')
  107. }
  108. }
  109.  
  110. set_bookmark = function(){
  111. var imgs = document.querySelectorAll('.manga_image')
  112.  
  113. if ( !imgs.length ) return;
  114.  
  115. var body_index = parseInt(document.body.getAttribute('data-index'), 10) ||
  116. parseInt(imgs[0].getAttribute('data-index'), 10)
  117. , next_index = body_index
  118. , innerHeight = window.innerHeight
  119. , middle_loc = parseInt((innerHeight / 2), 10)
  120.  
  121. for (var i = 0, len = imgs.length, rect; i < len; i++) {
  122. if (body_index - 1 == i) continue;
  123. rect = imgs[i].getBoundingClientRect()
  124. if ((middle_loc <= rect.bottom && innerHeight >= rect.bottom) ||
  125. (0 <= rect.top && middle_loc >= rect.top)) {
  126. next_index = parseInt(imgs[i].getAttribute('data-index'), 10)
  127. break
  128. }
  129. }
  130. if (next_index !== body_index) {
  131. SetReadHistory(DM5_CID, DM5_MID, next_index, DM5_USERID)
  132. document.body.setAttribute('data-index', next_index)
  133. }
  134. }
  135.  
  136. img.className = 'manga_image'
  137.  
  138. next_chapter_box = document.createElement('div')
  139. next_chapter_box.id = 'next_chapter_box'
  140. next_chapter_box.style.display = 'none'
  141. next_chapter_box.innerHTML = '<a class="close">X</a><p>已经是最后一页。<a class="add-bookmark">加入书签</a>。</p>'
  142. next_chapter_box.addEventListener('click', function (e) {
  143. if (-1 < e.target.className.indexOf('add-bookmark')) {
  144. this.style.display = 'none'
  145. SetBookmarker(DM5_CID, DM5_MID, DM5_IMAGE_COUNT, DM5_USERID)
  146. }
  147. if (-1 < e.target.className.indexOf('close')) {
  148. this.style.display = 'none'
  149. }
  150. }, false)
  151.  
  152. ;(function(page){
  153. var that = arguments.callee
  154. $.ajax({
  155. url: url,
  156. data: {
  157. cid: pid,
  158. page: page,
  159. language: 1,
  160. key: key
  161. },
  162. success: function(data){
  163. var d
  164. eval(data)
  165.  
  166. if (!Array.isArray(d)) return;
  167.  
  168. for (var i = 0, len = d.length, url; i < len; i++) {
  169. current_page++
  170. url = d[i].trim()
  171. if ('' == url || !!image_div.querySelector('img[src="' + url + '"]')) continue;
  172. var el = img.cloneNode()
  173. el.src = d[i]
  174. el.setAttribute('data-index', page_index++)
  175. el.addEventListener('mouseup', jump_to_page, false)
  176. image_div.appendChild(el)
  177. if (current_page > last_page) break;
  178. }
  179.  
  180. if (current_page <= last_page) {
  181. that.call(null, current_page)
  182. }
  183. }
  184. })
  185. })(current_page)
  186.  
  187. window.addEventListener('scroll', set_bookmark, false)
  188. }
  189. // end load_dm5
  190.  
  191. load_178 = function(){
  192. var img = document.querySelector( selector )
  193. if (!img) return;
  194. var parent = img.parentElement
  195. , currentPage = parseInt(document.querySelector('#jump_select2').value, 10)
  196. , url_taste = /(.*\/\d+)(?:-\d+)?(\..*)/i.exec(location.href)
  197. , url = {
  198. prefix: url_taste[1] + '-',
  199. format: url_taste[2]
  200. }
  201. , callback = function(){
  202. var page = parseInt(this.getAttribute('data-index'), 10)
  203. if (page < COMIC_PAGE.page_count) {
  204. window.location.href = url.prefix + (page + 1) + url.format
  205. return;
  206. } else {
  207. if ($('#next_chapter').size() > 0) {
  208. nextChapterMsgBox()
  209. } else {
  210. if (final_page_url) {
  211. window.location.href=final_page_url
  212. return;
  213. }
  214. alert('你已经浏览完所有内容。')
  215. window.location.href = 'http://manhua.178.com'
  216. }
  217. }
  218. }
  219.  
  220. for (var i = currentPage, len = arr_pages.length, el; i < len; i++) {
  221. el = document.createElement('img')
  222. el.src = img_prefix + arr_pages[i]
  223. el.setAttribute('data-index', i + 1)
  224. el.addEventListener('mouseup', callback, false)
  225. parent.appendChild(el)
  226. }
  227. }
  228.  
  229. load_manhua8 = function(){
  230. var img = document.querySelector( selector )
  231. if (!img) return;
  232. var parent = img.parentElement
  233. , pager = document.querySelector( '#topSelect' )
  234. , total_page = pager.querySelector( 'option:last-child' ).value
  235. , current_page = parseInt( pager.value, 10 )
  236. , url_taste = /(.+?)(\d+)(\.[a-z]{3,4})$/i.exec( img.src )
  237. , url = {
  238. prefix: url_taste[1],
  239. page_num_length: url_taste[2].length,
  240. format: url_taste[3]
  241. }
  242. , formatURL = function ( index ) {
  243. index = String(index)
  244. var len = url.page_num_length - index.length
  245. while ( len ) {
  246. index = '0' + index
  247. len--
  248. }
  249. return url.prefix + index + url.format
  250. }
  251.  
  252. while ( ++current_page <= total_page ) {
  253. el = document.createElement( 'img' )
  254. el.classList.add( 'ImgComic' )
  255. el.src = formatURL( current_page )
  256. el.setAttribute( 'data-index', current_page )
  257. parent.appendChild( el )
  258. }
  259. }
  260.  
  261. if ( /dmzj\.com|178\.com/.test( location.host ) ) {
  262. selector = 'img[id*=bigimg]'
  263. callback = load_178
  264. } else if ( ~location.host.indexOf( 'dm5.com' ) ) {
  265. selector = '#showimage'
  266. callback = load_dm5
  267. } else if ( /manhua\d+.(com|net)/.test( location.host ) ) {
  268. selector = '#comicImg'
  269. callback = load_manhua8
  270. }
  271.  
  272. (function(){
  273. if ( document.querySelector( selector ) ) {
  274. callback.call()
  275. return;
  276. }
  277.  
  278. if ( document.readyState !== 'complete' ) {
  279. setTimeout( arguments.callee, 1000 )
  280. }
  281. })()
  282. } // end init()
  283.  
  284. document.body.style.minHeight = (screen.availHeight + 100) + 'px'
  285. resize()
  286. window.addEventListener('resize', resize, false)
  287. document.body.style.minWidth = '980px'
  288.  
  289. style = document.createElement('style')
  290. style.innerHTML = '.content .ImgComic, .inner_img img, .manga_image{box-sizing:border-box;padding:1px!important;border:2px solid gray!important;margin:0 auto 10px!important;display:block!important;max-width:99%!important;width:auto!important;height:auto!important;cursor:pointer;}#next_chapter_box{background:#333;position:fixed;top:50%;left:50%;margin:0;z-index:999999;padding:20px;color:#fff;font-size:16px;box-shadow:0 0 15px #000;border-radius:5px;}#next_chapter_box a{color:#FF4E00;cursor:pointer;}.close{position:absolute;top:5px;right:5px;font-size:12px;}'
  291. document.head.appendChild(style)
  292.  
  293. script = document.createElement( 'script' )
  294. script.textContent = '(' + init.toString() + ')( window )'
  295. document.head.appendChild( script )
  296. })(window);

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址