From 0cf4c9bd519cde362fc9f43da4985d1b52a2310f Mon Sep 17 00:00:00 2001 From: luxick Date: Thu, 23 Jan 2025 08:55:18 +0100 Subject: [PATCH] Update whapedia-image-redirect.user.js --- whapedia-image-redirect.user.js | 57 +++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 7 deletions(-) diff --git a/whapedia-image-redirect.user.js b/whapedia-image-redirect.user.js index f08133f..4416c45 100644 --- a/whapedia-image-redirect.user.js +++ b/whapedia-image-redirect.user.js @@ -1,8 +1,8 @@ // ==UserScript== -// @name Wahapedia Image Search Redirect +// @name Wahapedia Enhanced Search // @namespace http://tampermonkey.net/ -// @version 2025-01-10 -// @description Replaces Google image search with Kagi image search on Wahapedia +// @version 2025-01-23 +// @description Enhances Wahapedia with Kagi image search and Warhammer.com search // @author luxick // @updateURL https://github.com/luxick/scripts/raw/master/whapedia-image-redirect.user.js // @downloadURL https://github.com/luxick/scripts/raw/master/whapedia-image-redirect.user.js @@ -27,11 +27,54 @@ } } - // Run when page loads - replaceImageSearchUrls(); + // Function to create a Warhammer.com search button + function createButton(modelName) { + const warhammerButton = document.createElement('a'); + warhammerButton.href = `https://www.warhammer.com/de-DE/plp?search=${encodeURIComponent(modelName)}`; + warhammerButton.className = 'dsButton'; + warhammerButton.target = '_blank'; + + const buttonDiv = document.createElement('div'); + buttonDiv.className = 'tooltip picSearch'; + + warhammerButton.appendChild(buttonDiv); + warhammerButton.style.marginLeft = '5px'; + warhammerButton.style.display = 'inline-block'; + + return warhammerButton; + } + + // Function to add Warhammer.com search buttons + function addWarhammerSearchButtons() { + // Get the model name from the dsH2Header div + const headerContainer = document.querySelector('.dsH2Header'); + if (!headerContainer) return; + + const modelName = headerContainer.firstElementChild.textContent.trim(); + if (!modelName) return; + + // Add button to narrow container + const narrowContainer = document.querySelector('.dsIconsNarrow'); + if (narrowContainer) { + narrowContainer.appendChild(createButton(modelName)); + } + + // Add button to wide container + const wideContainer = document.querySelector('.dsIconsWide'); + if (wideContainer) { + wideContainer.appendChild(createButton(modelName)); + } + } + + // Initial run of both functions + replaceImageSearchUrls(); + addWarhammerSearchButtons(); + + // Set up observer for dynamically loaded content + const observer = new MutationObserver(() => { + replaceImageSearchUrls(); + }); - // Run again if content is dynamically loaded - const observer = new MutationObserver(replaceImageSearchUrls); observer.observe(document.body, { childList: true, subtree: true