Created
May 15, 2010 08:12
-
-
Save hokaccha/402095 to your computer and use it in GitHub Desktop.
This file contains 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
// ==UserScript== | |
// @name setMicroformats | |
// @namespace http://webtech-walker.com/ | |
// @description set class by wedata | |
// @include http://* | |
// @include https://* | |
// ==/UserScript== | |
(function() { | |
var addClass = function(selector, className) { | |
var elems = Array.prototype.slice.call(document.querySelectorAll(selector)); | |
elems.forEach(function(elem) { | |
var baseClass = elem.getAttribute('class'); | |
var setClass = baseClass ? ' ' + baseClass : ''; | |
setClass += className; | |
elem.setAttribute('class', setClass); | |
}); | |
} | |
GM_xmlhttpRequest({ | |
method: 'GET', | |
url: 'http://wedata.net/databases/mf-test/items.json', | |
onload: function(res) { | |
info = eval(res.responseText).map(function(i) { return i.data }); | |
info.forEach(function(data) { | |
var regex = new RegExp(data.url); | |
if ( regex.test(location.href) ) { | |
var selectors = eval('[' + data.selector + ']'); | |
var classes = eval('[' + data.class + ']'); | |
selectors.forEach(function(selector, i) { | |
addClass(selector, classes[i]); | |
}); | |
} | |
}); | |
}, | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment