Skip to content

Instantly share code, notes, and snippets.

@ruwwww
Created July 4, 2025 06:41
Show Gist options
  • Select an option

  • Save ruwwww/c440e67cd5a02b2ae6733e7f255a66cf to your computer and use it in GitHub Desktop.

Select an option

Save ruwwww/c440e67cd5a02b2ae6733e7f255a66cf to your computer and use it in GitHub Desktop.
copy pinterest url from list (grid) item
// ==UserScript==
// @name Pinterest Image Scraper with Buttons
// @namespace http://tampermonkey.net/
// @version 2.1
// @description Adds buttons to the top-right above parent elements with data-grid-item="true" and role="listitem" containing images with elementtiming="grid-non-story-pin-image-related_pins" or "grid-non-story-pin-image-homefeed" to scrape and upscale their image URLs to 736x resolution and copy to clipboard
// @author Grok
// @match https://*.pinterest.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
function scrapeHighResUrl(img) {
if (!img || !img.src) return null;
return img.src.replace(/236x/, '736x');
}
function createCopyButton(img) {
const button = document.createElement('button');
button.textContent = '📋';
Object.assign(button.style, {
position: 'absolute',
bottom: '0px',
right: '50px',
zIndex: '9999',
background: 'rgba(0,0,0,0.6)',
color: 'white',
border: 'none',
borderRadius: '4px',
padding: '2px 6px',
fontSize: '16px',
cursor: 'pointer',
pointerEvents: 'auto'
});
button.addEventListener('click', (e) => {
e.stopPropagation();
e.preventDefault();
const highResUrl = scrapeHighResUrl(img);
if (!highResUrl) return;
navigator.clipboard.writeText(highResUrl).then(() => {
const originalText = button.textContent;
button.textContent = '✅';
button.disabled = true;
setTimeout(() => {
button.textContent = originalText;
button.disabled = false;
}, 1000);
});
});
return button;
}
function injectButtons() {
document.querySelectorAll('img[elementtiming="grid-non-story-pin-image-homefeed"], img[elementtiming="grid-non-story-pin-image-related_pins"]').forEach(img => {
const parent = img.closest('[data-grid-item], [role="listitem"], div[data-test-id="pin"]') || img.parentElement;
if (!parent || parent.dataset.scraped) return;
parent.dataset.scraped = 'true';
// Make sure parent is position relative
const style = window.getComputedStyle(parent);
if (style.position === 'static') {
parent.style.position = 'relative';
}
// Add button
const btn = createCopyButton(img);
parent.appendChild(btn);
});
}
// Initial run
window.addEventListener('load', injectButtons);
// Observe dynamically loaded content
const observer = new MutationObserver(injectButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment