Skip to content

Instantly share code, notes, and snippets.

@ethertank
ethertank / Number.js
Last active December 30, 2015 02:49
使ったら死ぬ
(function(N, global) {
// 不完全
// The value of Number.MAX_SAFE_INTEGER is 9007199254740991 (2e53-1)
// This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.
// IE8 の Object.defineProperty は Dom オブジェクトでのみ有効で、動作も異なる
if(!N.MAX_SAFE_INTEGER) {
N.MAX_SAFE_INTEGER = 9007199254740991;
Object.defineProperty && Object.defineProperty(N, "MAX_SAFE_INTEGER", {
writable : false,
@ethertank
ethertank / 直リン画像回転くん.user.js
Last active December 25, 2015 10:09
直リン画像回転くん.user.js for Google Chrome
// ==UserScript==
// @name 直リン画像回転くん
// @namespace http://ethertank.jp
// @version 0.2
// @description 直リン画像回転くん
// @include *.jpg
// @include *.jpeg
// @include *.png
// @include *.gif
var
E3, E6, E12, E24,
E48, E96, E192;
E3 = [
1.0, 2.2, 4.7
];
E6 = [
(function(DP) {
Date.now || (Date.now = function() {
return new Date().getTime();
});
})(Date.prototype);
function stopWatch (fn, timerName) {
console.log( console.time(timerName) );
fn();
console.log( console.timeEnd(timerName) );
}
/* Usage *//*
function testFn() {
return 10 * 10 * 10;
@ethertank
ethertank / tumbler_dashboard_addDelButton.js
Last active December 17, 2015 19:38
Tumblr のダッシュボードに、いっちゃん上のポストを消すボタンを追加するやつ。後でもうちょいマシなものにして userscript 化。
(function($){
$("body").append('<button id="b">button</button>');
$("#b").css({position:"fixed",bottom:"0",right:"0",height:"5em",width:"5em"});
$("#b").on("click", function() {
$(".post:nth-child(1)+li").remove();
console.clear();
});
})(jQuery);
@ethertank
ethertank / bookmarklet_noLogInNiconico.js
Last active December 15, 2015 18:09
「ツイッターでニコニコ動画のリンクをよく貼る方がいるが、あんまりログインしたくないんだよね~。」 そんな時はこれを使うのです。 www.nicovideo.jp It is popular in Japan is. Often japanese add link in your Twitter timeline. But it require login for viewing... Now, Use this bookmarklet. Niconico!
javascript:(function(d){var win=window.open(),doc=win.document,TITLE=d.title,vURL=d.URL,vID=vURL.replace(/http:\/\/www.nicovideo.jp\/watch\//g,'');doc.title=TITLE;doc.write('<h1>'+TITLE+'</h1><script type="text/javascript" src="http://ext.nicovideo.jp/thumb_watch/'+vID+'?w=490&h=307"></script><div>'+ d.getElementById('des_full').innerHTML+'</div><div>掲載URL : <a href="'+vURL+'">'+vURL+'</a></div>');doc.getElementsByClassName("font12")[0].removeChild(doc.getElementsByTagName("a")[0]);doc.body.style.fontFamily="arial,helvetica,meiryo,sans-serif";})(document);
@ethertank
ethertank / class.js
Created February 12, 2013 13:48
hasClass / addClass / removeClass
// http://www.avoid.org/?p=78
function hasClass(el, name) {
return new RegExp('(\\s|^)' + name + '(\\s|$)').test(el.className);
}
function addClass(el, name) {
if ( !hasClass(el, name) )
el.className += (el.className ? ' ' : '') + name;
}
(function(SP) {
SP.endsWith || (SP.endsWith = function(str, pos) {
pos = (pos === undefined) ? this.length : Math.floor(+pos);
str = str.toString();
var start = Math.min(Math.max(pos, 0), this.length) - str.length;
if (start < 0) return !1;
var idx = ''.indexOf.call(this, str, start);
return idx === start;
});
@ethertank
ethertank / String.prototype.js
Last active March 30, 2021 01:57
String.prototype の拡張のおまとめ。
(function(SP) {
var _t = "[\x09-\x0D\x20\xA0\x85\u1680\u180E\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]+",
_l = new RegExp("^" + _t),
_r = new RegExp(_t + "$");
// polyfills
SP.trimLeft = function() { return this.replace(_l, ""); };
SP.trimRight = function() { return this.replace(_r, ""); };
SP.trim = function() { return this.trimLeft().trimRight(); };