Skip to content

Instantly share code, notes, and snippets.

@franzenzenhofer
Created September 5, 2012 08:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save franzenzenhofer/3632965 to your computer and use it in GitHub Desktop.
Save franzenzenhofer/3632965 to your computer and use it in GitHub Desktop.
greasmonkey / chrome - userscript -shows important SEO head information
// ==UserScript==
// @name shows important SEO head information
// @namespace http://www.facesaerch.com/
// @description show canonical, noindex, nofollow
// @include *
// ==/UserScript==
function trim12 (str) {
var str = str.replace(/^\s\s*/, ''),
ws = /\s/,
i = str.length;
while (ws.test(str.charAt(--i)));
return str.slice(0, i + 1);
}
var allElements, thisElement;
allElements = document.getElementsByTagName('link');
var mybody, newElement, newElement2;
mybody = document.getElementsByTagName('body');
for (var i = 0; i < allElements.length; i++) {
thisElement = allElements[i];
if(thisElement.getAttribute('rel')=='canonical')
{
if (mybody[0]) {
if(thisElement.getAttribute('href')!=document.location)
{
bg="yellow";
bor="red";
c="blue";
var link = true;
}
else
{
bg="lightyellow";
bor="gray";
c="black";
var link = false;
}
newElement = document.createElement('div');
newElement.setAttribute('id', 'canonicaldebug');
newElement.setAttribute('style', 'position:fixed; left:5px; top:5px; z-index: 9999999; border: 1px solid '+bor+'; background-color: '+bg+'; padding: 2px; font: 9px arial; color: '+c+'";');
if(link==true)
{
newElement.innerHTML="<a href='"+thisElement.getAttribute('href')+"' style='color:blue;' >"+thisElement.getAttribute('href')+"</a>";
}
else
{
newElement.innerHTML=thisElement.getAttribute('href');
}
mybody[0].parentNode.insertBefore(newElement, mybody[0]);
}
}
}
//robotsS
allMeta = document.getElementsByTagName('meta');
var rc='';
for (var i = 0; i < allMeta.length; i++)
{
thisElement = allMeta[i];
if(thisElement.getAttribute('name')=='robots')
{
rc=rc+' '+thisElement.getAttribute('content');
}
else if(thisElement.getAttribute('name')=='googlebot')
{
rc=rc+' '+thisElement.getAttribute('content');
}
}
rc=trim12(rc);
if(rc!='')
{
//alert(rc);
newElement2 = document.createElement('div');
if((rc.search('noindex')!=-1)|(rc.search('nofollow')!=-1))
{
bg="yellow";
bor="red";
c="blue";
//alert(rc.search('noindex'));
}
else
{
bg="lightyellow";
bor="gray";
c="black";
}
if(document.getElementById('canonicaldebug'))
{
toppx="25";
}
else
{
toppx="5";
}
newElement2.setAttribute('style', 'position:fixed; left:5px; top:'+toppx+'px; z-index: 9999999; border: 1px solid '+bor+'; background-color: '+bg+'; padding: 2px; font: 9px arial; color: '+c+' !important";');
newElement2.innerHTML=rc;
document.body.parentNode.insertBefore(newElement2, mybody[0]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment