Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Initial Price Tracker (indiscriminate)
- // @namespace http://tampermonkey.net/
- // @version 1.0
- // @description Extracts Title, Price, and Link for spreadsheet analysis
- // @author Gemini
- // @match https://duckduckgo.com/*
- // @grant GM_setClipboard
- // ==/UserScript==
- (function() {
- 'use strict';
- // 1. Create the UI Button
- const btn = document.createElement("button");
- btn.innerHTML = "📊 Copy Market Data";
- btn.style = `
- position: fixed; top: 100px; right: 20px; z-index: 99999;
- padding: 12px 20px; background-color: #de5833; color: white;
- border: none; border-radius: 8px; font-weight: bold;
- cursor: pointer; box-shadow: 0 4px 6px rgba(0,0,0,0.2);
- `;
- document.body.appendChild(btn);
- btn.onclick = function() {
- let count = 0;
- let output = "Title\tPrice\tLink\n"; // Tab-separated header
- // 2. Select all list items
- const listItems = document.querySelectorAll('li');
- listItems.forEach(li => {
- // Find the anchor that has a title (The main product link)
- const anchor = li.querySelector('a[title]');
- // Find the price (Look for a span containing $)
- const spans = Array.from(li.querySelectorAll('span'));
- const priceSpan = spans.find(s => s.textContent.includes('$'));
- // 3. Validation Logic: Ensure it's a real listing
- if (anchor && priceSpan) {
- const title = anchor.getAttribute('title').trim();
- const link = anchor.href;
- // Clean the price: Remove $, commas, and extra text (e.g., "$2,500.00 Free Shipping" -> "2500.00")
- const rawPrice = priceSpan.textContent;
- const cleanPrice = rawPrice.replace(/[^\d.]/g, '');
- if (title && cleanPrice) {
- output += `${title}\t${cleanPrice}\t${link}\n`;
- count++;
- }
- }
- });
- // 4. Hand-off to Clipboard
- if (count > 0) {
- GM_setClipboard(output);
- btn.innerHTML = `✅ Copied ${count} items!`;
- btn.style.backgroundColor = "#4CAF50";
- // Reset button color after 3 seconds
- setTimeout(() => {
- btn.innerHTML = "📊 Copy Market Data";
- btn.style.backgroundColor = "#de5833";
- }, 3000);
- } else {
- alert("No listings found. Try scrolling down to load more results.");
- }
- };
- })();
Advertisement
Add Comment
Please, Sign In to add comment