diff --git a/content-monetization-helper/README.md b/content-monetization-helper/README.md new file mode 100644 index 0000000..e69de29 diff --git a/content-monetization-helper/content-monetization-helper.js b/content-monetization-helper/content-monetization-helper.js new file mode 100644 index 0000000..4f7ad78 --- /dev/null +++ b/content-monetization-helper/content-monetization-helper.js @@ -0,0 +1,763 @@ +// ==UserScript== +// @name Content Monetization Helper +// @namespace http://tampermonkey.net/ +// @version 1.1 +// @description Analyzes written content, extracts keywords, suggests related topics and structural tips to boost ad revenue or affiliate conversions. +// @author Mitul Patel +// @match *://*/* +// @grant GM_registerMenuCommand +// @grant GM_xmlhttpRequest +// @grant GM_addStyle +// @connect api.datamuse.com +// ==/UserScript== + +(function () { + ("use strict"); + + // Configuration options + const CONFIG = { + maxKeywords: 15, + maxRelatedTopics: 5, + minContentLength: 100 + }; + + // Expanded list of stopwords for keyword extraction + const STOPWORDS = new Set([ + "the", + "and", + "for", + "with", + "that", + "this", + "from", + "are", + "but", + "not", + "you", + "your", + "have", + "has", + "will", + "more", + "can", + "all", + "our", + "about", + "use", + "using", + "in", + "on", + "at", + "of", + "to", + "a", + "an", + "is", + "it", + "its", + "they", + "them", + "their", + "there", + "here", + "where", + "when", + "how", + "what", + "who", + "which", + "why", + "be", + "been", + "being", + "was", + "were", + "would", + "should", + "could", + "had", + "has", + "have", + "do", + "does", + "did", + "just", + "very", + "too", + "also", + "now", + "then", + "so", + "some", + "such", + "like", + "by", + "my", + "we", + "us", + "or", + "if", + "as", + "than", + "get", + "got", + "i", + ]); + + // Create suggestion panel with improved UI + const panel = document.createElement("div"); + panel.id = "cmh-panel"; + panel.style.position = "fixed"; + panel.style.top = "0"; + panel.style.right = "0"; + panel.style.width = "380px"; + panel.style.height = "100%"; + panel.style.backgroundColor = "#fff"; + panel.style.borderLeft = "1px solid #ccc"; + panel.style.boxShadow = "-2px 0 5px rgba(0,0,0,0.1)"; + panel.style.zIndex = "100000"; + panel.style.padding = "0"; + panel.style.overflowY = "auto"; + panel.style.display = "none"; + panel.style.fontFamily = "Arial, sans-serif"; + panel.style.transition = "transform 0.3s ease-in-out"; + panel.innerHTML = ` +
This tool analyzes your content and provides suggestions to improve its monetization potential.
+It focuses on:
+The tool uses the free Datamuse API to suggest related keywords and topics.
+Please select or focus on a text area with sufficient content (at least " + + CONFIG.minContentLength + + " characters).
"; + }); + return; + } + + try { + // Extract keywords and calculate their monetization potential + const keywordsWithScores = await analyzeKeywords(content); + + // Analyze SEO potential + const seoSuggestions = analyzeSEO(content, keywordsWithScores); + + // Compute structural tips for better monetization + const structureTips = computeStructure(content); + + // Render results in appropriate tabs + document.getElementById("cmh-keywords-content").innerHTML = + renderKeywordsTab(keywordsWithScores); + document.getElementById("cmh-seo-content").innerHTML = + renderSEOTab(seoSuggestions); + document.getElementById("cmh-structure-content").innerHTML = + renderStructureTab(structureTips); + + // Add event listeners for keyword suggestions + document.querySelectorAll(".cmh-keyword-suggestion").forEach((btn) => { + btn.addEventListener("click", function () { + const keyword = this.getAttribute("data-keyword"); + insertTextAtCursor(keyword); + }); + }); + } catch (error) { + console.error("Error analyzing content:", error); + document.getElementById( + "cmh-results" + ).innerHTML = `Error analyzing content: ${ + error.message || "Unknown error" + }
`; + } finally { + document.getElementById("cmh-loading").style.display = "none"; + } + } + + // Insert text at cursor position (for keyword suggestions) + function insertTextAtCursor(text) { + const el = document.activeElement; + if (!el || (el.tagName !== "TEXTAREA" && !el.isContentEditable)) return; + + if (el.tagName === "TEXTAREA") { + const start = el.selectionStart; + const end = el.selectionEnd; + el.value = el.value.substring(0, start) + text + el.value.substring(end); + el.selectionStart = el.selectionEnd = start + text.length; + } else { + // For contentEditable elements + const selection = window.getSelection(); + const range = selection.getRangeAt(0); + range.deleteContents(); + range.insertNode(document.createTextNode(text)); + range.collapse(false); + selection.removeAllRanges(); + selection.addRange(range); + } + } + + // Analyze keywords and calculate monetization potential + async function analyzeKeywords(content) { + // Extract basic keywords + const basicKeywords = extractKeywords(content, CONFIG.maxKeywords); + + // Calculate monetization potential for each keyword + const keywordsWithScores = []; + + for (const keyword of basicKeywords) { + // Get related topics + const related = await fetchRelated(keyword); + + // Calculate monetization score (0-100) + let score = 0; + + // Check if keyword is a product or service + if (/product|service|tool|app|software|course|book|guide/i.test(keyword)) + score += 25; + + // Check if keyword is related to high-value niches + if (/finance|health|wealth|business|marketing|investment/i.test(keyword)) + score += 25; + + // Check if keyword is related to purchase intent + if ( + /buy|purchase|price|cost|review|best|top|vs|versus|comparison/i.test( + keyword + ) + ) + score += 30; + + // Check if keyword is a long-tail keyword (3+ words) + if (keyword.split(/\s+/).length >= 3) score += 20; + + // Cap at 100 + score = Math.min(100, score); + + keywordsWithScores.push({ + keyword, + score, + related: related.slice(0, CONFIG.maxRelatedTopics), + }); + } + + // Sort by score (highest first) + return keywordsWithScores.sort((a, b) => b.score - a.score); + } + + function getEditableContent() { + const el = document.activeElement; + if (el && (el.tagName === "TEXTAREA" || el.isContentEditable)) { + return el.value || el.innerText; + } + return document.body.innerText; + } + + function extractKeywords(text, maxCount) { + // Extract single words + const wordFreq = {}; + text + .toLowerCase() + .replace(/[^a-z0-9\s]/g, " ") + .split(/\s+/) + .forEach((word) => { + if (word.length > 3 && !STOPWORDS.has(word)) { + wordFreq[word] = (wordFreq[word] || 0) + 1; + } + }); + + // Extract phrases (2-3 words) + const phraseFreq = {}; + const words = text + .toLowerCase() + .replace(/[^a-z0-9\s]/g, " ") + .split(/\s+/) + .filter((word) => word.length > 2 && !STOPWORDS.has(word)); + + // Extract 2-word phrases + for (let i = 0; i < words.length - 1; i++) { + const phrase = `${words[i]} ${words[i + 1]}`; + phraseFreq[phrase] = (phraseFreq[phrase] || 0) + 1; + } + + // Extract 3-word phrases + for (let i = 0; i < words.length - 2; i++) { + const phrase = `${words[i]} ${words[i + 1]} ${words[i + 2]}`; + phraseFreq[phrase] = (phraseFreq[phrase] || 0) + 1; + } + + // Combine single words and phrases, prioritizing phrases + const combined = [ + ...Object.entries(phraseFreq) + .sort((a, b) => b[1] - a[1]) + .slice(0, Math.floor(maxCount * 0.6)) + .map(([phrase]) => phrase), + ...Object.entries(wordFreq) + .sort((a, b) => b[1] - a[1]) + .slice(0, Math.floor(maxCount * 0.4)) + .map(([word]) => word), + ]; + + // Remove duplicates and limit to maxCount + return [...new Set(combined)].slice(0, maxCount); + } + + function fetchRelated(word) { + return new Promise((resolve) => { + GM_xmlhttpRequest({ + method: "GET", + url: `https://api.datamuse.com/words?ml=${encodeURIComponent( + word + )}&max=${CONFIG.maxRelatedTopics}`, + onload: (res) => { + try { + const data = JSON.parse(res.responseText); + resolve(data.map((item) => item.word)); + } catch { + resolve([]); + } + }, + onerror: () => resolve([]), + }); + }); + } + + // Analyze SEO potential of content + function analyzeSEO(content, keywordsWithScores) { + const seoSuggestions = { + title: [], + headings: [], + density: [], + structure: [], + }; + + // Check title suggestions + const topKeywords = keywordsWithScores.slice(0, 3).map((k) => k.keyword); + seoSuggestions.title.push(`Include your main keyword "${topKeywords[0]}" at the beginning of your title`); + seoSuggestions.title.push(`Consider using a number in your title (e.g., "7 Ways to...", "5 Best...")`); + seoSuggestions.title.push(`Add emotional words like "amazing", "essential", or "proven" to increase clicks`); + + // Check heading structure + if (!/(#{1,6}\s|These keywords have the highest potential for monetization. Click to insert at cursor position.
+