Created
October 26, 2024 20:55
-
-
Save Steveseo73/26ee434cb8b6c182ef45a26330fa4b4b to your computer and use it in GitHub Desktop.
checks title of webpage in google serps to see if it is the same as in the webpage url
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:(function(){const s=document.createElement('style');s.textContent=`.tc{margin-top:8px;font-size:14px}.tm{color:#0f5132;background:#d1e7dd;padding:2px%206px;border-radius:3px}.tmm{color:#842029;background:#f8d7da;padding:2px%206px;border-radius:3px}.te{color:#664d03;background:#fff3cd;padding:2px%206px;border-radius:3px}`;document.head.appendChild(s);const%20p=['https://corsproxy.io/?','https://api.allorigins.win/raw?url='];let%20c=0;const%20g=()=>Array.from(document.querySelectorAll('div.g:not(.kno-kp%20.g)%20div[data-snf]%20a:has(h3)')).map((l,i)=>({p:i+1,e:l.closest('div.g'),t:l.querySelector('h3').textContent,u:l.href}));const%20f=async%20u=>{const%20x=p[Math.floor(Math.random()*p.length)]+encodeURIComponent(u);const%20r=await%20fetch(x);const%20h=await%20r.text();const%20d=(new%20DOMParser).parseFromString(h,'text/html');return%20d.title.trim()};const%20d=(e,g,a,r=false)=>{const%20v=document.createElement('div');v.className='tc';if(r)v.innerHTML='<span%20class="te">Error%20fetching%20page%20title</span>';else%20if(g===a)v.innerHTML=`<span%20class="tm">%E2%9C%93%20Titles%20match:%20"${g}"</span>`;else{c++;v.innerHTML=`<span%20class="tmm">Google:%20"${g}"<br>Page:%20"${a}"</span>`}e.appendChild(v)};(async()=>{const%20r=g();for(const%20t%20of%20r){try{const%20a=await%20f(t.u);d(t.e,t.t,a)}catch{d(t.e,t.t,'',true)}await%20new%20Promise(r=>setTimeout(r,300))}const%20s=document.getElementById('result-stats');if(s)s.textContent+=`%20-%20${c}%20title${c!==1?'s':''}%20different%20from%20search%20results`})()})(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:(function(){const s=document.createElement('style');s.textContent=`.tc{margin:8px 0;font-size:14px;line-height:1.4}.tm{color:#0f5132;background:#d1e7dd;padding:2px 6px;border-radius:3px;display:block;margin:2px 0}.tmm{color:#842029;background:#f8d7da;padding:2px 6px;border-radius:3px;display:block;margin:2px 0}.te{color:#664d03;background:#fff3cd;padding:2px 6px;border-radius:3px;display:block}.label{font-weight:bold;font-size:12px;color:#666;display:block;margin-top:4px}`;document.head.appendChild(s);const p=['https://corsproxy.io/?','https://api.allorigins.win/raw?url='];let titleChanges=0;let descChanges=0;const getResults=()=>Array.from(document.querySelectorAll('div.g:not(.kno-kp .g) div[data-snf] a:has(h3)')).map((l,i)=>({pos:i+1,element:l.closest('div.g'),title:l.querySelector('h3').textContent,description:l.closest('div.g').querySelector('.VwiC3b')?.textContent||'',url:l.href}));const fetchMetadata=async u=>{const x=p[Math.floor(Math.random()*p.length)]+encodeURIComponent(u);const r=await fetch(x);const h=await r.text();const d=(new DOMParser).parseFromString(h,'text/html');return{title:d.title.trim(),description:d.querySelector('meta[name="description"]')?.content?.trim()||'No meta description found'};};const displayComparison=(e,gTitle,gDesc,aTitle,aDesc,error=false)=>{const v=document.createElement('div');v.className='tc';if(error){v.innerHTML='<span class="te">Error fetching page metadata</span>';}else{let html='';html+=`<span class="label">Title:</span>`;if(gTitle===aTitle){html+=`<span class="tm">✓ Matches: "${gTitle}"</span>`;}else{titleChanges++;html+=`<span class="tmm">Google: "${gTitle}"<br>Page: "${aTitle}"</span>`;}html+=`<span class="label">Description:</span>`;if(gDesc===aDesc){html+=`<span class="tm">✓ Matches: "${gDesc}"</span>`;}else{descChanges++;html+=`<span class="tmm">Google: "${gDesc}"<br>Page: "${aDesc}"</span>`;}v.innerHTML=html;}e.appendChild(v);};(async()=>{const r=getResults();console.log(`Checking ${r.length} results...`);for(const t of r){try{const meta=await fetchMetadata(t.url);displayComparison(t.element,t.title,t.description,meta.title,meta.description);}catch{displayComparison(t.element,t.title,t.description,'','',true);}await new Promise(r=>setTimeout(r,300));}const s=document.getElementById('result-stats');if(s)s.textContent+=` - ${titleChanges} title(s) and ${descChanges} description(s) different from search results`;})()})(); |
The seo metadata checker does both metadescription and title.
I used claude.ai to make it. And got he idea from this original post: https://gist.github.com/fedegomez/7b4601e2cc9491e004189e9a23dd35b1
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
see https://gist.github.com/fedegomez/7b4601e2cc9491e004189e9a23dd35b1 for details on how to use