Imgur Album Slideshow

Adds a menu to Imgur albums to start a slideshow

目前为 2017-04-05 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Imgur Album Slideshow
  3. // @version v3.6
  4. // @description Adds a menu to Imgur albums to start a slideshow
  5. // @author Withaika
  6. // @match *://imgur.com/a/*
  7. // @grant none
  8. // @require http://code.jquery.com/jquery-1.12.4.min.js
  9. // @require http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.min.js
  10. // @namespace https://greasyfork.org/users/94615
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. $("#right-content").prepend("<div id='ssMenu' style='box-sizing: border-box;width: 300px;padding: 8px;background-color: #2c2f34;border-radius: 4px;height: 135px;'><center><p style='display:inline-block;padding-bottom:10px;'>Delay (s):</p><input value='3' style='display:inline-block;width:30px;margin-bottom:10px;'id='ssSec'></input></center><center><p style='margin-top:-5px;'>Randomize:</p><label class='switch'><input id='randomize' type='checkbox'><div class='slider round'></div></label></center><center style='margin-top:5px;'><button id='ssStart' style='text-align: center;cursor: pointer;padding-left: 8px;height: 36px;box-sizing: border-box;padding-right: 8px;background: #5c69ff;border: none;color: #F2F2F2;text-decoration: none;outline: 0;-webkit-user-select: none;user-select: none;cursor: pointer; display: inline-block;border-radius: 2px;font-size: 14px;border: none;font-family: \"Open Sans\",sans-serif;'>Start Slideshow</button><div id='restart' style='display:none'><p style='display:inline-block'> </p><button id='ssReStart' style='text-align: center;cursor: pointer;padding-left: 8px;height: 36px;box-sizing: border-box;padding-right: 8px;background: #ed6d6d;border: none;color: #F2F2F2;text-decoration: none;outline: 0;-webkit-user-select: none;user-select: none;cursor: pointer; display: inline-block;border-radius: 2px;font-size: 14px;border: none;font-family: \"Open Sans\",sans-serif;'>Restart Slideshow</button></div></center></div>");
  15. $('body').prepend('<style>.switch { position: relative; display: inline-block; width: 45px; height: 20px; }.switch input {display:none;}.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; -webkit-transition: .4s; transition: .4s; } .slider:before { position: absolute; content: ""; height: 12px; width: 12px; left: 4px; bottom: 4px; background-color: white; -webkit-transition: .4s; transition: .4s; } input:checked + .slider { background-color: #2196F3; } input:focus + .slider { box-shadow: 0 0 1px #2196F3; } input:checked + .slider:before { -webkit-transform: translateX(26px); -ms-transform: translateX(26px); transform: translateX(26px); } .slider.round { border-radius: 34px; } .slider.round:before { border-radius: 50%; }</style>');
  16. })();
  17.  
  18. var slideIndex = 1;
  19. var Images=[];
  20.  
  21. function plusDivs(n) {
  22. showDivs(slideIndex += n);
  23. }
  24.  
  25. function showDivs(n) {
  26. var i;
  27. var x = Images;
  28. if (n > x.length) {slideIndex = 1;}
  29. if (n < 1) {slideIndex = x.length;}
  30. document.getElementById("FSSI").src=x[slideIndex-1];
  31. }
  32.  
  33. function startSlide(){
  34. document.getElementById("restart").style.display="inline-block";
  35. if (document.getElementById("randomize").checked){undefinedImages = _widgetFactory._.config.gallery.image.album_images.randomize();}else{undefinedImages = _widgetFactory._.config.gallery.image.album_images;}
  36. for (i=0;i<undefinedImages.length;i++){
  37. ext=undefinedImages[i].ext;
  38. hsh=undefinedImages[i].hash;
  39. Images.push("https://i.imgur.com/"+hsh+ext);
  40. }
  41. var delay = parseInt(document.getElementById("ssSec").value);
  42. var isPaused=false;
  43. $("body").append("<img id='FSSI' style='width:auto;height:100%' src=''></div>");
  44. $(document).keydown(function(e) {
  45. switch(e.which) {
  46. case 37: // left
  47. plusDivs(-1);
  48. break;
  49. case 38: // up
  50. delay--;
  51. break;
  52. case 39: // right
  53. plusDivs(1);
  54. break;
  55. case 40: // down
  56. delay++;
  57. break;
  58. case 32: // space
  59. if (isPaused){isPaused=false;}else{isPaused=true;}
  60. break;
  61. case 27: // escape
  62. FSTog(document.getElementById("FSSI"));
  63. clearInterval(intID);
  64. break;
  65. default: return;
  66. }
  67. e.preventDefault();
  68. });
  69. showDivs(slideIndex);
  70. FSTog(document.getElementById("FSSI"));
  71. var intID=window.setInterval(function(){
  72. if(!isPaused) {
  73. plusDivs(1);
  74. }
  75. }, delay*1000);
  76. }
  77.  
  78. function FSTog(element) {
  79. if (!element.fullscreenElement && !element.mozFullScreenElement && !element.webkitFullscreenElement && !element.msFullscreenElement ) {
  80. if (element.requestFullscreen) {
  81. element.requestFullscreen();
  82. } else if (element.msRequestFullscreen) {
  83. element.msRequestFullscreen();
  84. } else if (element.mozRequestFullScreen) {
  85. element.mozRequestFullScreen();
  86. } else if (element.webkitRequestFullscreen) {
  87. element.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
  88. }
  89. } else {
  90. if (element.exitFullscreen) {
  91. element.exitFullscreen();
  92. } else if (element.msExitFullscreen) {
  93. element.msExitFullscreen();
  94. } else if (element.mozCancelFullScreen) {
  95. element.mozCancelFullScreen();
  96. } else if (element.webkitExitFullscreen) {
  97. element.webkitExitFullscreen();
  98. }
  99. }
  100. }
  101.  
  102. Array.prototype.randomize = function() {
  103. array=this;
  104. var currentIndex = array.length, temporaryValue, randomIndex;
  105. while (0 !== currentIndex) {
  106. randomIndex = Math.floor(Math.random() * currentIndex);
  107. currentIndex -= 1;
  108. temporaryValue = array[currentIndex];
  109. array[currentIndex] = array[randomIndex];
  110. array[randomIndex] = temporaryValue;
  111. }
  112. return array;
  113. };
  114.  
  115. document.getElementById("ssStart").addEventListener("click", function(){
  116. startSlide();
  117. });
  118. document.getElementById("ssReStart").addEventListener("click", function(){
  119. startSlide();
  120. slideIndex = 1;
  121. });