Fix DDG Slideshow

This commit is contained in:
Brian Buller 2024-12-30 08:47:45 -06:00
parent 7e045e8759
commit 7371b0fd03

View File

@ -1,8 +1,8 @@
// ==UserScript==
// @name DuckDuckGo Images Slideshow
// @namespace https://bullercodeworks.com
// @version 0.3
// @description Takes a DuckDuckGo Images page and turns it into a slideshow.
// @version 1.0.0
// @description Takes a DuckDuckGo Images page and adds a button to run through all of the pictures as a slideshow.
// @author brian@bullercodeworks.com
// @match https://duckduckgo.com/*
// @grant none
@ -34,22 +34,33 @@
}
var addSlideshowButton = function() {
if(document.getElementById('slideshow_button') == null) {
var slideshowLi = document.createElement('li');
var slideshowA = document.createElement('a');
slideshowLi.id = "slideshow_button";
slideshowLi.classList.add('zcm__item');
slideshowA.classList.add('zcm__link');
slideshowA.classList.add('js-zci-link');
slideshowA.innerText="Slideshow";
slideshowA.href='#';
slideshowLi.appendChild(slideshowA);
slideshowA.onclick = init;
document.getElementById('duckbar_static').appendChild(slideshowLi);
if(document.getElementById('slideshow-button') == null) {
var ssBtnDiv = document.createElement('div');
var ssBtnA = document.createElement('a');
ssBtnDiv.id = 'slideshow-button';
ssBtnDiv.classList.add('dropdown');
ssBtnA.innerText='Slideshow';
ssBtnA.href='#';
ssBtnDiv.appendChild(ssBtnA);
ssBtnA.onclick = init;
document.querySelector('.metabar__dropdowns').appendChild(ssBtnDiv);
}
}
var removeSlideshowButton = function() {
var ssBtn = document.getElementById('slideshow-button');
if(ssBtn != null) {
ssBtn.parent.delete(ssBtn);
}
}
var checkAndSetSlideshowButton = function() {
if(window.location.toString().includes('iax=images')) {
addSlideshowButton();
clearInterval(btnChecker);
} else {
removeSlideshowButton();
}
}
//var allImagesCache = [];
var currimg=0;
var allimages = document.querySelectorAll('img.tile--img__img');
var timer;
@ -63,11 +74,6 @@
var lastScroll = 0;
var cacheimg = document.createElement('img');
var tab = document.querySelector('.js-zci-link--images');
if(tab == null) { return; } // Need that tab
if(tab.classList.contains('is-active')) { addSlideshowButton(); }
tab.addEventListener('click', addSlideshowButton);
function updateImages() {
var testimages = document.querySelectorAll('img.tile--img__img');
var testcount = testimages.length;
@ -120,6 +126,10 @@
}
function loadOrigImg(idx) {
var detailPanes = document.querySelectorAll('.detail__pane');
if(detailPanes.length == 0) {
console.log('No detail panes');
return;
}
var detailPane = detailPanes[1];
if(detailPanes.length == 2) detailPane = detailPanes[0];
var imgsrc = detailPane.querySelector('img.detail__media__img-highres').src;
@ -128,6 +138,9 @@
lbimg.src = this.src;
timer = setTimeout(() => showImage(++idx), imageTime);
}
newImg.onerror=function() {
timer = setTimeout(() => showImage(++idx), imageTime);
}
newImg.src = imgsrc
}
@ -225,4 +238,6 @@
}
return stopProp;
});
var btnChecker = setInterval(checkAndSetSlideshowButton, 500);
})();