Skip to content

Instantly share code, notes, and snippets.

@yoko
Forked from hitode909/random-color.user.js
Created May 7, 2010 14:49
Show Gist options
  • Save yoko/393504 to your computer and use it in GitHub Desktop.
Save yoko/393504 to your computer and use it in GitHub Desktop.
WebKitでも動くようにした
// ==UserScript==
// @name random-color
// @namespace http://www.hatena.ne.jp/hitode909
// @include *
// ==/UserScript==
var randomColor = function() {
return 'rgb(' + (Math.random() > 0.5 ? 255 : 0) + ', ' + (Math.random() > 0.5 ? 255 : 0) + ', ' + (Math.random() > 0.5 ? 255 : 0) + ')';
};
var style = document.createElement('style');
document.body.appendChild(style);
var selectors = Array.prototype.slice.call(document.querySelectorAll('*[id]')).map(function(element) {
var id = element.id;
if (!id) return '';
return element.tagName + '#' + id;
}).concat(Array.prototype.slice.call(document.querySelectorAll('*[class]')).map(function(element) {
var className = element.className;
if (!className) return '';
return element.tagName + '.' + className;
}));
var apply = function() {
style.textContent = ['*', 'body'].concat(selectors).map(function(selector) {
if (!selector) return '';
return selector + ' {color: ' + randomColor() + '; background: ' + randomColor() + ' }';
}).join("\n");
};
setInterval(apply, 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment