Pinterest Slideshow

Start a slideshow on any Pinterest page where there's pins. Clean and minimalist design. 5s interval between slides. Use spacebar to start, left/right keys to navigate.

当前为 2017-06-19 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Pinterest Slideshow
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Start a slideshow on any Pinterest page where there's pins. Clean and minimalist design. 5s interval between slides. Use spacebar to start, left/right keys to navigate.
  6. // @author French Bond
  7. // @match https://www.pinterest.com/*
  8. // @grant none
  9. // @require http://code.jquery.com/jquery-latest.js
  10. // ==/UserScript==
  11.  
  12. $(function() {
  13. 'use strict';
  14.  
  15. var pinList = [];
  16. var c = 0;
  17. var slideInterval = 5000;
  18. var interval;
  19. var running = 0;
  20.  
  21. // Add the slideshow button in the header
  22. var slideshowButton = '<div><span class="slideshow" style="cursor:pointer; background-color: #C92228; color: #fff; padding: 8px; font-weight: bold; font-size: 14px; border-radius: 4px;">Slideshow</span></div>';
  23. $('body').append('<div style="position: fixed; bottom: 20px; left: 10px;">' + slideshowButton + '</div>');
  24. $('.slideshow').click(startSlideshow);
  25.  
  26. function startSlideshow() {
  27. // Hide slideshow button
  28. $('.slideshow').hide();
  29. // List the pins
  30. pinList = [];
  31. $('.pinImageWrapper img').each(function(i) {
  32. var src = $(this).attr('src');
  33. //src = src.replace(/^https:\/\/([^/]+)\/([^/]+)\/(.*)/, 'https://$1/originals/$3');
  34. src = src.replace(/^https:\/\/([^/]+)\/([^/]+)\/(.*)/, 'https://$1/564x/$3');
  35. pinList[pinList.length] = src;
  36. });
  37.  
  38. // Add the slideshow menu
  39. $('html').append('<div class="menu-slideshow" style="position: absolute; left:3px; top:3px; font-size:14px;"></div>');
  40. $('.menu-slideshow')
  41. .append('<div class="stop-slideshow" style="cursor:pointer; background-color: #C92228; color: #fff; padding: 7px; float:left; font-weight: bold; border-radius: 4px;">Stop</div>')
  42. //.append('<div class="options-slideshow" style="cursor:pointer; background-color: #666; color: #fff; padding: 7px; float:left; border-radius: 4px; margin-left:3px;">Options</div>')
  43. .append('<div class="info-slideshow" style="color: #ccc; padding: 7px; float:left;">/</div>');
  44. $('.stop-slideshow').click(function() {
  45. $('.menu-slideshow').remove();
  46. clearInterval(interval);
  47. running = 0;
  48. $('.App').css('display', 'block');
  49. $('body').css('background-color', '#fff');
  50. $('body').css('background-image', 'none');
  51. // Show slideshow button
  52. $('.slideshow').show();
  53. console.log('Slideshow stopped');
  54. });
  55.  
  56. // Prepare the slideshow canvas
  57. $('.App').css('display', 'none');
  58. $('body').css('background-repeat', 'no-repeat');
  59. $('body').css('background-size', 'contain');
  60. $('body').css('background-position', 'center');
  61. $('body').css('background-color', '#333');
  62.  
  63. console.log('Starting slideshow');
  64. console.log('Number of slides: ' + pinList.length);
  65. console.log('Slide interval: ' + (slideInterval/1000) + 's');
  66.  
  67. // Start from first slide
  68. c = 0;
  69. clearInterval(interval);
  70. running = 1;
  71. showSlide();
  72. interval = setInterval(nextSlide, slideInterval);
  73. }
  74.  
  75. function showSlide() {
  76. console.log('Current slide: ' + (c+1));
  77. $('body').css('background-image', 'url('+pinList[c]+')');
  78. $('.info-slideshow').html((c+1)+'/'+pinList.length);
  79. }
  80.  
  81. function nextSlide() {
  82. c++;
  83. if (c > pinList.length-1) c = 0;
  84. showSlide();
  85. }
  86.  
  87. function previousSlide() {
  88. c--;
  89. if (c < 0) c = pinList.length-1;
  90. showSlide();
  91. }
  92.  
  93. $("body").keydown(function(e) {
  94. if (running) {
  95. if (e.keyCode == 37) { // left
  96. clearInterval(interval);
  97. previousSlide();
  98. interval = setInterval(nextSlide, slideInterval);
  99. }
  100. if (e.keyCode == 39) { // right
  101. clearInterval(interval);
  102. nextSlide();
  103. interval = setInterval(nextSlide, slideInterval);
  104. }
  105. } else {
  106. if (e.keyCode == 32) startSlideshow();
  107. }
  108. });
  109.  
  110. });