SlideShow

Automatically presses the "next" button on image gallaries. Will only work if the next button is a hyperlink ( <a> ) instead of a div ( <div> ).

Verzia zo dňa 29.07.2015. Pozri najnovšiu verziu.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, Greasemonkey alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, % alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, % alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey alebo Userscripts.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie, ako napríklad Tampermonkey.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie správcu používateľských skriptov.

(Už mám správcu používateľských skriptov, nechajte ma ho nainštalovať!)

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

(Už mám správcu používateľských štýlov, nechajte ma ho nainštalovať!)

// ==UserScript==
// @name        SlideShow
// @namespace   
// @description Automatically presses the "next" button on image gallaries. Will only work if the next button is a hyperlink ( <a> ) instead of a div ( <div> ).
// @include     *
// @include     http://code.jquery.com/jquery-2.1.4.min.js
// @version     1
// @grant       none
// ==/UserScript==

/* OPTIONS */

/* When the image is off the screen, when to move down.
0-1 = Never
3/4 = 3 Quarters of the way through
2/3 = 2 Thirds of the way through
2 = Half way through
3 = Third of the way through
4 = Quarter of the way through

etc.
*/
var whenToMoveDown = 2;

/* In milliseconds (1 second * 1000), how long the animation is for the screen to move auto scroll to the image.
For no animation, set it to 0
*/
var moveDownAnimationTime = 1000;

/* END OPTIONS */

var windowHeight;
var slide = false;
var timer;
var timer2;
var timehalf;
var height;
var heightNum;
var mainImage;
$(window).load(function(){
  var cookieExsist = checkCookie();
  $( '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>');
  $( '#slidecontrols' ).html('<input id="slidetime" value="10"/><div id="slidelabel">(seconds)</div><button id="slide">Start</button>');
  $( '#slidetime' ).css({'width': '60%', 'float': 'left', 
                         'padding': '0 3px',
                         'font-size': '13px',
                         'background-color': '#383838',
                         'color': '#fff',
                         'height':'28px',
                         'margin': '2px 0',
                         'text-align': 'center'
                        });
  $( '#slidelabel' ).css({'float': 'left',
                          'padding': '0 3px',
                          'font-size': '13px',
                          'color': '#000',
                          'height': '28px',
                          'line-height': '30px',
                          'margin': '2px 0'
                         });
  $( '#slide' ).css({'width': '14%', 'float': 'right', 
                     'padding': '0 3px',
                     'font-size': '13px',
                     'background-color': '#D0D0D0',
                     'color': '#585858',
                     'height':'28px',
                     'margin': '2px 0',
                     'text-align': 'center',
                     'border-radius': '5px',
                     'border': '1px solid blue',
                     'font-weight': 'normal'
                    });
  height = $( '#slidecontainer' ).css( "height" );
  heightNum = $( '#slidecontainer' ).height();
  windowHeight = $( window ).height();
  $( 'body' ).css({'margin-top': height});
  if(cookieExsist)
  {
    var slidetime = getCookie('slideactive');
    slide = true;
    $( '#slide' ).text('Stop');
    var sts = slidetime / 1000;
    $( '#slidetime' ).val(sts);
    $( '#slidetime' ).attr("disabled", true);
    timer = setInterval(function(){nextPage();},slidetime);
    timehalf = slidetime / whenToMoveDown;
    scroll();
  }
  
  
  $( '#slide' ).click(function(){
    if(!slide)
    {
      slide = true;
      $( '#slide' ).text('Stop');
      var slidetime = $('#slidetime').val();
      slidetime = slidetime * 1000;
      if(!$.isNumeric(slidetime) || slidetime == '')
      {
          slidetime = 10000;
      }
      timehalf = slidetime / 2;
      timer = setInterval(function(){nextPage();},slidetime);
      setCookie('slideactive',slidetime,1);
      $( '#slidetime' ).attr("disabled", true);
      scroll();
    }
    else
    {
      stopSlide();
    }
    
    
  });    
});

function stopSlide()
{
  slide = false;
  $( '#slide' ).text('Start');
  clearInterval(timer);
  $( '#slidetime' ).removeAttr("disabled");
  setCookie('slideactive','',0);
  clearTimeout(timer2);
}

function scroll()
{
  var offset = 0;
  var imageHeight = 0;
  $('img').each(function(){
    if($( this ).width() >= 400 || $( this ).height() >= 400)
    {
      offset = $( this ).offset().top;
      imageHeight = $( this ).height();
      mainImage = $( this );
      return false;
    }
  });
  var offset2 = offset - (heightNum + 100);
  $('html, body').animate({ scrollTop: offset2 }, 500);
  var contentheight = offset + imageHeight;
  var downvalue = contentheight - windowHeight;
  if(downvalue+20 >= offset2)
  {
    downvalue +=  20;
    timer2 = setTimeout(function(){$('html, body').animate({ scrollTop: downvalue }, moveDownAnimationTime);}, timehalf);
  }
}

function nextPage()
{
  var found = false;
  $('a').each(function(){
    var t = $(this).text();
    if (t.toLowerCase().indexOf("next") >= 0)
      {
        $(this).click();
        found = true;
        return false;
      }
  });
  if(found == true)
  {
   scroll();
  }
  else
  {
    var URL = $(location).attr('href');
    $('body').trigger({
      type: 'keydown',
      which: 37
    });
    var URL2 = $(location).attr('href');
    if(URL == URL2)
    {
      console.log(mainImage);
      mainImage.click();
      URL2 = $(location).attr('href');
      setTimeout(function(){
        if(URL == URL2)
        {
          alert("Couldn't find a next button! :(");
          stopSlide();
        }
        else
        {
          scroll();
        }
      },1500);
    }
    else
    {
      scroll();
    }
  }
}

function setCookie(cname, cvalue, exdays) {
    var d = new Date();
    d.setTime(d.getTime() + (exdays*24*60*60*1000));
    var expires = "expires="+d.toUTCString();
    document.cookie = cname + "=" + cvalue + "; " + expires+"; path=/";
}

function getCookie(cname) {
    var name = cname + "=";
    var ca = document.cookie.split(';');
    for(var i=0; i<ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1);
        if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
    }
    return "";
}

function checkCookie() {
    var active=getCookie("slideactive");
    if (active!="") {
        return true;
    }else{
        return false;
    }
}