SlideShow

Automatically presses the "next" button on image gallaries.

  1. // ==UserScript==
  2. // @name SlideShow
  3. // @namespace
  4. // @description Automatically presses the "next" button on image gallaries.
  5. // @include *
  6. // @include http://code.jquery.com/jquery-2.1.4.min.js
  7. // @version 1.2
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. /* OPTIONS */
  12.  
  13. /* When the image is off the screen, when to move down.
  14. 0-1 = Never
  15. 3/4 = 3 Quarters of the way through
  16. 2/3 = 2 Thirds of the way through
  17. 2 = Half way through
  18. 3 = Third of the way through
  19. 4 = Quarter of the way through
  20.  
  21. etc.
  22. */
  23. var whenToMoveDown = 2;
  24.  
  25. /* In milliseconds (1 second * 1000), how long the animation is for the screen to move auto scroll to the image.
  26. For no animation, set it to 0
  27. */
  28. var moveDownAnimationTime = 1000;
  29.  
  30. /* In pixels, how much space there is between the top of the screen and image. Default is 50. */
  31. var spaceAboveImage = 50;
  32.  
  33. /* END OPTIONS */
  34.  
  35. var windowHeight;
  36. var slide = false;
  37. var timer;
  38. var timer2;
  39. var timehalf;
  40. var height;
  41. var heightNum;
  42. var mainImage;
  43. $(window).load(function(){
  44. var cookieExsist = checkCookie();
  45. $( 'body' ).prepend('<div id="slidecontainer" style="margin: 0 auto; position: fixed; width: 100%; overflow: auto; top: 0; background-color: #fff; border-bottom: 5px solid #A00000; z-index: 100000;"><div id="slidecontrols" style="min-width: 300px; width: 30%; margin: 0 auto;"></div></div>');
  46. $( '#slidecontrols' ).html('<input id="slidetime" value="10"/><div id="slidelabel">(seconds)</div><button id="slide">Start</button>');
  47. $( '#slidetime' ).css({'width': '60%', 'float': 'left',
  48. 'padding': '0 3px',
  49. 'font-size': '13px',
  50. 'background-color': '#383838',
  51. 'color': '#fff',
  52. 'height':'28px',
  53. 'margin': '2px 0',
  54. 'text-align': 'center'
  55. });
  56. $( '#slidelabel' ).css({'float': 'left',
  57. 'padding': '0 3px',
  58. 'font-size': '13px',
  59. 'color': '#000',
  60. 'height': '28px',
  61. 'line-height': '30px',
  62. 'margin': '2px 0'
  63. });
  64. $( '#slide' ).css({'width': '14%', 'float': 'right',
  65. 'padding': '0 3px',
  66. 'font-size': '13px',
  67. 'background-color': '#D0D0D0',
  68. 'color': '#585858',
  69. 'height':'28px',
  70. 'margin': '2px 0',
  71. 'text-align': 'center',
  72. 'border-radius': '5px',
  73. 'border': '1px solid blue',
  74. 'font-weight': 'normal',
  75. 'cursor': 'pointer'
  76. });
  77. height = $( '#slidecontainer' ).css( "height" );
  78. heightNum = $( '#slidecontainer' ).height();
  79. windowHeight = $( window ).height();
  80. $( 'body' ).css({'margin-top': height});
  81. if(cookieExsist)
  82. {
  83. var slidetime = getCookie('slideactive');
  84. slide = true;
  85. $( '#slide' ).text('Stop');
  86. var sts = slidetime / 1000;
  87. $( '#slidetime' ).val(sts);
  88. $( '#slidetime' ).attr("disabled", true);
  89. timer = setInterval(function(){nextPage();},slidetime);
  90. timehalf = slidetime / whenToMoveDown;
  91. scroll();
  92. }
  93. $( '#slide' ).click(function(){
  94. if(!slide)
  95. {
  96. slide = true;
  97. $( '#slide' ).text('Stop');
  98. var slidetime = $('#slidetime').val();
  99. slidetime = slidetime * 1000;
  100. if(!$.isNumeric(slidetime) || slidetime == '')
  101. {
  102. slidetime = 10000;
  103. }
  104. timehalf = slidetime / 2;
  105. timer = setInterval(function(){nextPage();},slidetime);
  106. setCookie('slideactive',slidetime,1);
  107. $( '#slidetime' ).attr("disabled", true);
  108. scroll();
  109. }
  110. else
  111. {
  112. stopSlide();
  113. }
  114. });
  115. });
  116.  
  117. function stopSlide()
  118. {
  119. slide = false;
  120. $( '#slide' ).text('Start');
  121. clearInterval(timer);
  122. $( '#slidetime' ).removeAttr("disabled");
  123. setCookie('slideactive','',0);
  124. clearTimeout(timer2);
  125. }
  126.  
  127. function scroll()
  128. {
  129. var offset = 0;
  130. var imageHeight = 0;
  131. $('img').each(function(){
  132. if($( this ).width() >= 400 || $( this ).height() >= 400)
  133. {
  134. offset = $( this ).offset().top;
  135. imageHeight = $( this ).height();
  136. mainImage = $( this );
  137. return false;
  138. }
  139. });
  140. var offset2 = offset - (heightNum + spaceAboveImage);
  141. $('html, body').animate({ scrollTop: offset2 }, 500);
  142. var contentheight = offset + imageHeight;
  143. var downvalue = contentheight - windowHeight;
  144. if(downvalue+20 >= offset2)
  145. {
  146. downvalue += 20;
  147. timer2 = setTimeout(function(){$('html, body').animate({ scrollTop: downvalue }, moveDownAnimationTime);}, timehalf);
  148. }
  149. }
  150.  
  151. function nextPage()
  152. {
  153. var URL = $(location).attr('href');
  154. var URL2 = $(location).attr('href');
  155. var found = false;
  156. $('a').each(function(){
  157. var t = $(this).text();
  158. if (t.toLowerCase().indexOf("next") >= 0)
  159. {
  160. $(this).click();
  161. found = true;
  162. }
  163. });
  164. if(URL != URL2 || found == true)
  165. {
  166. scroll();
  167. }
  168. else
  169. {
  170. $('body').trigger({
  171. type: 'keydown',
  172. which: 39
  173. });
  174. URL2 = $(location).attr('href');
  175. if(URL == URL2)
  176. {
  177. console.log(mainImage);
  178. mainImage.click();
  179. URL2 = $(location).attr('href');
  180. setTimeout(function(){
  181. if(URL == URL2)
  182. {
  183. alert("Couldn't find a next button! :(");
  184. stopSlide();
  185. }
  186. else
  187. {
  188. scroll();
  189. }
  190. },100);
  191. }
  192. else
  193. {
  194. scroll();
  195. }
  196. }
  197. }
  198.  
  199. function setCookie(cname, cvalue, exdays) {
  200. var d = new Date();
  201. d.setTime(d.getTime() + (exdays*24*60*60*1000));
  202. var expires = "expires="+d.toUTCString();
  203. document.cookie = cname + "=" + cvalue + "; " + expires+"; path=/";
  204. }
  205.  
  206. function getCookie(cname) {
  207. var name = cname + "=";
  208. var ca = document.cookie.split(';');
  209. for(var i=0; i<ca.length; i++) {
  210. var c = ca[i];
  211. while (c.charAt(0)==' ') c = c.substring(1);
  212. if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
  213. }
  214. return "";
  215. }
  216.  
  217. function checkCookie() {
  218. var active=getCookie("slideactive");
  219. if (active!="") {
  220. return true;
  221. }else{
  222. return false;
  223. }
  224. }