Skip to content

Instantly share code, notes, and snippets.

@hitode909
Created May 7, 2010 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hitode909/393209 to your computer and use it in GitHub Desktop.
Save hitode909/393209 to your computer and use it in GitHub Desktop.
色をランダムに変える
// ==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