// ==UserScript== // @name Amazon Keyword Modifier with Frequency Analysis // @namespace http://tampermonkey.net/ // @version 2.0 // @description Add "+" to selected high-frequency keywords on Amazon pages // @author Your Name // @match https://www.amazon.com/* // @grant GM_setClipboard // @downloadURL none // ==/UserScript== (function () { 'use strict'; // List of words to exclude const excludedWords = [ "and", "or", "not", "but", "nor", "so", "yet", "for", "in", "on", "at", "by", "to", "of", "with", "about", "as", "from", "into", "over", "under", "after", "before", "around", "through", "between", "sets", "set", "pack", "pcs", "dozen", "pair", "unit", "kg", "g", "lb", "oz", "cm", "mm", "m", "km", "in", "ft", "ml", "l", "box", "bottle", "jar", "can", "tray" ]; const excludedSymbols = /^[!@#$%^&*(),.?":{}|<>+=/\\~`;'\[\]-]+$/; // Create a floating button const button = document.createElement("div"); button.textContent = "+"; button.style.position = "fixed"; button.style.bottom = "20px"; button.style.left = "20px"; button.style.width = "50px"; button.style.height = "50px"; button.style.borderRadius = "50%"; button.style.backgroundColor = "#007bff"; button.style.color = "white"; button.style.fontSize = "24px"; button.style.textAlign = "center"; button.style.lineHeight = "50px"; button.style.cursor = "pointer"; button.style.boxShadow = "0 4px 8px rgba(0, 0, 0, 0.2)"; document.body.appendChild(button); // Create a popup const popup = document.createElement("div"); popup.style.position = "fixed"; popup.style.bottom = "80px"; popup.style.left = "20px"; popup.style.width = "400px"; popup.style.padding = "20px"; popup.style.backgroundColor = "white"; popup.style.border = "1px solid #ccc"; popup.style.boxShadow = "0 4px 8px rgba(0, 0, 0, 0.2)"; popup.style.display = "none"; popup.style.zIndex = "1000"; document.body.appendChild(popup); // Add input box for keywords const input = document.createElement("textarea"); input.style.width = "100%"; input.style.height = "80px"; input.placeholder = "Enter keywords here (one per line)..."; popup.appendChild(input); // Create a container for word frequency const frequencyContainer = document.createElement("div"); frequencyContainer.style.marginTop = "10px"; frequencyContainer.style.borderTop = "1px solid #ccc"; frequencyContainer.style.paddingTop = "10px"; popup.appendChild(frequencyContainer); // Add buttons const generateButton = document.createElement("button"); generateButton.textContent = "Generate +"; generateButton.style.marginTop = "10px"; generateButton.style.marginRight = "10px"; popup.appendChild(generateButton); const copyButton = document.createElement("button"); copyButton.textContent = "Copy"; copyButton.style.marginTop = "10px"; popup.appendChild(copyButton); const output = document.createElement("textarea"); output.style.width = "100%"; output.style.height = "80px"; output.style.marginTop = "10px"; output.style.backgroundColor = "#f9f9f9"; output.style.border = "1px solid #ccc"; output.readOnly = true; popup.appendChild(output); // Show popup on button click button.addEventListener("click", () => { popup.style.display = popup.style.display === "none" ? "block" : "none"; }); // Analyze word frequency const analyzeFrequency = () => { frequencyContainer.innerHTML = ""; // Clear previous analysis const lines = input.value.split(/\n/).filter(line => line.trim() !== ""); // Split lines and remove empty ones const words = lines.flatMap(line => line.trim().split(/\s+/)); // Split words const wordCounts = {}; // Count word occurrences words.forEach(word => { if ( !excludedWords.includes(word.toLowerCase()) && !excludedSymbols.test(word) ) { wordCounts[word] = (wordCounts[word] || 0) + 1; } }); // Display frequency with checkboxes Object.entries(wordCounts) .sort((a, b) => b[1] - a[1]) // Sort by frequency .forEach(([word, count]) => { const label = document.createElement("label"); const checkbox = document.createElement("input"); checkbox.type = "checkbox"; checkbox.value = word; label.appendChild(checkbox); label.appendChild(document.createTextNode(` ${word} (${count})`)); frequencyContainer.appendChild(label); frequencyContainer.appendChild(document.createElement("br")); }); }; // Generate "+" keywords generateButton.addEventListener("click", () => { const checkedWords = Array.from( frequencyContainer.querySelectorAll("input:checked") ).map(checkbox => checkbox.value); const lines = input.value.split(/\n/).filter(line => line.trim() !== ""); const processedLines = lines.map(line => { const words = line.trim().split(/\s+/); const processedWords = words.map(word => { if (checkedWords.includes(word)) { return `+${word}`; } else { return word; } }); return processedWords.join(" "); }); output.value = processedLines.join("\n"); output.style.height = "auto"; output.style.height = `${output.scrollHeight}px`; }); // Copy to clipboard copyButton.addEventListener("click", () => { if (output.value.trim() !== "") { GM_setClipboard(output.value); alert("Copied to clipboard!"); } else { alert("No content to copy!"); } }); // Update word frequency on input change input.addEventListener("input", analyzeFrequency); })();