Advertisement
Guest User

godspeed

a guest
Jul 26th, 2019
955
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.26 KB | None | 0 0
  1. ===this creates a list of all your favorites on e-hentai. use this with hitomi downloader, replace all instances of e- with ex. Godspeed anons, and may the corruption spare you===
  2. // ==UserScript==
  3. // @name Sadpanda Save/Export All Favorites
  4. // @namespace SaddestPanda
  5. // @description Load all favorites to the page and save it or just copy the textbox contents. Works on exhentai and e-hentai.
  6. // @include /^https?://e.hentai\.org/favorites.php.*/
  7. // @homepage https://greasyfork.org/en/scripts/23406-sadpanda-save-export-all-favorites
  8. // @supportURL https://greasyfork.org/en/scripts/23406-sadpanda-save-export-all-favorites/feedback
  9. // @version 2.3.0
  10. // @grant GM.getValue
  11. // @grant GM.setValue
  12. // @grant GM.deleteValue
  13. // @grant GM_addValueChangeListener
  14. // @grant GM.addValueChangeListener
  15. // @require https://greasyfork.org/scripts/371339-gm-webextpref/code/GM_webextPref.js?version=623327
  16. // @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js
  17. // @require https://cdnjs.cloudflare.com/ajax/libs/he/1.2.0/he.min.js
  18. // ==/UserScript==
  19.  
  20. //Top text box inspiration and its code from http://userscripts-mirror.org/scripts/show/173553. But this one won't have an import feature like that one.
  21. //Using Jquery for jquery purposes and he.js for he.js purposes.
  22. //Using GM_webextPref for the preferences menu. Many thanks to the author "eight" for the library. Greasyfork libraries use a specific version so they should be from malicious updates.
  23.  
  24. //Use the options menu to change these values.
  25. var inserttoTable = true; //Disables inserting new pages to the table. Set this to false if your browser gets real slow. You can still use the textbox to save your favorites.
  26. var pageTimer = 5000; //Waiting timer for each page in miliseconds. Default is 2500. Making it too short might prevent pages from loading.
  27.  
  28. const pref = GM_webextPref({
  29. default: {
  30. inserttoTable: true,
  31. pageTimer: 5000
  32. },
  33. body: [{
  34. key: "inserttoTable",
  35. type: "checkbox",
  36. label: "Insert new pages into the current page. Disable this if your browser freezes."
  37. },
  38. {
  39. key: "pageTimer",
  40. type: "number",
  41. label: "Time (ms) to load each page. Keep this higher than 2000 especially if you set the thumbnails to load with the page."
  42. }
  43. ]
  44. });
  45.  
  46. var counter = 0,
  47. showExport = 0,
  48. pageNumber = "",
  49. winlocsea = "?";
  50. var displayMode = $("#dms [selected='selected']")[0].value; // m:minimal, p:minimal+, l:compact, e:extended, t:thumbnail
  51. //console.log(displayMode);
  52. if (window.location.search == "") {
  53. winlocsea = "?";
  54. } else {
  55. winlocsea = window.location.search;
  56. }
  57. var PageUrl = "favorites.php" + winlocsea + "&page=";
  58.  
  59. function destroyBox() {
  60. $('.uselessbr').each(function() { $(this).remove(); });
  61. $('#exportFav').remove();
  62. $('#exportStatus').remove();
  63. }
  64.  
  65. function getPageNumber() {
  66. var finalcell = $(".ptt")[0].rows[0].cells[$(".ptt")[0].rows[0].cells.length - 2];
  67. pageNumber = finalcell.textContent;
  68. }
  69.  
  70. function addRemoveButton() {
  71. $('#exportFav').after("<div>");
  72. $('#exportFav').next().append($('<input/>').attr('type', 'button').attr('value', 'Remove titles from the list').attr('id', 'removeTitles').attr('style', 'margin-top:5px;min-height:18px;'));
  73. $('#removeTitles').click(removeTitles);
  74. }
  75.  
  76. function removeTitles() {
  77. $('#exportFav')[0].textContent = $('#exportFav')[0].textContent.replace(/( - .*)/g, "");
  78. }
  79.  
  80. function getText(thisa) {
  81. var thetext = "";
  82. if (displayMode == "e") {
  83. thetext = he.encode(thisa.href + " - " + thisa.children[0].children[0].innerText);
  84. } else if (displayMode == "l") {
  85. thetext = he.encode(thisa.href + " - " + thisa.children[0].innerText);
  86. } else {
  87. thetext = he.encode(thisa.href + " - " + thisa.text);
  88. }
  89. $('#exportFav').append(thetext + '\n');
  90. }
  91.  
  92. function getThisPage() {
  93. var trlen, thislink, j = 0;
  94. if (displayMode == "e") {
  95. trlen = $(".glink").length;
  96. for (j = 0; j < trlen; j++) {
  97. thislink = $(".glink")[j].parentNode.parentNode;
  98. getText(thislink);
  99. }
  100. } else {
  101. trlen = $(".itg .glname").length;
  102. for (j = 0; j < trlen; j++) {
  103. thislink = $(".itg .glname a")[j];
  104. getText(thislink);
  105. }
  106. }
  107. }
  108.  
  109. function exportFavorites() {
  110. if (showExport === 0) {
  111. showExport = 1;
  112. $('#nb').after('<br class="uselessbr"/>');
  113. $('#nb').after($('<input/>').attr('type', 'button').attr('value', 'START').attr('id', 'startBut').attr('href', 'javascript:void(0)').attr('style', 'margin-left:5px;margin-top:5px;min-height:18px;'));
  114. $('#startBut').click(getThePages);
  115. $('#nb').after($('<input/>').attr('type', 'button').attr('value', 'Options').attr('id', 'optionsBut').attr('href', 'javascript:void(0)').attr('style', 'margin-top:5px;min-height:18px;'));
  116. $('#optionsBut').click(pref.openDialog);
  117. $('#nb').after('<br class="uselessbr"/>');
  118. $('#nb').after('<textarea id="exportStatus" name="Text2" cols="80" rows="8" ... />');
  119. $('#nb').after('<h2 class="uselessbr">Status');
  120. $('#nb').after('<textarea id="exportFav" name="Text1" cols="80" rows="7" ... />');
  121. $('#nb').after('<h2 class="uselessbr">Text List of Favorites');
  122. $('#nb').after('<br class="uselessbr"/><br class="uselessbr"/>');
  123. $('#exportStatus').append("Currently the website is REALLY SLOW so keep the delay between pages at least 5000 if you want the pages/thumbnails to load." + '\n\n');
  124. $('#exportStatus').append("Chrome and some other browsers throttle background tabs so if you switch to another tab it might prevent you from loading all the pages." + '\n');
  125. $('#exportStatus').append("To bypass that; turn this tab into its own window before you start and don't minimize it." + '\n');
  126. if (pageNumber > 10) {
  127. $('#exportStatus').append("You more than 10 pages. If your browser crashes disable inserting to the page from the options." + '\n\n');
  128. }
  129. $('#exportStatus').append("Press START below to start loading the pages." + '\n');
  130. } else {
  131. //destroyBox();
  132. //showExport = 0;
  133. return;
  134. }
  135.  
  136. if (window.location.search.indexOf("page=") != -1) {
  137. $('#exportFav').append("GO TO THE FIRST PAGE AND TRY AGAIN" + '\n');
  138. $('#exportStatus').append("GO TO THE FIRST PAGE AND TRY AGAIN" + '\n');
  139. return;
  140. }
  141. }
  142.  
  143. function getThePages() {
  144. inserttoTable = pref.get("inserttoTable");
  145. pageTimer = pref.get("pageTimer");
  146. getThisPage();
  147. if (pageNumber > 1) {
  148. $('#exportStatus').append("Loading all pages will take " + (Math.ceil(pageTimer / 100) * (pageNumber)) / 10 + " seconds." + '\n');
  149. //$('#exportStatus').append("NOTICE - If your browser completely freezes, try using the newest Firefox/Chrome with tampermonkey/violentmonkey or help me fix it." + '\n');
  150. for (var ii = 1; ii < pageNumber; ii++) {
  151. //console.log("Queued page: " + ii);
  152. setTimeout(function() {
  153. counter++;
  154. //console.log("Current page: " + counter);
  155. $('#exportStatus').append("Loading Page " + (counter + 1) + " of " + pageNumber + "..." + '\n');
  156. if ((counter + 1) == pageNumber) {
  157. setTimeout(function() {
  158. $('#exportStatus').append("Loading complete." + '\n' + "Copy above list, Ctrl+S to save the page or use an extension like SingleFile or Save Page WE." + '\n');
  159. addRemoveButton();
  160. $('#exportStatus').append("Confirmation: " + ($('#exportFav')[0].value.split("\n").length - 1) + " favorites in above text area, " + ($(".itg .glname a").length + $(".gl4e .glink").length) + " favorites in below page." + '\n');
  161. if (pageNumber > 10) {
  162. $('#exportStatus').append("If your gallery count doesn't add up, try again. You can load the pages faster now that you cached all the thumbnails." + '\n\n');
  163. }
  164. $('#exportStatus').scrollTop($('#exportStatus')[0].scrollHeight);
  165. }, pageTimer + 2500);
  166. }
  167. $('#exportStatus').scrollTop($('#exportStatus')[0].scrollHeight);
  168. $.ajax({
  169. url: PageUrl + counter,
  170. type: 'GET',
  171. tryCount: 0,
  172. retryLimit: 5,
  173. success: function(sss) {
  174. //do something
  175. var trlen, thislink, j = 0;
  176. trlen = (displayMode == "e") ? $(sss).find(".glink").length : $(sss).find(".itg .glname").length;
  177. for (j = 0; j < trlen; j++) {
  178. thislink = (displayMode == "e") ? $(sss).find(".glink")[j].parentNode.parentNode : $(sss).find(".itg .glname a")[j];
  179. getText(thislink);
  180. if (inserttoTable) {
  181. if (displayMode != "t") {
  182. $(".itg tbody")[0].append($(thislink).parents("tr:first")[0]);
  183. } else {
  184. $(".itg")[0].append($(thislink).parents(".gl1t")[0]);
  185. }
  186. }
  187. }
  188. },
  189. error: function(xhr, textStatus, errorThrown) {
  190. this.tryCount++;
  191. if (this.tryCount <= this.retryLimit) {
  192. //try again
  193. $.ajax(this);
  194. return;
  195. }
  196. return;
  197. /*
  198. if (textStatus == 'timeout') {
  199.  
  200. }
  201. if (xhr.status == 500) {
  202. //handle error
  203. } else {
  204. //handle error
  205. }
  206. */
  207. }
  208. });
  209.  
  210. }, 200 + ii * pageTimer);
  211. }
  212. } else {
  213. $('#exportStatus').append("Loading complete." + '\n' + "Copy above list, Ctrl+S to save the page or use an extension like SingleFile or Save Page WE." + '\n');
  214. $('#exportStatus').append("Confirmation: " + ($('#exportFav')[0].value.split("\n").length - 1) + " favorites in above text area, " + ($(".itg .glname a").length + $(".gl4e .glink").length) + " favorites in below page." + '\n');
  215. addRemoveButton();
  216. }
  217. }
  218.  
  219. $(document).ready(function() {
  220. var topmenu = document.querySelector("#nb");
  221. topmenu.style.justifyContent = "center";
  222. topmenu.style.maxWidth = "1400px";
  223. $('#nb').append($('<div/>').attr('id', 'exportFavsdiv'));
  224. $('#exportFavsdiv').append($('<a/>').attr('href', 'javascript:void(0)').attr('id', 'exportFavorites').text('Load All Favorites'));
  225. $('#exportFavorites').click(exportFavorites);
  226. document.querySelector("#exportFavsdiv").style.marginLeft = "8px";
  227. getPageNumber();
  228. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement