Sleazy Fork is available in English.

Sadpanda Download Archive hotkey

Adds a hotkey to download Archive.

  1. // ==UserScript==
  2. // @name Sadpanda Download Archive hotkey
  3. // @namespace exh
  4. // @description Adds a hotkey to download Archive.
  5. // @include http://exhentai.org/g/*
  6. // @include https://exhentai.org/g/*
  7. // @include http://g.e-hentai.org/g/*
  8. // @include https://g.e-hentai.org/g/*
  9. // @version 1.2
  10. // @grant none
  11. // @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js
  12. // ==/UserScript==
  13.  
  14.  
  15. var link = getArchiveLink();
  16.  
  17. function getArchiveLink() {
  18. var EXTRACT_URL_REGEX = /http.*\.php\?[a-zA-Z0-9&=]*/
  19. var linkElm = $('.gm a:contains("Archive")')
  20. var link = linkElm.attr('onclick').match(EXTRACT_URL_REGEX);
  21.  
  22. shortcut.add('space', function() {
  23. linkElm[0].click();
  24. }, {
  25. disable_in_input: true,
  26. });
  27. return link;
  28. }
  29.  
  30.  
  31. /**
  32. * http://www.openjs.com/scripts/events/keyboard_shortcuts/
  33. * Version : 2.01.B
  34. * By Binny V A
  35. * License : BSD
  36. */
  37. shortcut = {
  38. 'all_shortcuts':{},//All the shortcuts are stored in this array
  39. 'add': function(shortcut_combination,callback,opt) {
  40. //Provide a set of default options
  41. var default_options = {
  42. 'type':'keydown',
  43. 'propagate':false,
  44. 'disable_in_input':false,
  45. 'target':document,
  46. 'keycode':false
  47. }
  48. if(!opt) opt = default_options;
  49. else {
  50. for(var dfo in default_options) {
  51. if(typeof opt[dfo] == 'undefined') opt[dfo] = default_options[dfo];
  52. }
  53. }
  54.  
  55. var ele = opt.target;
  56. if(typeof opt.target == 'string') ele = document.getElementById(opt.target);
  57. var ths = this;
  58. shortcut_combination = shortcut_combination.toLowerCase();
  59.  
  60. //The function to be called at keypress
  61. var func = function(e) {
  62. e = e || window.event;
  63.  
  64. if(opt['disable_in_input']) { //Don't enable shortcut keys in Input, Textarea fields
  65. var element;
  66. if(e.target) element=e.target;
  67. else if(e.srcElement) element=e.srcElement;
  68. if(element.nodeType==3) element=element.parentNode;
  69.  
  70. if(element.tagName == 'INPUT' || element.tagName == 'TEXTAREA') return;
  71. }
  72.  
  73. //Find Which key is pressed
  74. if (e.keyCode) code = e.keyCode;
  75. else if (e.which) code = e.which;
  76. var character = String.fromCharCode(code).toLowerCase();
  77.  
  78. if(code == 188) character=","; //If the user presses , when the type is onkeydown
  79. if(code == 190) character="."; //If the user presses , when the type is onkeydown
  80.  
  81. var keys = shortcut_combination.split("+");
  82. //Key Pressed - counts the number of valid keypresses - if it is same as the number of keys, the shortcut function is invoked
  83. var kp = 0;
  84.  
  85. //Work around for stupid Shift key bug created by using lowercase - as a result the shift+num combination was broken
  86. var shift_nums = {
  87. "`":"~",
  88. "1":"!",
  89. "2":"@",
  90. "3":"#",
  91. "4":"$",
  92. "5":"%",
  93. "6":"^",
  94. "7":"&",
  95. "8":"*",
  96. "9":"(",
  97. "0":")",
  98. "-":"_",
  99. "=":"+",
  100. ";":":",
  101. "'":"\"",
  102. ",":"<",
  103. ".":">",
  104. "/":"?",
  105. "\\":"|"
  106. }
  107. //Special Keys - and their codes
  108. var special_keys = {
  109. 'esc':27,
  110. 'escape':27,
  111. 'tab':9,
  112. 'space':32,
  113. 'return':13,
  114. 'enter':13,
  115. 'backspace':8,
  116.  
  117. 'scrolllock':145,
  118. 'scroll_lock':145,
  119. 'scroll':145,
  120. 'capslock':20,
  121. 'caps_lock':20,
  122. 'caps':20,
  123. 'numlock':144,
  124. 'num_lock':144,
  125. 'num':144,
  126.  
  127. 'pause':19,
  128. 'break':19,
  129.  
  130. 'insert':45,
  131. 'home':36,
  132. 'delete':46,
  133. 'end':35,
  134.  
  135. 'pageup':33,
  136. 'page_up':33,
  137. 'pu':33,
  138.  
  139. 'pagedown':34,
  140. 'page_down':34,
  141. 'pd':34,
  142.  
  143. 'left':37,
  144. 'up':38,
  145. 'right':39,
  146. 'down':40,
  147.  
  148. 'f1':112,
  149. 'f2':113,
  150. 'f3':114,
  151. 'f4':115,
  152. 'f5':116,
  153. 'f6':117,
  154. 'f7':118,
  155. 'f8':119,
  156. 'f9':120,
  157. 'f10':121,
  158. 'f11':122,
  159. 'f12':123
  160. }
  161.  
  162. var modifiers = {
  163. shift: { wanted:false, pressed:false},
  164. ctrl : { wanted:false, pressed:false},
  165. alt : { wanted:false, pressed:false},
  166. meta : { wanted:false, pressed:false} //Meta is Mac specific
  167. };
  168.  
  169. if(e.ctrlKey) modifiers.ctrl.pressed = true;
  170. if(e.shiftKey) modifiers.shift.pressed = true;
  171. if(e.altKey) modifiers.alt.pressed = true;
  172. if(e.metaKey) modifiers.meta.pressed = true;
  173.  
  174. for(var i=0; k=keys[i],i<keys.length; i++) {
  175. //Modifiers
  176. if(k == 'ctrl' || k == 'control') {
  177. kp++;
  178. modifiers.ctrl.wanted = true;
  179.  
  180. } else if(k == 'shift') {
  181. kp++;
  182. modifiers.shift.wanted = true;
  183.  
  184. } else if(k == 'alt') {
  185. kp++;
  186. modifiers.alt.wanted = true;
  187. } else if(k == 'meta') {
  188. kp++;
  189. modifiers.meta.wanted = true;
  190. } else if(k.length > 1) { //If it is a special key
  191. if(special_keys[k] == code) kp++;
  192.  
  193. } else if(opt['keycode']) {
  194. if(opt['keycode'] == code) kp++;
  195.  
  196. } else { //The special keys did not match
  197. if(character == k) kp++;
  198. else {
  199. if(shift_nums[character] && e.shiftKey) { //Stupid Shift key bug created by using lowercase
  200. character = shift_nums[character];
  201. if(character == k) kp++;
  202. }
  203. }
  204. }
  205. }
  206.  
  207. if(kp == keys.length &&
  208. modifiers.ctrl.pressed == modifiers.ctrl.wanted &&
  209. modifiers.shift.pressed == modifiers.shift.wanted &&
  210. modifiers.alt.pressed == modifiers.alt.wanted &&
  211. modifiers.meta.pressed == modifiers.meta.wanted) {
  212. callback(e);
  213.  
  214. if(!opt['propagate']) { //Stop the event
  215. //e.cancelBubble is supported by IE - this will kill the bubbling process.
  216. e.cancelBubble = true;
  217. e.returnValue = false;
  218.  
  219. //e.stopPropagation works in Firefox.
  220. if (e.stopPropagation) {
  221. e.stopPropagation();
  222. e.preventDefault();
  223. }
  224. return false;
  225. }
  226. }
  227. }
  228. this.all_shortcuts[shortcut_combination] = {
  229. 'callback':func,
  230. 'target':ele,
  231. 'event': opt['type']
  232. };
  233. //Attach the function with the event
  234. if(ele.addEventListener) ele.addEventListener(opt['type'], func, false);
  235. else if(ele.attachEvent) ele.attachEvent('on'+opt['type'], func);
  236. else ele['on'+opt['type']] = func;
  237. },
  238.  
  239. //Remove the shortcut - just specify the shortcut and I will remove the binding
  240. 'remove':function(shortcut_combination) {
  241. shortcut_combination = shortcut_combination.toLowerCase();
  242. var binding = this.all_shortcuts[shortcut_combination];
  243. delete(this.all_shortcuts[shortcut_combination])
  244. if(!binding) return;
  245. var type = binding['event'];
  246. var ele = binding['target'];
  247. var callback = binding['callback'];
  248.  
  249. if(ele.detachEvent) ele.detachEvent('on'+type, callback);
  250. else if(ele.removeEventListener) ele.removeEventListener(type, callback, false);
  251. else ele['on'+type] = false;
  252. }
  253. }