E(x)-Hentai One-Click DL

Enables one-click DL archive downloading (GP/Credits are still required). Supports E-Hentai & EXHentai.

  1. // ==UserScript==
  2. // @name E(x)-Hentai One-Click DL
  3. // @description Enables one-click DL archive downloading (GP/Credits are still required). Supports E-Hentai & EXHentai.
  4. // @author Daku (admin@codeanimu.net)
  5. // @namespace https://github.com/DakuTree/userscripts
  6. // @homepage https://github.com/DakuTree/userscripts
  7. // @homepageURL https://github.com/DakuTree/userscripts
  8. // @supportURL https://github.com/DakuTree/userscripts/issues
  9. // @icon https://e-hentai.org/favicon.ico
  10. // @match https://e-hentai.org/g/*
  11. // @match https://exhentai.org/g/*
  12. // @version 1.4.1
  13. // ==/UserScript==
  14.  
  15. /******SETTINGS******/
  16. var showCostPopup = false; // set to true to show a confirm popup including the cost of the gallery (this is still ignored if you have free gallery downloads via donation)
  17. var downloadOriginal = true;
  18. /********************/
  19.  
  20. //Auto-redirect to https & non g.e (NOTE: This will be done by EH automatically some time in the future so this is just a temp-fix.)
  21. if (location.hostname !== 'exhentai.org' && location.origin !== "https://e-hentai.org") {
  22. location.href = (location.href.replace(/^https?:\/\/(?:g\.)?e-hentai\.org/, "https://e-hentai.org"));
  23. } else if (location.hostname === 'exhentai.org' && location.protocol !== 'https:') {
  24. location.href = (location.href.replace(/^https?:\/\/exhentai\.org/, "https://exhentai.org"));
  25. }
  26.  
  27. var a = document.getElementsByClassName('g2')[0].getElementsByTagName('a')[0]; // "Archive Download" link
  28. var xs = a.getAttributeNode('onclick').nodeValue.split('?')[1].split("'")[0]; // Grab arg from onclick attr
  29. a.removeAttribute('onclick'); // Remove default onclick
  30.  
  31. a.addEventListener('click', function () {
  32. var downloadGallery = true;
  33.  
  34. if (showCostPopup) {
  35. var http_cost = new XMLHttpRequest();
  36. http_cost.open("GET", location.origin + '/archiver.php?' + xs, false);
  37. http_cost.onreadystatechange = function () {
  38. if (http_cost.readyState == 4 && http_cost.status == 200) {
  39. var match_cost = http_cost.responseText.match(/Download Cost:\s+(.*)/);
  40.  
  41. //If gallery has a download cost, and is not free, ask the user if they want to DL the gallery via a confirm popup.
  42. if (match_cost && match_cost[1].replace(/<(?:.|\n)*?>/gm, '').replace(/&nbsp;/gi, '').trim() !== "Free!") {
  43. var cost = match_cost[1].replace(/<(?:.|\n)*?>/gm, '').replace(/&nbsp;/gi, '').trim();
  44. downloadGallery = confirm("This gallery is not free.\nThe cost is: " + cost + ".\nAre you sure you want to DL?");
  45. }
  46. }
  47. };
  48. http_cost.send();
  49. }
  50.  
  51. if (downloadGallery) {
  52. var http = new XMLHttpRequest();
  53. var params = "dlcheck=Download Original Archive&dltype=org";
  54. if (!downloadOriginal) {
  55. params = "dlcheck=Download Resample Archive&dltype=res";
  56. }
  57. http.open("POST", location.origin + '/archiver.php?' + xs, true);
  58. http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  59.  
  60. http.onreadystatechange = function () {
  61. if (http.readyState == 4 && http.status == 200) {
  62. if (http.responseText == 'Insufficient funds.') {
  63. alert('Insufficient funds.');
  64. }
  65. else if (http.responseText.indexOf("Please wait...") !== -1) { //Check if pop-up opened.
  66. var match = /<a href="(http.*?)"/g.exec(http.responseText);
  67. window.location.href = match[1] + "?start=1";
  68. }
  69. else {
  70. //WTF?
  71. }
  72. }
  73. };
  74. http.send(params);
  75. }
  76.  
  77. return false;
  78. }, false);