Update whapedia-image-redirect.user.js
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name Wahapedia Image Search Redirect
|
// @name Wahapedia Enhanced Search
|
||||||
// @namespace http://tampermonkey.net/
|
// @namespace http://tampermonkey.net/
|
||||||
// @version 2025-01-10
|
// @version 2025-01-23
|
||||||
// @description Replaces Google image search with Kagi image search on Wahapedia
|
// @description Enhances Wahapedia with Kagi image search and Warhammer.com search
|
||||||
// @author luxick
|
// @author luxick
|
||||||
// @updateURL https://github.com/luxick/scripts/raw/master/whapedia-image-redirect.user.js
|
// @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
|
// @downloadURL https://github.com/luxick/scripts/raw/master/whapedia-image-redirect.user.js
|
||||||
@@ -27,11 +27,54 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run when page loads
|
// Function to create a Warhammer.com search button
|
||||||
replaceImageSearchUrls();
|
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, {
|
observer.observe(document.body, {
|
||||||
childList: true,
|
childList: true,
|
||||||
subtree: true
|
subtree: true
|
||||||
|
|||||||
Reference in New Issue
Block a user