userscripts/old-reddit-expando.user.js

47 lines
1.5 KiB
JavaScript
Raw Permalink Normal View History

2024-09-20 15:16:24 -05:00
// ==UserScript==
// @name Old Reddit Image Expander
// @namespace danielrayjones
// @description Allow removal of visited links on Amazon Giveaway Listing
// @include https://old.reddit.com*
// @version 1.0.3
2024-09-20 15:16:24 -05:00
// ==/UserScript==
(function() {
const listing = document.getElementById('siteTable');
if (!listing) {
return;
}
let para = document.createElement('p');
let exButton = document.createElement('button');
exButton.innerText = 'Expand';
2024-09-20 15:16:24 -05:00
exButton = para.appendChild(exButton);
2024-09-20 16:00:18 -05:00
exButton.addEventListener('click', () => document.querySelectorAll('.expando-button.collapsed').forEach(e => e.click()));
2024-09-20 15:16:24 -05:00
let deButton = document.createElement('button');
deButton.innerText = 'Collapse';
2024-09-20 15:16:24 -05:00
deButton = para.appendChild(deButton);
2024-09-20 16:00:18 -05:00
deButton.addEventListener('click', () => document.querySelectorAll('.expando-button.expanded').forEach(e => e.click()));
2024-09-20 15:16:24 -05:00
para = listing.insertBefore(para, listing.firstChild);
2024-09-20 16:00:18 -05:00
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();
2024-09-20 15:16:24 -05:00
2024-09-20 16:00:18 -05:00
thing.querySelector('.expando-button')?.click();
return false;
};
listing.querySelectorAll('.thumbnail').forEach(e => e.addEventListener('click', proxyThumbClicks));
2024-09-20 16:00:18 -05:00
})();