AutoPager for E-Hentai

Provides AutoPager-like function for E-Hentai.

La data de 03-08-2014. Vezi ultima versiune.

  1. // ==UserScript==
  2. // @name AutoPager for E-Hentai
  3. // @description Provides AutoPager-like function for E-Hentai.
  4. // @grant GM_xmlhttpRequest
  5. // @grant unsafeWindow
  6. // @include http://g.e-hentai.org/*
  7. // @version 0.0.1.20140803090251
  8. // @namespace https://greasyfork.org/users/2233
  9. // ==/UserScript==
  10.  
  11. var wnd = window
  12. var doc = wnd.document
  13. var loc = location
  14. var href = loc.href
  15.  
  16. if(/^http:\/\/g\.e-hentai\.org\//.test(href))
  17. {
  18. if(!/\/[gs]\//.test(href)){ throw 'exit' }
  19.  
  20. var gid = gtoken = ''
  21. if(/\/g\//.test(href))
  22. {
  23. var m = /\/g\/([^\/]+)\/([^\/]+)/.exec(href)
  24. if(m == null){ alert('Invalid gallery.'); throw 'exit' }
  25. gid = m[1], gtoken = m[2]
  26. }
  27. else if(/\/s\//.test(href))
  28. {
  29. var m = /\/s\/([^\/]+)\/([^\/]+)-([0-9]+)/.exec(href)
  30. if(m == null){ alert('Invalid image page.'); throw 'exit' }
  31. var imgkey = m[1], gid = m[2], page = m[3]
  32. if(imgkey.length > 10) { imgkey = imgkey.substring(0, 10) }
  33. var gtoken = GM_xmlhttpRequest({
  34. method: 'POST',
  35. url: 'http://g.e-hentai.org/api.php',
  36. data: JSON.stringify({'method':'gtoken', 'pagelist':[[gid, imgkey, page]]}),
  37. synchronous: true,
  38. })
  39. gtoken = JSON.parse(gtoken.responseText)['tokenlist'][0]['token']
  40. }
  41. if(gid == '' || gtoken == ''){ alert('Cannot find gid or gtoken.'); throw 'exit' }
  42.  
  43. var filecount = ''
  44. filecount = GM_xmlhttpRequest({
  45. method: 'POST',
  46. url: 'http://g.e-hentai.org/api.php',
  47. data: JSON.stringify({'method':'gdata', 'gidlist':[[gid, gtoken]]}),
  48. synchronous: true,
  49. })
  50. filecount = parseInt(JSON.parse(filecount.responseText)['gmetadata'][0]['filecount'])
  51. if(isNaN(filecount)){ alert('Cannot find file count.'); throw 'exit' }
  52.  
  53. if(/\/g\//.test(href))
  54. {
  55. var page = imgkey = ''
  56. page = parseInt(doc.querySelector('#gdt a').href.replace(/^.*-([0-9]+)/, '$1')), page_url = ''
  57. lnks = doc.getElementsByTagName('A')
  58. for(var i=lnks.length-1; i>=0; i--)
  59. {
  60. if(new RegExp('/s/[^/]+/'+gid+'-'+page+'$').test(lnks[i].href))
  61. {
  62. try {
  63. page_url = lnks[i].href
  64. imgkey = /\/s\/([^\/]+)/.exec(lnks[i].href)[1]
  65. if(imgkey.length > 10) { imgkey = imgkey.substring(0, 10) }
  66. } catch(e){}
  67. break
  68. }
  69. }
  70. }
  71. else if(/\/s\//.test(href)){ page_url = href.replace(/\?.*/, '') }
  72. if(imgkey == ''){ alert('Cannot find the first imgkey.'); throw 'exit' }
  73.  
  74. var showkey = ''
  75. try {
  76. showkey = /\bshowkey=['"]?([-0-9a-z]+)/.exec(GM_xmlhttpRequest({
  77. method: 'GET',
  78. url: page_url,
  79. synchronous: true,
  80. }).responseText)[1]
  81. } catch(e){}
  82. if(showkey == ''){ alert('Cannot find the first showkey.'); throw 'exit' }
  83.  
  84. var b = doc.body
  85. var append_img = function()
  86. {
  87. GM_xmlhttpRequest({
  88. method: 'POST',
  89. url: 'http://g.e-hentai.org/api.php',
  90. data: JSON.stringify({'method':'showpage', 'gid':gid, 'page':page, 'imgkey':imgkey, 'showkey':showkey}),
  91. onload: function(response)
  92. {
  93. var i3 = JSON.parse(response.responseText)['i3']
  94. var img_src = /src=['"]([^'"]+)['"]/.exec(i3)[1].replace(/&/g, '&')
  95.  
  96. var img = new Image()
  97. img.id = page
  98. img.onerror = function(){ this.onerror = null; this.style.display = 'none' }
  99. img.src = img_src
  100. img.style.cssText = 'display: block; margin-left: auto; margin-right: auto'
  101. img.width = wnd.innerWidth * 0.70
  102. b.appendChild(doc.createTextNode('p. '+page))
  103. b.appendChild(doc.createElement('BR'))
  104. b.appendChild(img)
  105. b.appendChild(doc.createElement('BR'))
  106.  
  107. if(page >= filecount){ return }
  108. var m = /\/s\/([^'"]+?)\/[^'"]+-([0-9]+)['"]/.exec(i3)
  109. if(m == null){ alert('An error happened when parsing p. ' + page); return }
  110. imgkey = m[1]
  111. page = parseInt(m[2])
  112. setTimeout(append_img, 3000)
  113. }
  114. })
  115. }
  116. append_img()
  117. }