Skip to content

Instantly share code, notes, and snippets.

@hokaccha
Created May 15, 2010 08:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hokaccha/402095 to your computer and use it in GitHub Desktop.
Save hokaccha/402095 to your computer and use it in GitHub Desktop.
// ==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