// ==UserScript== // @name Majorgeeks gallery view // @namespace Violentmonkey Scripts // @match *://www.majorgeeks.com/* // @grant unsafeWindow // @grant GM_addStyle // @grant GM_openInTab // @grant GM_download // @grant GM_info // @grant GM_notification' // @grant GM_xmlhttpRequest // @grant GM_setValue // @grant GM_getValue // @license MIT // @connect self // @run-at document-idle // @inject-into document-auto // @icon https://www.google.com/s2/favicons?sz=64&domain=www.majorgeeks.com // @resource Icon https://www.google.com/s2/favicons?sz=64&domain=www.majorgeeks.com // @noframes false // @version 1.0.1 // @author Wizzergod // @description Replace arrow images with actual thumbnails from the linked pages, and render in grid gallery links view // @downloadURL none // ==/UserScript== (function() { 'use strict'; // Add custom styles for the images and layout GM_addStyle(` .geekytitle img.replacement { width: 190px; height: 190px; margin: 5px; transition: background 1.3s, transform 0.4s, box-shadow 0.3s; box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.5); cursor: pointer; z-index: 10000; border-radius: 6px; } .geekytitle img.replacement:hover { transform: scale(2.2); box-shadow: 0px 0px 20px rgba(0, 0, 0, 0.7); width: scale(2.2); height: scale(2.2); position: absolute; z-index: 100000; } .geekyinsidecontent { display: none; } .mainpage .geekycontent, .altmainpage .geekycontent { display: flex; flex-direction: row; flex-wrap: wrap; align-content: stretch; justify-content: space-evenly; align-items: stretch; } .geekytitle-container { display: flex; flex-direction: row; flex-wrap: wrap; align-content: stretch; justify-content: space-evenly; align-items: stretch; } .geekytitle { flex: 1 1 200px; /* Flex-grow, flex-shrink, flex-basis */ box-sizing: border-box; margin: 0px; padding: 0px; border: 0px solid #ccc; background-color: #f9f9f9; } `); // Function to fetch the image URL from the detail page function fetchImageUrl(detailPageUrl, callback) { GM_xmlhttpRequest({ method: 'GET', url: detailPageUrl, onload: function(response) { const parser = new DOMParser(); const doc = parser.parseFromString(response.responseText, 'text/html'); const galleryDiv = doc.querySelector('div#gallery'); if (galleryDiv) { const img = galleryDiv.querySelector('img'); if (img) { const imgUrl = img.src.replace(/&/g, '&'); callback(imgUrl); } else { callback(null); } } else { callback(null); } } }); } // Function to process geeky titles function processGeekyTitles() { const geekyTitles = document.querySelectorAll('.geekytitle'); let pendingRequests = 0; geekyTitles.forEach((geekyTitle) => { const link = geekyTitle.querySelector('a[href^="files/details/"]'); if (link) { const detailPageUrl = link.href; pendingRequests++; // Fetch the image URL from the detail page fetchImageUrl(detailPageUrl, (imgUrl) => { if (imgUrl) { const img = geekyTitle.querySelector('img'); if (img) { img.src = imgUrl; img.classList.add('replacement'); // Change the data-src attribute on hover img.dataset.srcHover = imgUrl.replace('action=thumb', 'action=file'); // Add event listener for hover effect img.addEventListener('mouseenter', function() { this.src = this.dataset.srcHover; }); img.addEventListener('mouseleave', function() { this.src = imgUrl; }); // Remove all children of geekyTitle while (geekyTitle.firstChild) { geekyTitle.removeChild(geekyTitle.firstChild); } // Append the new structure const newLink = document.createElement('a'); newLink.href = detailPageUrl; newLink.appendChild(img); geekyTitle.appendChild(newLink); // Append the original text content back to the geekyTitle const originalText = link.textContent; const textNode = document.createTextNode(originalText); geekyTitle.appendChild(textNode); } } pendingRequests--; // If all requests are done, check if we need to reprocess if (pendingRequests === 0) { setTimeout(() => { const remainingTitles = Array.from(geekyTitles).filter(title => title.querySelector('img').src.includes('arrowd.gif')); if (remainingTitles.length > 0) { processGeekyTitles(); } }, 300); // Wait a bit before retrying } }); } }); } // Initial processing of geeky titles processGeekyTitles(); })();