Fix DDG Slideshow
This commit is contained in:
parent
7e045e8759
commit
7371b0fd03
@ -1,8 +1,8 @@
|
|||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name DuckDuckGo Images Slideshow
|
// @name DuckDuckGo Images Slideshow
|
||||||
// @namespace https://bullercodeworks.com
|
// @namespace https://bullercodeworks.com
|
||||||
// @version 0.3
|
// @version 1.0.0
|
||||||
// @description Takes a DuckDuckGo Images page and turns it into a slideshow.
|
// @description Takes a DuckDuckGo Images page and adds a button to run through all of the pictures as a slideshow.
|
||||||
// @author brian@bullercodeworks.com
|
// @author brian@bullercodeworks.com
|
||||||
// @match https://duckduckgo.com/*
|
// @match https://duckduckgo.com/*
|
||||||
// @grant none
|
// @grant none
|
||||||
@ -34,22 +34,33 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
var addSlideshowButton = function() {
|
var addSlideshowButton = function() {
|
||||||
if(document.getElementById('slideshow_button') == null) {
|
if(document.getElementById('slideshow-button') == null) {
|
||||||
var slideshowLi = document.createElement('li');
|
var ssBtnDiv = document.createElement('div');
|
||||||
var slideshowA = document.createElement('a');
|
var ssBtnA = document.createElement('a');
|
||||||
slideshowLi.id = "slideshow_button";
|
ssBtnDiv.id = 'slideshow-button';
|
||||||
slideshowLi.classList.add('zcm__item');
|
ssBtnDiv.classList.add('dropdown');
|
||||||
slideshowA.classList.add('zcm__link');
|
ssBtnA.innerText='Slideshow';
|
||||||
slideshowA.classList.add('js-zci-link');
|
ssBtnA.href='#';
|
||||||
slideshowA.innerText="Slideshow";
|
ssBtnDiv.appendChild(ssBtnA);
|
||||||
slideshowA.href='#';
|
ssBtnA.onclick = init;
|
||||||
slideshowLi.appendChild(slideshowA);
|
document.querySelector('.metabar__dropdowns').appendChild(ssBtnDiv);
|
||||||
slideshowA.onclick = init;
|
}
|
||||||
document.getElementById('duckbar_static').appendChild(slideshowLi);
|
}
|
||||||
|
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 currimg=0;
|
||||||
var allimages = document.querySelectorAll('img.tile--img__img');
|
var allimages = document.querySelectorAll('img.tile--img__img');
|
||||||
var timer;
|
var timer;
|
||||||
@ -63,11 +74,6 @@
|
|||||||
var lastScroll = 0;
|
var lastScroll = 0;
|
||||||
var cacheimg = document.createElement('img');
|
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() {
|
function updateImages() {
|
||||||
var testimages = document.querySelectorAll('img.tile--img__img');
|
var testimages = document.querySelectorAll('img.tile--img__img');
|
||||||
var testcount = testimages.length;
|
var testcount = testimages.length;
|
||||||
@ -120,6 +126,10 @@
|
|||||||
}
|
}
|
||||||
function loadOrigImg(idx) {
|
function loadOrigImg(idx) {
|
||||||
var detailPanes = document.querySelectorAll('.detail__pane');
|
var detailPanes = document.querySelectorAll('.detail__pane');
|
||||||
|
if(detailPanes.length == 0) {
|
||||||
|
console.log('No detail panes');
|
||||||
|
return;
|
||||||
|
}
|
||||||
var detailPane = detailPanes[1];
|
var detailPane = detailPanes[1];
|
||||||
if(detailPanes.length == 2) detailPane = detailPanes[0];
|
if(detailPanes.length == 2) detailPane = detailPanes[0];
|
||||||
var imgsrc = detailPane.querySelector('img.detail__media__img-highres').src;
|
var imgsrc = detailPane.querySelector('img.detail__media__img-highres').src;
|
||||||
@ -128,6 +138,9 @@
|
|||||||
lbimg.src = this.src;
|
lbimg.src = this.src;
|
||||||
timer = setTimeout(() => showImage(++idx), imageTime);
|
timer = setTimeout(() => showImage(++idx), imageTime);
|
||||||
}
|
}
|
||||||
|
newImg.onerror=function() {
|
||||||
|
timer = setTimeout(() => showImage(++idx), imageTime);
|
||||||
|
}
|
||||||
newImg.src = imgsrc
|
newImg.src = imgsrc
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,4 +238,6 @@
|
|||||||
}
|
}
|
||||||
return stopProp;
|
return stopProp;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var btnChecker = setInterval(checkAndSetSlideshowButton, 500);
|
||||||
})();
|
})();
|
Loading…
Reference in New Issue
Block a user