Update 'DuckDuckGo Images Slideshow.user.js'
Add Image Counter Display
This commit is contained in:
parent
bece740d3f
commit
141cde3cf2
@ -1,9 +1,9 @@
|
|||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name DuckDuckGo Images Slideshow
|
// @name DuckDuckGo Images Slideshow
|
||||||
// @namespace https://bullercodeworks.com
|
// @namespace https://bullercodeworks.com
|
||||||
// @version 0.2
|
// @version 0.3
|
||||||
// @description Takes a DuckDuckGo Images page and turns it into a slideshow.
|
// @description Takes a DuckDuckGo Images page and turns it into a slideshow.
|
||||||
// @author You
|
// @author brian@bullercodeworks.com
|
||||||
// @match https://duckduckgo.com/*
|
// @match https://duckduckgo.com/*
|
||||||
// @grant none
|
// @grant none
|
||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
@ -12,7 +12,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var init = function() {
|
var init = function() {
|
||||||
console.log("Starting Slideshow");
|
|
||||||
lb.style.textAlign = 'center';
|
lb.style.textAlign = 'center';
|
||||||
lb.style.height = '100%';
|
lb.style.height = '100%';
|
||||||
lb.style.width = '100%';
|
lb.style.width = '100%';
|
||||||
@ -24,6 +23,12 @@
|
|||||||
document.body.prepend(lb);
|
document.body.prepend(lb);
|
||||||
lbimg.style.objectFit = 'cover';
|
lbimg.style.objectFit = 'cover';
|
||||||
lb.append(lbimg);
|
lb.append(lbimg);
|
||||||
|
imgCounter.style.backgroundColor = 'rgba(0, 0, 0, 0.85)';
|
||||||
|
imgCounter.style.color = 'white';
|
||||||
|
imgCounter.style.position = 'fixed';
|
||||||
|
imgCounter.style.top = '0px';
|
||||||
|
imgCounter.style.left = '0px';
|
||||||
|
lb.append(imgCounter);
|
||||||
running = true;
|
running = true;
|
||||||
showImage(0);
|
showImage(0);
|
||||||
}
|
}
|
||||||
@ -53,6 +58,7 @@
|
|||||||
var imgcount=allimages.length;
|
var imgcount=allimages.length;
|
||||||
var lb = document.createElement('div');
|
var lb = document.createElement('div');
|
||||||
var lbimg = document.createElement('img');
|
var lbimg = document.createElement('img');
|
||||||
|
var imgCounter = document.createElement('span');
|
||||||
var lastScroll = 0;
|
var lastScroll = 0;
|
||||||
|
|
||||||
|
|
||||||
@ -65,7 +71,7 @@
|
|||||||
var testimages = document.querySelectorAll('img');
|
var testimages = document.querySelectorAll('img');
|
||||||
var testcount = testimages.length;
|
var testcount = testimages.length;
|
||||||
if(testcount > imgcount) {
|
if(testcount > imgcount) {
|
||||||
console.log("Image Count Changed:"+testcount+" > "+imgcount);
|
console.log("Loading more images...");
|
||||||
imgcount = testcount;
|
imgcount = testcount;
|
||||||
allimages = testimages;
|
allimages = testimages;
|
||||||
}
|
}
|
||||||
@ -83,8 +89,9 @@
|
|||||||
timer = setTimeout(() => showImage(++idx), 100);
|
timer = setTimeout(() => showImage(++idx), 100);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
allimages[idx].click();
|
||||||
allimages[idx].scrollIntoView();
|
allimages[idx].scrollIntoView();
|
||||||
console.log("Showing Image "+idx+" :: "+allimages[idx]);
|
console.log("Showing Image "+idx+" ("+allimages[idx]+")");
|
||||||
var useHeight=allimages[idx].height > allimages[idx].width;
|
var useHeight=allimages[idx].height > allimages[idx].width;
|
||||||
if(useHeight){
|
if(useHeight){
|
||||||
lbimg.style.height = '100%';
|
lbimg.style.height = '100%';
|
||||||
@ -94,6 +101,7 @@
|
|||||||
lbimg.style.width = '100%'
|
lbimg.style.width = '100%'
|
||||||
}
|
}
|
||||||
lbimg.src = allimages[idx].src;
|
lbimg.src = allimages[idx].src;
|
||||||
|
imgCounter.innerText = "Image " + idx + " / " + imgcount;
|
||||||
timer = setTimeout(() => showImage(++idx), imageTime);
|
timer = setTimeout(() => showImage(++idx), imageTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,10 +145,10 @@
|
|||||||
|
|
||||||
function pause(){
|
function pause(){
|
||||||
if(paused){
|
if(paused){
|
||||||
console.log("resume");
|
console.log("Resuming Slideshow");
|
||||||
showImage(currimg);
|
showImage(currimg);
|
||||||
} else {
|
} else {
|
||||||
console.log("pause");
|
console.log("Pausing Slideshow");
|
||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
}
|
}
|
||||||
paused = !paused;
|
paused = !paused;
|
||||||
@ -148,7 +156,7 @@
|
|||||||
|
|
||||||
|
|
||||||
function rewind() {
|
function rewind() {
|
||||||
console.log("rewind");
|
console.log("Rewinding Slideshow");
|
||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
currimg = currimg-1;
|
currimg = currimg-1;
|
||||||
showImage(currimg);
|
showImage(currimg);
|
||||||
@ -156,7 +164,7 @@
|
|||||||
|
|
||||||
|
|
||||||
function fastforward() {
|
function fastforward() {
|
||||||
console.log("fast forward");
|
console.log("Fast Forwarding Slideshow");
|
||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
currimg = currimg+1;
|
currimg = currimg+1;
|
||||||
showImage(currimg);
|
showImage(currimg);
|
||||||
|
Loading…
Reference in New Issue
Block a user