Skip to content

Instantly share code, notes, and snippets.

View yoko's full-sized avatar
🍐
I like pear

yksk yoko

🍐
I like pear
View GitHub Profile
var emoji = {
binary_store: {},
convert: function(str, raw) {
var ret = [], img;
for (var i = 0, c; c = str.charCodeAt(i); i++) {
if (
0xE63E <= c && c <= 0xE6A5 ||
0xE6AC <= c && c <= 0xE6AE ||
0xE6B1 <= c && c <= 0xE6B3 ||
try
do shell script "open \"http://radiko.jp/player/player.html#TBS\""
on error errorText
display dialog errorText
end try
Number.prototype.drop = function(digit) {
var n = Math.pow(10, digit || 0);
var ret = this * n;
ret = Math.floor(ret);
return (ret / n).toFixed(digit);
};
// ==UserScript==
// @name Gresemonkey localStorage Test
// @namespace http://codefairy.org/ns/userscripts
// @include *
// ==/UserScript==
GM_log(typeof unsafeWindow.localStorage); // object
GM_log(unsafeWindow.localStorage.num = Number(unsafeWindow.localStorage.num || 0) + 1); // OK!
GM_log(typeof window.localStorage); // object
// prototype.js breakes native JSON
if (String.prototype.evalJSON && Object.toJSON)
window.JSON = {
parse: function(str) { return str.evalJSON(); },
stringify: function(obj) { return Object.toJSON(obj); }
};
function formatTumblrDate(date) {
var y = date.getFullYear();
var m = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][date.getMonth()];
var d = date.getDate();
d = d+(['st', 'nd', 'rd', 'th'][(/(1?\d)$/.exec(d))[1] - 1] || 'th');
var h = date.getHours();
var ampm = ['am', 'pm'][Number(h >= 12)];
h = h % 12;
var min = date.getMinutes();
if (min < 10) min = '0'+min;
var shortcut = {
keys: [],
setup: function() {
document.addEventListener('keypress', this.keypress, false);
return this;
},
bind: function(key, handler) {
this.keys[key] = handler;
var greasemonkey = (typeof unsafeWindow != 'undefined');
if (greasemonkey)
Foo.setup(); // use @resource
else {
// referred to jQuery
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js';
Array.prototype.flatten = function() {
return this.join().split(',');
};
function monochrome(src) {
var d = new Deferred;
var img = new Image;
img.src = src; // must same domain
img.onload = function() {
var w = img.width;
var h = img.height;
var _canvas = $('<canvas width="'+w+'" height="'+h+'" class="photo">');
var _context = _canvas[0].getContext('2d');