✨ Add button to make thumb clickable
This commit is contained in:
parent
5db7867f46
commit
e61fdbdbd3
1 changed files with 24 additions and 8 deletions
|
|
@ -3,7 +3,7 @@
|
||||||
// @namespace danielrayjones
|
// @namespace danielrayjones
|
||||||
// @description Allow removal of visited links on Amazon Giveaway Listing
|
// @description Allow removal of visited links on Amazon Giveaway Listing
|
||||||
// @include https://old.reddit.com*
|
// @include https://old.reddit.com*
|
||||||
// @version 1.0.0
|
// @version 1.0.2
|
||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
@ -14,20 +14,36 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
let para = document.createElement('p');
|
let para = document.createElement('p');
|
||||||
//para.innerHtml = '<button id="expander">Expand images</button><button id="depand">Collapse images</button>';
|
|
||||||
let exButton = document.createElement('button');
|
let exButton = document.createElement('button');
|
||||||
exButton.id = 'expander';
|
|
||||||
exButton.innerText = 'Expand images';
|
exButton.innerText = 'Expand images';
|
||||||
exButton = para.appendChild(exButton);
|
exButton = para.appendChild(exButton);
|
||||||
|
exButton.addEventListener('click', () => document.querySelectorAll('.expando-button.collapsed').forEach(e => e.click()));
|
||||||
|
|
||||||
let deButton = document.createElement('button');
|
let deButton = document.createElement('button');
|
||||||
deButton.id = 'depand';
|
|
||||||
deButton.innerText = 'Collapse images';
|
deButton.innerText = 'Collapse images';
|
||||||
deButton = para.appendChild(deButton);
|
deButton = para.appendChild(deButton);
|
||||||
|
deButton.addEventListener('click', () => document.querySelectorAll('.expando-button.expanded').forEach(e => e.click()));
|
||||||
|
|
||||||
|
const proxyThumbClicks = function(evt) {
|
||||||
|
let thing = evt.target;
|
||||||
|
while (!thing.classList.contains('thing') && thing != document.body) {
|
||||||
|
thing = thing.parentElement;
|
||||||
|
}
|
||||||
|
if (!thing.classList.contains('thing')) {
|
||||||
|
console.log("Couldn't find thing");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
evt.preventDefault();
|
||||||
|
|
||||||
|
thing.querySelector('.expando-button')?.click();
|
||||||
|
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
let icoButton = document.createElement('button');
|
||||||
|
icoButton.innerText = 'Thumb expands';
|
||||||
|
icoButton = para.appendChild(icoButton);
|
||||||
|
icoButton.addEventListener('click', () => listing.querySelectorAll('.thumbnail').forEach(e => e.addEventListener('click', proxyThumbClicks)));
|
||||||
|
|
||||||
para = listing.insertBefore(para, listing.firstChild);
|
para = listing.insertBefore(para, listing.firstChild);
|
||||||
|
|
||||||
exButton.addEventListener('click', () => document.querySelectorAll('.expando-button.collapsed').forEach(e => e.click()));
|
|
||||||
deButton.addEventListener('click', () => document.querySelectorAll('.expando-button.expanded').forEach(e => e.click()));
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue