Created
July 1, 2009 13:40
-
-
Save youpy/138781 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Teiten Uploader | |
// @namespace http://d.hatena.ne.jp/youpy/ | |
// @include http://teiten.org/everyone* | |
// ==/UserScript== | |
(function() { | |
GM_addStyle('.fav-add { display: none; }'); | |
Number.prototype.times = function(f) { | |
var times = Math.abs(this.valueOf()); | |
for(var i = 0; i < times; i ++) { | |
f(i); | |
} | |
}; | |
function formatHex(hex) { | |
return hex.length == 1 ? '0' + hex : hex; | |
} | |
function getColors() { | |
var image = document.images[Math.floor(Math.random() * document.images.length)]; | |
canvas.width = image.naturalWidth; | |
canvas.height = image.naturalHeight; | |
ctx.drawImage(image, 0, 0); | |
var imageData = ctx.getImageData(0, 0, canvas.width, canvas.height).data; | |
var Effects = {}; | |
Effects.thru = function(v) { | |
return v; | |
}; | |
var effect = Effects.thru; | |
var colors = []; | |
var line, lines; | |
lines = []; | |
(canvas.width).times(function(w) { | |
line = []; | |
(canvas.height).times(function(h) { | |
var pos = (canvas.width * h + w) * 4; | |
var r = formatHex(effect(imageData[pos]).toString(16)); | |
var g = formatHex(effect(imageData[pos+1]).toString(16)); | |
var b = formatHex(effect(imageData[pos+2]).toString(16)); | |
line.push(r + g + b); | |
}); | |
// workaround for misalignment | |
line.push('000000'); | |
lines.push(line); | |
}); | |
var sort_key = Math.floor(Math.random() * canvas.height); | |
colors = lines.sort(function(a, b) { | |
return parseInt(b[sort_key], 16) - parseInt(a[sort_key], 16); | |
}).reduce(function(line, result) { | |
return result.concat(line); | |
}, []); | |
return colors.join('%2C') + '&h=' + canvas.height + '&w=' + canvas.width; | |
} | |
function upload() { | |
GM_xmlhttpRequest({ | |
method: 'post', | |
url: 'http://teiten.org/snapshot.php', | |
data: 'colors=' + getColors(), | |
headers: { | |
'Content-type': 'application/x-www-form-urlencoded' | |
}, | |
onload: function(res) { | |
location.reload(); | |
} | |
}); | |
} | |
var canvas = unsafeWindow.document.createElement('canvas'); | |
canvas.style.display = 'inline'; | |
unsafeWindow.document.body.appendChild(canvas); | |
var ctx = canvas.getContext("2d"); | |
setInterval(upload, 1000 * 60 * 1); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment