Skip to content

Instantly share code, notes, and snippets.

@fedegomez
Last active October 26, 2024 20:44
Show Gist options
  • Select an option

  • Save fedegomez/7b4601e2cc9491e004189e9a23dd35b1 to your computer and use it in GitHub Desktop.

Select an option

Save fedegomez/7b4601e2cc9491e004189e9a23dd35b1 to your computer and use it in GitHub Desktop.
Checks if the title of the result in the SERP matches the title of the URL
javascript: (function (doc){var changed=0; function checkTitles(){console.log('jQuery version ', $.fn.jquery, ' loaded'); var position=1; var items=[]; var results=$('#rso .kp-blk .g, #rso .g[class="g"], #rso .srg .g').not('.kno-kp .g').find('div:first').find('a:first'); $('.title-changed, #CountTitlesChanged').remove(); results.each(function (){if (!$(this).parents('.related-question-pair').length){var parent=$(this).closest('.tF2Cxc').length > 0 ? $(this).closest('.tF2Cxc') : $(this).closest('li'); items.push([ position, $(this).find('h3').text(), encodeURI($(this).attr('href')), parent]); position++;}}); var numItems=1; cors_proxies=[ 'https://api.codetabs.com/v1/proxy?quest=', 'https://jsonp.afeld.me/?url=',]; items.forEach(item=>{$.ajax({url: cors_proxies[Math.floor(Math.random() * cors_proxies.length)] + item[2], success: function (data, status, xhr){title=$(data).filter('title').text(); var html='<div class="title-changed">'; if (title !=item[1]){html +='<span style="font-weight: bold;color: #ff6961;">' + title + '</span>'; changed++;}else{html +='<span style="font-weight: bold;color: darkgreen;">' + item[1] + '</span>';}html +='</div>'; item[3].find('div').first().append(html);}, error: function (xhr, status, error){var html='<div class="title-changed">'; html +='<span style="font-weight: bold;color: lightslategray;">Error: No se ha podido procesar la solicitud</span>'; html +='</div>'; item[3].find('div').first().append(html);}, complete: function (xhr, status){if (numItems==items.length){petitionCompleted();}else{numItems++;}}});});}function petitionCompleted(){$('#result-stats').append('<span id="CountTitlesChanged"> - ' + changed + ' títulos cambiados en esta página</span>');}if (typeof jQuery=='undefined'){var script_jQuery=document.createElement('script'); script_jQuery.src='https://code.jquery.com/jquery-latest.min.js'; script_jQuery.onload=checkTitles; doc.body.appendChild(script_jQuery); console.log('script_jQuery appended to body');}else{console.log('jQuery already included ...'); checkTitles();}})(document)
@fedegomez

Copy link
Copy Markdown
Author

image

@faisalrafique21

Copy link
Copy Markdown

@fedegomez Kindly can you tell me how to install or configure it on the browser??

@fedegomez

fedegomez commented Aug 29, 2021

Copy link
Copy Markdown
Author

@fedegomez Kindly can you tell me how to install or configure it on the browser??

Just drag the code to the browser's bookmark bar, or create a new bookmark and paste the code in the URL field. Then when you do a search, just click on the bookmark and it will return the original titles.

meta-bookmarklet
GIF by Jens Polomski
(https://jens.marketing/google-meta-title-ueberpruefen/)

@neximuss

Copy link
Copy Markdown

Thank you, very useful, but still with some ugly bugs:
Bildschirmfoto 2021-08-30 um 00 22 47
Bildschirmfoto 2021-08-30 um 00 22 33

@jmfelip

jmfelip commented Aug 30, 2021

Copy link
Copy Markdown

Hey Fede, really nice one!
Many thanks for sharing :-)

@jblanch2018

Copy link
Copy Markdown

Si los sitios tienen protección por cloudflare no muestra el title "escrapeado" por lo demás funciona perfectamente!

@rootxnaresh

Copy link
Copy Markdown

Thanks for this tool, really helpful. 👏

@arvindsoniindia

Copy link
Copy Markdown

Well done it will really help SEO professionals
Thanks for sharing it

@yashlohade21

Copy link
Copy Markdown

Thanks For This

@priyansh1001

Copy link
Copy Markdown

Hey, I am not getting the proper view, can some one suggest me what to do?
Only 1st one is proceed, no effect from 2nd result.

image

@chrishaensel

Copy link
Copy Markdown

Thank you, very useful, but still with some ugly bugs:
Bildschirmfoto 2021-08-30 um 00 22 47
Bildschirmfoto 2021-08-30 um 00 22 33

The webiste you're showing in your screenshot is using the charset=iso-8859-1, as you can see in the source. If it were to use utf8, everything would be fine :) So I don't think it's a task for Fede to cope with this :)

@naruto-chelsea

Copy link
Copy Markdown

How do i do this in safari on mac?

@anskari1972

Copy link
Copy Markdown

Fede, Gracias!!! 🙏🙌👏

@mikkellauge

mikkellauge commented Sep 3, 2021

Copy link
Copy Markdown

Very nice tool. Can you tell, why some results gets these error?
image

@jaegermark

Copy link
Copy Markdown

@mikkellauge Read here: https://www.simply.com/dk/support/faq/php/36/ (in Danish). You have to deactivate your web host's Web Application Firewall.

@mikkellauge

Copy link
Copy Markdown

Thanks @jaegermark :)

@jrosell

jrosell commented Sep 8, 2021

Copy link
Copy Markdown

No conocia estos proxies que usas y me parece una idea genial para ir rapidito con javascript. Gracias @fedegomez

@Dasuhalder

Copy link
Copy Markdown

this code is not working on Mac, please help.

@borma425

Copy link
Copy Markdown

I can improve this code to work properly
better and faster
If interested: https://twitter.com/yehia_online

@gab81

gab81 commented Nov 5, 2021

Copy link
Copy Markdown

this is amazing, thanks @fedegomez - is there a chance of having one for meta descriptions as well? that'd be awesome, thanks!!

@5starcruises

Copy link
Copy Markdown

Hi, this is exactly what I have been looking for but can't seem to get it to work. I am on a Mac. I have added the code to the URL of the bookmark. I presume that I just do a google search for a keyword term and then press the bookmark? It would be amazing to get it working. Any help gratefully received.

Thanks

Danny

@team-community

Copy link
Copy Markdown

This script has stopped working. Yesterday I worked on windows.

@kurhadeakshay

Copy link
Copy Markdown

This script is not working and no errors in the output. I am checking it on google chrome windows.

@idrsln

idrsln commented Nov 23, 2022

Copy link
Copy Markdown

Hej! Could you be so kind to review your JS? Seems to be Google changed class names or smth. Your script was very very! useful for webmasters. Please, make it valid)))

@Jolle775

Copy link
Copy Markdown

Script stopped to work. Is there a Solution for this? Thanks

@Steveseo73

Copy link
Copy Markdown

Hi all, I just used Claude.ai to fix this and it works again.

javascript:(function(){const s=document.createElement('style');s.textContent=.tc{margin-top:8px;font-size:14px}.tm{color:#0f5132;background:#d1e7dd;padding:2px 6px;border-radius:3px}.tmm{color:#842029;background:#f8d7da;padding:2px 6px;border-radius:3px}.te{color:#664d03;background:#fff3cd;padding:2px 6px;border-radius:3px};document.head.appendChild(s);const p=['https://corsproxy.io/?','https://api.allorigins.win/raw?url='];let c=0;const g=()=>Array.from(document.querySelectorAll('div.g:not(.kno-kp .g) div[data-snf] a:has(h3)')).map((l,i)=>({p:i+1,e:l.closest('div.g'),t:l.querySelector('h3').textContent,u:l.href}));const f=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 d.title.trim()};const d=(e,g,a,r=false)=>{const v=document.createElement('div');v.className='tc';if(r)v.innerHTML='<span class="te">Error fetching page title</span>';else if(g===a)v.innerHTML=✓ Titles match: "${g}";else{c++;v.innerHTML=Google: "${g}"
Page: "${a}"
}e.appendChild(v)};(async()=>{const r=g();for(const t of r){try{const a=await f(t.u);d(t.e,t.t,a)}catch{d(t.e,t.t,'',true)}await new Promise(r=>setTimeout(r,300))}const s=document.getElementById('result-stats');if(s)s.textContent+= - ${c} title${c!==1?'s':''} different from search results})()})();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment