here2share

chrome: pinterest-auto-downloader

Jan 20th, 2026
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ##### content.js
  2.  
  3. function getLargestImageURL(img) {
  4.     const srcset = img.getAttribute("srcset");
  5.     if (!srcset) return img.src;
  6.  
  7.     const parts = srcset.split(",").map(s => s.trim());
  8.     const last = parts[parts.length - 1];
  9.     return last.split(" ")[0];
  10. }
  11.  
  12. function addDownloadButtons() {
  13.     const images = document.querySelectorAll("img");
  14.  
  15.     images.forEach((img) => {
  16.         const pin = img.closest("[data-test-id='pin']");
  17.         if (!pin) return;
  18.  
  19.         const footer = pin.querySelector("[data-test-id='pinrep-footer']");
  20.         if (!footer) return;
  21.  
  22.         if (footer.querySelector(".download-btn")) return;
  23.  
  24.         const imageURL = getLargestImageURL(img);
  25.         if (!imageURL) return;
  26.  
  27.         const button = document.createElement("button");
  28.         button.innerText = "Download";
  29.         button.className = "download-btn";
  30.  
  31.         button.style.position = "absolute";
  32.         button.style.left = "5px";
  33.         button.style.top = "50%";
  34.         button.style.transform = "translateY(-50%)";
  35.         button.style.zIndex = "9999";
  36.  
  37.         button.onclick = (e) => {
  38.             e.stopPropagation();
  39.             chrome.runtime.sendMessage({
  40.                 action: "download",
  41.                 url: imageURL
  42.             });
  43.         };
  44.  
  45.         footer.style.position = "relative";
  46.         footer.appendChild(button);
  47.     });
  48. }
  49.  
  50. const observer = new MutationObserver(addDownloadButtons);
  51. observer.observe(document.body, { childList: true, subtree: true });
  52.  
  53. addDownloadButtons();
  54.  
  55. ##### background.js
  56.  
  57. chrome.runtime.onMessage.addListener((message) => {
  58.     if (message.action === "download" && message.url) {
  59.         chrome.downloads.download({
  60.             url: message.url,
  61.             filename: "pinterest_" + Date.now() + ".jpg"
  62.         });
  63.     }
  64. });
  65.  
  66. ##### manifest.json
  67.  
  68. {
  69.   "manifest_version": 3,
  70.   "name": "Pinterest Auto Downloader",
  71.   "version": "1.0.0",
  72.   "description": "Automatically download images from Pinterest",
  73.   "permissions": [
  74.     "downloads",
  75.     "activeTab",
  76.     "scripting"
  77.   ],
  78.   "host_permissions": [
  79.     "*://*.pinterest.com/*",
  80.     "*://*.pinimg.com/*"
  81.   ],
  82.   "background": {
  83.     "service_worker": "background.js"
  84.   },
  85.   "content_scripts": [
  86.     {
  87.       "matches": ["*://*.pinterest.com/*"],
  88.       "js": ["content.js"],
  89.       "run_at": "document_idle"
  90.     }
  91.   ]
  92. }
  93.  
Advertisement
Add Comment
Please, Sign In to add comment