Skip to content

Instantly share code, notes, and snippets.

Last active May 24, 2023 03:38
  • Star 57 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
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=[ '', '',]; 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=''; script_jQuery.onload=checkTitles; doc.body.appendChild(script_jQuery); console.log('script_jQuery appended to body');}else{console.log('jQuery already included ...'); checkTitles();}})(document)
Copy link

@mikkellauge Read here: (in Danish). You have to deactivate your web host's Web Application Firewall.

Copy link

Thanks @jaegermark :)

Copy link

jrosell commented Sep 8, 2021

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

Copy link

this code is not working on Mac, please help.

Copy link

I can improve this code to work properly
better and faster
If interested:

Copy link

gab81 commented Nov 5, 2021

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

Copy link

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.



Copy link

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

Copy link

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

Copy link

idrsln commented Nov 23, 2022

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)))

Copy link

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

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