Slideshow Pinterest

Start a slide show on any Pinterest page where there's pins. Clean and minimalist design. 5s interval between slides. Use left/right keyboard to navigate.

目前為 2016-10-18 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Slideshow Pinterest
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Start a slide show on any Pinterest page where there's pins. Clean and minimalist design. 5s interval between slides. Use left/right keyboard to navigate.
// @author       French Bond
// @match        https://www.pinterest.com/*
// @grant        none
// @require http://code.jquery.com/jquery-latest.js
// ==/UserScript==

(function() {
    'use strict';

    var imgList = [];
    var c = 0;
    var slideInterval = 5000;
    var interval;

    $('.leftHeaderContent').append('<span class="slideshow" style="cursor:pointer; background-color: #C92228; color: #fff; padding: 5px;">Slideshow</span>');

    $('.slideshow').click(function() {
        imgList = [];
        $('.pinImg').each(function(i) {
            var src = $(this).attr('src');
            //src = src.replace(/^https:\/\/([^/]+)\/([^/]+)\/(.*)/, 'https://$1/originals/$3');
            src = src.replace(/^https:\/\/([^/]+)\/([^/]+)\/(.*)/, 'https://$1/564x/$3');
            imgList[imgList.length] = src;
        });
        startSlideshow();
    });

    function startSlideshow() {
        $('html').append('<div class="stop-slideshow" style="cursor:pointer; background-color: #C92228; color: #fff; padding: 5px; position: absolute; left:0; top:0;">Stop</div>');
        $('.stop-slideshow').click(function() {
            clearInterval(interval);
            $('.App').css('display', 'block');
            $('body').css('background-color', '#fff');
            $('body').css('background-image', 'none');
        });

        $('.App').css('display', 'none');
        $('body').css('background-repeat', 'no-repeat');
        $('body').css('background-size', 'contain');
        $('body').css('background-position', 'center');
        $('body').css('background-color', '#333');

        console.log('Starting slideshow');
        console.log('Number of slides: ' + imgList.length);
        console.log('Slide interval: ' + (slideInterval/1000) + 's');

        c = 0;
        showSlide();
        interval = setInterval(nextSlide, slideInterval);
    }

    function showSlide() {
        console.log('Current slide: ' + (c+1));
        $('body').css('background-image', 'url('+imgList[c]+')');
    }

    function nextSlide() {
        c++;
        if (c > imgList.length-1) c = 0;
        showSlide();
    }

    function previousSlide() {
        c--;
        if (c < 0) c = imgList.length-1;
        showSlide();
    }

    $("body").keydown(function(e) {
        if(e.keyCode == 37) { // left
            clearInterval(interval);
            previousSlide();
            interval = setInterval(nextSlide, slideInterval);
        }
        else if(e.keyCode == 39) { // right
            clearInterval(interval);
            nextSlide();
            interval = setInterval(nextSlide, slideInterval);
        }
    });

})();