Advertisement
Guest User

FoolX (now for archive.moe)

a guest
Mar 15th, 2015
1,493
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.39 KB | None | 0 0
  1. // ==UserScript==
  2. // Displayable Name of your script
  3. // @name FoolX
  4.  
  5. // Brief description
  6. // @description Enhances functionality of FoolFuuka boards
  7.  
  8. // Your name, copyright
  9. // @author GNH
  10. // @copyright 2014, GNH
  11.  
  12. // Version Number
  13. // @version 1.1.1
  14.  
  15. // @downloadURL https://dl.dropbox.com/s/5fxjiuig4vnkgte/FoolX.user.js
  16.  
  17. // @include https://*4plebs.org/*
  18. // @include http://*4plebs.org/*
  19. // @include https://archive.moe/*
  20. // @include http://*loveisover.me/*
  21. // @include https://*loveisover.me/*
  22. // @include http://*imcute.yt/*
  23. // @include https://*imcute.yt/*
  24. // @include http://boards.foolz.us/*
  25. // @include https://boards.foolz.us/*
  26.  
  27.  
  28. // ==/UserScript==
  29.  
  30. var newPostCount = 0
  31. var DocumentTitle = document.title
  32. var ignoreInline = ['v']
  33. var rulesBox = $(".rules_box").html();
  34.  
  35. shortcut = {
  36. 'all_shortcuts':{},//All the shortcuts are stored in this array
  37. 'add': function(shortcut_combination,callback,opt) {
  38. //Provide a set of default options
  39. var default_options = {
  40. 'type':'keydown',
  41. 'propagate':false,
  42. 'disable_in_input':false,
  43. 'target':document,
  44. 'keycode':false
  45. }
  46. if(!opt) opt = default_options;
  47. else {
  48. for(var dfo in default_options) {
  49. if(typeof opt[dfo] == 'undefined') opt[dfo] = default_options[dfo];
  50. }
  51. }
  52.  
  53. var ele = opt.target;
  54. if(typeof opt.target == 'string') ele = document.getElementById(opt.target);
  55. var ths = this;
  56. shortcut_combination = shortcut_combination.toLowerCase();
  57.  
  58. //The function to be called at keypress
  59. var func = function(e) {
  60. e = e || window.event;
  61.  
  62. if(opt['disable_in_input']) { //Don't enable shortcut keys in Input, Textarea fields
  63. var element;
  64. if(e.target) element=e.target;
  65. else if(e.srcElement) element=e.srcElement;
  66. if(element.nodeType==3) element=element.parentNode;
  67.  
  68. if(element.tagName == 'INPUT' || element.tagName == 'TEXTAREA') return;
  69. }
  70.  
  71. //Find Which key is pressed
  72. if (e.keyCode) code = e.keyCode;
  73. else if (e.which) code = e.which;
  74. var character = String.fromCharCode(code).toLowerCase();
  75.  
  76. if(code == 188) character=","; //If the user presses , when the type is onkeydown
  77. if(code == 190) character="."; //If the user presses , when the type is onkeydown
  78.  
  79. var keys = shortcut_combination.split("+");
  80. //Key Pressed - counts the number of valid keypresses - if it is same as the number of keys, the shortcut function is invoked
  81. var kp = 0;
  82.  
  83. //Work around for stupid Shift key bug created by using lowercase - as a result the shift+num combination was broken
  84. var shift_nums = {
  85. "`":"~",
  86. "1":"!",
  87. "2":"@",
  88. "3":"#",
  89. "4":"$",
  90. "5":"%",
  91. "6":"^",
  92. "7":"&",
  93. "8":"*",
  94. "9":"(",
  95. "0":")",
  96. "-":"_",
  97. "=":"+",
  98. ";":":",
  99. "'":"\"",
  100. ",":"<",
  101. ".":">",
  102. "/":"?",
  103. "\\":"|"
  104. }
  105. //Special Keys - and their codes
  106. var special_keys = {
  107. 'esc':27,
  108. 'escape':27,
  109. 'tab':9,
  110. 'space':32,
  111. 'return':13,
  112. 'enter':13,
  113. 'backspace':8,
  114.  
  115. 'scrolllock':145,
  116. 'scroll_lock':145,
  117. 'scroll':145,
  118. 'capslock':20,
  119. 'caps_lock':20,
  120. 'caps':20,
  121. 'numlock':144,
  122. 'num_lock':144,
  123. 'num':144,
  124.  
  125. 'pause':19,
  126. 'break':19,
  127.  
  128. 'insert':45,
  129. 'home':36,
  130. 'delete':46,
  131. 'end':35,
  132.  
  133. 'pageup':33,
  134. 'page_up':33,
  135. 'pu':33,
  136.  
  137. 'pagedown':34,
  138. 'page_down':34,
  139. 'pd':34,
  140.  
  141. 'left':37,
  142. 'up':38,
  143. 'right':39,
  144. 'down':40,
  145.  
  146. 'f1':112,
  147. 'f2':113,
  148. 'f3':114,
  149. 'f4':115,
  150. 'f5':116,
  151. 'f6':117,
  152. 'f7':118,
  153. 'f8':119,
  154. 'f9':120,
  155. 'f10':121,
  156. 'f11':122,
  157. 'f12':123
  158. }
  159.  
  160. var modifiers = {
  161. shift: { wanted:false, pressed:false},
  162. ctrl : { wanted:false, pressed:false},
  163. alt : { wanted:false, pressed:false},
  164. meta : { wanted:false, pressed:false} //Meta is Mac specific
  165. };
  166.  
  167. if(e.ctrlKey) modifiers.ctrl.pressed = true;
  168. if(e.shiftKey) modifiers.shift.pressed = true;
  169. if(e.altKey) modifiers.alt.pressed = true;
  170. if(e.metaKey) modifiers.meta.pressed = true;
  171.  
  172. for(var i=0; k=keys[i],i<keys.length; i++) {
  173. //Modifiers
  174. if(k == 'ctrl' || k == 'control') {
  175. kp++;
  176. modifiers.ctrl.wanted = true;
  177.  
  178. } else if(k == 'shift') {
  179. kp++;
  180. modifiers.shift.wanted = true;
  181.  
  182. } else if(k == 'alt') {
  183. kp++;
  184. modifiers.alt.wanted = true;
  185. } else if(k == 'meta') {
  186. kp++;
  187. modifiers.meta.wanted = true;
  188. } else if(k.length > 1) { //If it is a special key
  189. if(special_keys[k] == code) kp++;
  190.  
  191. } else if(opt['keycode']) {
  192. if(opt['keycode'] == code) kp++;
  193.  
  194. } else { //The special keys did not match
  195. if(character == k) kp++;
  196. else {
  197. if(shift_nums[character] && e.shiftKey) { //Stupid Shift key bug created by using lowercase
  198. character = shift_nums[character];
  199. if(character == k) kp++;
  200. }
  201. }
  202. }
  203. }
  204.  
  205. if(kp == keys.length &&
  206. modifiers.ctrl.pressed == modifiers.ctrl.wanted &&
  207. modifiers.shift.pressed == modifiers.shift.wanted &&
  208. modifiers.alt.pressed == modifiers.alt.wanted &&
  209. modifiers.meta.pressed == modifiers.meta.wanted) {
  210. callback(e);
  211.  
  212. if(!opt['propagate']) { //Stop the event
  213. //e.cancelBubble is supported by IE - this will kill the bubbling process.
  214. e.cancelBubble = true;
  215. e.returnValue = false;
  216.  
  217. //e.stopPropagation works in Firefox.
  218. if (e.stopPropagation) {
  219. e.stopPropagation();
  220. e.preventDefault();
  221. }
  222. return false;
  223. }
  224. }
  225. }
  226. this.all_shortcuts[shortcut_combination] = {
  227. 'callback':func,
  228. 'target':ele,
  229. 'event': opt['type']
  230. };
  231. //Attach the function with the event
  232. if(ele.addEventListener) ele.addEventListener(opt['type'], func, false);
  233. else if(ele.attachEvent) ele.attachEvent('on'+opt['type'], func);
  234. else ele['on'+opt['type']] = func;
  235. },
  236.  
  237. //Remove the shortcut - just specify the shortcut and I will remove the binding
  238. 'remove':function(shortcut_combination) {
  239. shortcut_combination = shortcut_combination.toLowerCase();
  240. var binding = this.all_shortcuts[shortcut_combination];
  241. delete(this.all_shortcuts[shortcut_combination])
  242. if(!binding) return;
  243. var type = binding['event'];
  244. var ele = binding['target'];
  245. var callback = binding['callback'];
  246.  
  247. if(ele.detachEvent) ele.detachEvent('on'+type, callback);
  248. else if(ele.removeEventListener) ele.removeEventListener(type, callback, false);
  249. else ele['on'+type] = false;
  250. }
  251. }
  252.  
  253. var getBoard = function() {
  254. URL = document.URL
  255. return URL.split("/")[3]
  256. }
  257.  
  258. var inlineImages = function()
  259. {
  260. // I Believe because I'm setting the src of the thumbnail to the full image right away,
  261. // it also causes the images to be prefetched
  262. $('.thread_image_box').each(function(index,currentImage) {
  263. if ($(currentImage).data("inline") != "true")
  264. {
  265. $(currentImage).find('a').each(function() {
  266. fullImage = $(this).attr('href')
  267. if (!fullImage.match(/thumb(-[23])?/))
  268. {
  269. if (!fullImage.match(/search(-[23])?/))
  270. {
  271. if (!fullImage.match(/redirect?/))
  272. {
  273. if (!fullImage.match(/download/))
  274. {
  275. $(currentImage).find('img').each(function() {
  276. $(this).attr('src',fullImage);
  277. $(this).click(function(e){
  278. e.preventDefault()
  279. if ($(this).hasClass("fullImage")) {
  280. $(this).attr('width',$(this).data("thumbWidth"))
  281. $(this).attr('height',$(this).data("thumbHeight"))
  282. $(this).removeClass("fullImage")
  283.  
  284. } else {
  285. $(this).data("thumbWidth",$(this).attr('width'));
  286. $(this).data("thumbbHeight", $(this).attr('height'));
  287. $(this).removeAttr('width');
  288. $(this).removeAttr('height');
  289. $(this).addClass("fullImage");
  290. }
  291. }
  292. );
  293. });
  294. }
  295. }
  296. }
  297. $(currentImage).data("inline","true")
  298. }
  299. })
  300. }
  301. })
  302. }
  303.  
  304. var hidePosts = function()
  305. {
  306. $('.pull-left').each(function(index, currentPost) {
  307. if ($(currentPost).hasClass('stub')) {
  308. $(currentPost).removeClass('stub')
  309. }
  310. });
  311. }
  312.  
  313. var ThreadUpdate = function() { postCounter(); inlineImages(); hidePosts(); newPosts(); }
  314. var seenPosts = function(){$('article').each(function(index, currentArticle){$(currentArticle).data('seen','true')});}
  315.  
  316. var newPosts = function() {
  317. $('article').each(function(index, currentArticle)
  318. {
  319. if ($(currentArticle).data('seen') != 'true')
  320. {
  321. $(currentArticle).data('seen', 'true')
  322. newPostCount +=1
  323. }
  324. });
  325.  
  326. if (windowFocus == true) newPostCount = 0
  327. document.title = "(" + newPostCount + ") " + DocumentTitle
  328. }
  329.  
  330. var postCounter = function() {$(".rules_box").html("<h6>Posts: " + $('.post_wrapper').length + "/400 <br> Images: " + $(".thread_image_box").length + "/250</h6>" + rulesBox)}
  331.  
  332. var bindShortcuts = function()
  333. {
  334.  
  335. }
  336.  
  337. $(document).ready(function(){
  338. windowFocus = true
  339. $(window).focus(function(){windowFocus = true; ThreadUpdate()})
  340. $(window).blur(function(){windowFocus = false})
  341. })
  342.  
  343. var executeShortcut = function(shortcut) {
  344. console.log(shortcut)
  345. var input = document.getElementById('reply_chennodiscursus')
  346. var selectedText;
  347. var text = document.getElementById('reply_chennodiscursus').value
  348.  
  349. if (input.selectionStart != undefined)
  350. {
  351. var startPos = input.selectionStart;
  352. var endPos = input.selectionEnd;
  353. selectedText = input.value.substring(startPos, endPos)
  354. var newtext = "[" + shortcut + "]" + selectedText + "[/" + shortcut + "]"
  355. document.getElementById('reply_chennodiscursus').value = text.replace(selectedText,newtext)
  356. }
  357.  
  358.  
  359.  
  360. }
  361.  
  362.  
  363. $(function(){
  364. shortcut.add("ctrl+s", function(){ executeShortcut("spoiler")});
  365. shortcut.add("ctrl+i", function(){ executeShortcut("i")});
  366. shortcut.add("ctrl+b", function(){ executeShortcut("b")});
  367. shortcut.add("ctrl+u", function(){ executeShortcut("u")});
  368.  
  369. seenPosts()
  370. ThreadUpdate()
  371. getBoard()
  372. bindShortcuts()
  373. window.setInterval( function(){ ThreadUpdate(); }, 500 );
  374. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement