Skip to content

Instantly share code, notes, and snippets.

@mkxto
Created January 28, 2025 20:02
Show Gist options
  • Save mkxto/251f067c4f1eea38a081399ec8d4a1d4 to your computer and use it in GitHub Desktop.
Save mkxto/251f067c4f1eea38a081399ec8d4a1d4 to your computer and use it in GitHub Desktop.
DeepSeek generated Tamper monkey script to grab OfferID from an Amazon EU product with a button + notifications
// ==UserScript==
// @name Amazon OfferID Grabber
// @namespace http://tampermonkey.net/
// @version 0.3
// @description Copies Amazon product offer ID from input field with id "offerListingId" to clipboard
// @author Your Name
// @match https://www.amazon.de/*
// @match https://www.amazon.fr/*
// @match https://www.amazon.co.uk/*
// @match https://www.amazon.it/*
// @match https://www.amazon.es/*
// @icon https://www.amazon.com/favicon.ico
// @grant GM_setClipboard
// @grant GM_notification
// ==/UserScript==
(function() {
'use strict';
function getOfferId() {
const offerInput = document.getElementById('offerListingID');
console.log(offerInput);
if (offerInput && offerInput.type === 'hidden') {
return offerInput.value;
}
return null;
}
function createButton() {
const btn = document.createElement('button');
btn.innerHTML = 'Copy Offer ID';
btn.id = 'offerIdBtn'; // Add an ID to the button
btn.style.cssText = `
padding: 8px 16px;
background: #ff9900;
color: white;
border: none;
border-radius: 3px;
cursor: pointer;
margin-bottom: 10px;
font-family: 'Amazon Ember', Arial, sans-serif;
font-size: 14px;
`;
btn.addEventListener('click', () => {
const offerId = getOfferId();
if (offerId) {
GM_setClipboard(offerId, 'text');
showNotification('✅ Offer ID copied to clipboard!', 2000);
} else {
showNotification('❌ Offer ID not found!', 3000);
btn.style.background = '#cc0000';
setTimeout(() => btn.style.background = '#ff9900', 500);
}
});
return btn;
}
function showNotification(message, duration) {
const notification = document.createElement('div');
notification.textContent = message;
notification.style.cssText = `
position: fixed;
top: 20px;
right: 20px;
padding: 12px 20px;
background: #333;
color: white;
border-radius: 4px;
z-index: 9999;
font-family: 'Amazon Ember', Arial, sans-serif;
box-shadow: 0 2px 5px rgba(0,0,0,0.2);
`;
document.body.appendChild(notification);
setTimeout(() => notification.remove(), duration);
}
function insertButton() {
const productTitle = document.getElementById('productTitle');
if (productTitle && !document.getElementById('offerIdBtn')) {
const container = document.createElement('div');
container.style.marginBottom = '15px';
container.appendChild(createButton());
productTitle.parentNode.insertBefore(container, productTitle);
}
}
const observer = new MutationObserver(() => {
insertButton();
});
observer.observe(document, {
childList: true,
subtree: true
});
// Initial check in case the page is already loaded
insertButton();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment