Skip to content

Instantly share code, notes, and snippets.

@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;
}
@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 / 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);
function stopWatch (fn, timerName) {
console.log( console.time(timerName) );
fn();
console.log( console.timeEnd(timerName) );
}
/* Usage *//*
function testFn() {
return 10 * 10 * 10;
(function(DP) {
Date.now || (Date.now = function() {
return new Date().getTime();
});
})(Date.prototype);
var
E3, E6, E12, E24,
E48, E96, E192;
E3 = [
1.0, 2.2, 4.7
];
E6 = [
@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
@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,
/*jshint multistr: true */
// 全ての艦名 (改造艦は含まない)
var allKanmusu =
"長門, 陸奥, 伊勢, 日向, 雪風,\
赤城, 加賀, 蒼龍, 飛龍, 島風,\
吹雪, 白雪, 初雪, 深雪, 叢雲,\
磯波, 綾波, 敷波, 大井, 北上,\
金剛, 比叡, 榛名, 霧島, 鳳翔,\
// document.body.style
// ※これだと length プロパティなどもふくまれてしまうので目視で削除・加工
// 何か良い方法は無いものか
var webkitCssStyles = [
"alignContent",
"alignItems",
"alignSelf",
"alignmentBaseline",
"background",