Created
May 7, 2010 08:55
-
-
Save hitode909/393209 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 random-color | |
// @namespace http://www.hatena.ne.jp/hitode909 | |
// @include * | |
// ==/UserScript== | |
var randomColor = function() '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