SlideShow

Automatically presses the "next" button on image gallaries.

目前為 2015-07-29 提交的版本,檢視 最新版本

  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
  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. /* END OPTIONS */
  31.  
  32. var windowHeight;
  33. var slide = false;
  34. var timer;
  35. var timer2;
  36. var timehalf;
  37. var height;
  38. var heightNum;
  39. var mainImage;
  40. $(window).load(function(){
  41. var cookieExsist = checkCookie();
  42. $( '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>');
  43. $( '#slidecontrols' ).html('<input id="slidetime" value="10"/><div id="slidelabel">(seconds)</div><button id="slide">Start</button>');
  44. $( '#slidetime' ).css({'width': '60%', 'float': 'left',
  45. 'padding': '0 3px',
  46. 'font-size': '13px',
  47. 'background-color': '#383838',
  48. 'color': '#fff',
  49. 'height':'28px',
  50. 'margin': '2px 0',
  51. 'text-align': 'center'
  52. });
  53. $( '#slidelabel' ).css({'float': 'left',
  54. 'padding': '0 3px',
  55. 'font-size': '13px',
  56. 'color': '#000',
  57. 'height': '28px',
  58. 'line-height': '30px',
  59. 'margin': '2px 0'
  60. });
  61. $( '#slide' ).css({'width': '14%', 'float': 'right',
  62. 'padding': '0 3px',
  63. 'font-size': '13px',
  64. 'background-color': '#D0D0D0',
  65. 'color': '#585858',
  66. 'height':'28px',
  67. 'margin': '2px 0',
  68. 'text-align': 'center',
  69. 'border-radius': '5px',
  70. 'border': '1px solid blue',
  71. 'font-weight': 'normal'
  72. });
  73. height = $( '#slidecontainer' ).css( "height" );
  74. heightNum = $( '#slidecontainer' ).height();
  75. windowHeight = $( window ).height();
  76. $( 'body' ).css({'margin-top': height});
  77. if(cookieExsist)
  78. {
  79. var slidetime = getCookie('slideactive');
  80. slide = true;
  81. $( '#slide' ).text('Stop');
  82. var sts = slidetime / 1000;
  83. $( '#slidetime' ).val(sts);
  84. $( '#slidetime' ).attr("disabled", true);
  85. timer = setInterval(function(){nextPage();},slidetime);
  86. timehalf = slidetime / whenToMoveDown;
  87. scroll();
  88. }
  89. $( '#slide' ).click(function(){
  90. if(!slide)
  91. {
  92. slide = true;
  93. $( '#slide' ).text('Stop');
  94. var slidetime = $('#slidetime').val();
  95. slidetime = slidetime * 1000;
  96. if(!$.isNumeric(slidetime) || slidetime == '')
  97. {
  98. slidetime = 10000;
  99. }
  100. timehalf = slidetime / 2;
  101. timer = setInterval(function(){nextPage();},slidetime);
  102. setCookie('slideactive',slidetime,1);
  103. $( '#slidetime' ).attr("disabled", true);
  104. scroll();
  105. }
  106. else
  107. {
  108. stopSlide();
  109. }
  110. });
  111. });
  112.  
  113. function stopSlide()
  114. {
  115. slide = false;
  116. $( '#slide' ).text('Start');
  117. clearInterval(timer);
  118. $( '#slidetime' ).removeAttr("disabled");
  119. setCookie('slideactive','',0);
  120. clearTimeout(timer2);
  121. }
  122.  
  123. function scroll()
  124. {
  125. var offset = 0;
  126. var imageHeight = 0;
  127. $('img').each(function(){
  128. if($( this ).width() >= 400 || $( this ).height() >= 400)
  129. {
  130. offset = $( this ).offset().top;
  131. imageHeight = $( this ).height();
  132. mainImage = $( this );
  133. return false;
  134. }
  135. });
  136. var offset2 = offset - (heightNum + 100);
  137. $('html, body').animate({ scrollTop: offset2 }, 500);
  138. var contentheight = offset + imageHeight;
  139. var downvalue = contentheight - windowHeight;
  140. if(downvalue+20 >= offset2)
  141. {
  142. downvalue += 20;
  143. timer2 = setTimeout(function(){$('html, body').animate({ scrollTop: downvalue }, moveDownAnimationTime);}, timehalf);
  144. }
  145. }
  146.  
  147. function nextPage()
  148. {
  149. var found = false;
  150. $('a').each(function(){
  151. var t = $(this).text();
  152. if (t.toLowerCase().indexOf("next") >= 0)
  153. {
  154. $(this).click();
  155. found = true;
  156. return false;
  157. }
  158. });
  159. if(found == true)
  160. {
  161. scroll();
  162. }
  163. else
  164. {
  165. var URL = $(location).attr('href');
  166. $('body').trigger({
  167. type: 'keydown',
  168. which: 37
  169. });
  170. var URL2 = $(location).attr('href');
  171. if(URL == URL2)
  172. {
  173. console.log(mainImage);
  174. mainImage.click();
  175. URL2 = $(location).attr('href');
  176. setTimeout(function(){
  177. if(URL == URL2)
  178. {
  179. alert("Couldn't find a next button! :(");
  180. stopSlide();
  181. }
  182. else
  183. {
  184. scroll();
  185. }
  186. },1500);
  187. }
  188. else
  189. {
  190. scroll();
  191. }
  192. }
  193. }
  194.  
  195. function setCookie(cname, cvalue, exdays) {
  196. var d = new Date();
  197. d.setTime(d.getTime() + (exdays*24*60*60*1000));
  198. var expires = "expires="+d.toUTCString();
  199. document.cookie = cname + "=" + cvalue + "; " + expires+"; path=/";
  200. }
  201.  
  202. function getCookie(cname) {
  203. var name = cname + "=";
  204. var ca = document.cookie.split(';');
  205. for(var i=0; i<ca.length; i++) {
  206. var c = ca[i];
  207. while (c.charAt(0)==' ') c = c.substring(1);
  208. if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
  209. }
  210. return "";
  211. }
  212.  
  213. function checkCookie() {
  214. var active=getCookie("slideactive");
  215. if (active!="") {
  216. return true;
  217. }else{
  218. return false;
  219. }
  220. }
  221.