Made a mistake on the previous script so don`t use it lol
I made a better version anyway, Its still one by one but way quicker, drop LaunchBox BoxArt Name Grabber.exe into a Platform and run it, it searches for all boxart ending in -01 and adds them to a list within a GUI, clicking a line in the list will save it to the clipboard and delete the line from the GUI, then using this new script right click in the search box on Search video games, characters, developers (igdb.com) it will paste and search automatically, make sure to select a platform for better results, then right click a image to match a game and it will rename it using the last pasted text.
New Script for Tampermonkey
// ==UserScript==
// @name IGDB Right Click 4k Boxart Downloader
// @namespace http://tampermonkey.net/
// @version 2024-06-05
// @description Right-click on an image to automatically download 4k boxart from IGDB.com and paste text in input fields
// @author Clean Boxart
// @match *://*.igdb.com/*
// @grant none
// ==/UserScript==
(async function() {
'use strict';
// Function to get text from clipboard
async function getClipboardText() {
try {
const text = await navigator.clipboard.readText();
return text.trim();
} catch (err) {
console.error('Failed to read clipboard contents: ', err);
return '';
}
}
// Function to simulate key press
function simulateEnterKey(target) {
let keyboardEvent = new KeyboardEvent('keydown', {
bubbles: true,
cancelable: true,
key: 'Enter',
code: 'Enter',
keyCode: 13,
which: 13
});
target.dispatchEvent(keyboardEvent);
keyboardEvent = new KeyboardEvent('keypress', {
bubbles: true,
cancelable: true,
key: 'Enter',
code: 'Enter',
keyCode: 13,
which: 13
});
target.dispatchEvent(keyboardEvent);
keyboardEvent = new KeyboardEvent('keyup', {
bubbles: true,
cancelable: true,
key: 'Enter',
code: 'Enter',
keyCode: 13,
which: 13
});
target.dispatchEvent(keyboardEvent);
}
// Event listener for context menu
document.addEventListener('contextmenu', async function(event) {
let target = event.target;
// Handle image right-click
if (target.tagName === 'IMG') {
event.preventDefault();
let imageUrl = target.src;
// Determine the image name
let imageName = await getClipboardText();
// If no clipboard text, find the nearest link element text
if (!imageName) {
let parentElement = target.closest('.media');
let linkElement = parentElement ? parentElement.querySelector('a') : null;
if (!linkElement) {
console.log("No nearby link found for the image.");
return;
}
imageName = linkElement.innerText.trim();
if (!imageName) {
console.log("No text found in the nearby link.");
return;
}
}
// Edit URL to always download the largest boxart size
const sizeVariants = ['_cover_big_2x', '_cover_big', '_cover_med', '_cover_small', '_720p', '_1080p'];
sizeVariants.forEach(variant => {
if (imageUrl.includes(variant)) {
imageUrl = imageUrl.replace(variant, '_4k');
}
});
console.log("Modified URL: " + imageUrl);
// Fetch the image data
let response = await fetch(imageUrl);
if (!response.ok) {
console.log("Failed to fetch the image.");
return;
}
let blob = await response.blob();
let blobUrl = window.URL.createObjectURL(blob);
// Create a hidden link element to trigger the download
let link = document.createElement('a');
link.href = blobUrl;
link.download = imageName + '.jpg'; // Use the clipboard text or the nearest link text to name the file
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
window.URL.revokeObjectURL(blobUrl);
// Handle input or textarea right-click
} else if (target.tagName === 'INPUT' || target.tagName === 'TEXTAREA') {
event.preventDefault();
let clipboardText = await getClipboardText();
if (clipboardText) {
// Clear the text field before pasting the data
target.value = '';
let clearEvent = new Event('input', { bubbles: true });
target.dispatchEvent(clearEvent);
// Set the clipboard text
target.value = clipboardText;
console.log("Auto-pasted text: " + clipboardText);
// Simulate input event to trigger any change listeners
let inputEvent = new Event('input', { bubbles: true });
target.dispatchEvent(inputEvent);
// Simulate pressing Enter key
setTimeout(() => simulateEnterKey(target), 100); // Add a slight delay to ensure paste is completed
}
}
}, true);
})();
IGDB 4k boxart & rename.mp4
LaunchBox boxart name grabber.exe