Skip to content

Instantly share code, notes, and snippets.

@alterx
Last active December 19, 2015 07:39
Show Gist options
  • Save alterx/5920529 to your computer and use it in GitHub Desktop.
Save alterx/5920529 to your computer and use it in GitHub Desktop.
This is a small script that will basically crawl a page and log the names and values of: -Title -Metas -Links You can add values to the check Object for specific metas to show. The showAll flag can be turned on to show all the links, metas and the title tag. The ommit Object can contains metas and links that you want to exclude (even if showAll …
var check = {
description : 'Description',
title : 'Title',
image : 'Image',
canonical : 'Canonical',
'og:image' : 'Open graph image',
'twitter:image' : 'Twitter Image'
},
ommit = {
stylesheet : 'styles'
},
showAll = false,
metaTags = document.getElementsByTagName('meta'),
linkTags = document.getElementsByTagName('link');
function _undefined(key, collection){
return (typeof collection[key] == 'undefined')? true: false;
}
for(var i=0;i<metaTags.length;i++){
var name = metaTags[i].name || metaTags[i].getAttribute('property');
if( (!_undefined(name, check) || showAll) && _undefined(name, ommit) ){
console.log( (check[ name ] || name) + ': ' + metaTags[i].content );
}
}
for(var i=0;i<linkTags.length;i++){
var name = check[linkTags[i].rel] || linkTags[i].rel;
if( (!_undefined(linkTags[i].rel, check) || showAll ) && _undefined(linkTags[i].rel, ommit ) ){
console.log(name + ': ' +linkTags[i].href);
}
}
titleTag = document.getElementsByTagName('title');
console.log('Title: ' + titleTag[0].innerText)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment