Skip to content

Instantly share code, notes, and snippets.

@xulapp
xulapp / class.js
Created March 12, 2010 14:08
Class
function Class(sup, pro) {
if (sup && typeof sup === 'object')
pro = sup, sup = Object;
var con = Object.getOwnPropertyDescriptor(pro, 'constructor');
if (!con)
con = {value: Function(), writable: true, configurable: true};
if (con.configurable) {
con.enumerable = false;
@xulapp
xulapp / inherit.js
Created March 15, 2010 16:57
inherit
function inherit(sub, sup) {
var c = Function();
c.prototype = sup.prototype;
var fn = new c;
fn.constructor = sub;
sub.prototype = fn;
sub.superclass = sup;
}
/* @require Prototype.js
var src = new WaveFile(properties).toDataURI();
// properties は WaveFile.prototype を参考に。
*/
Object.extend(Number.prototype, {
toLEArray: function toLEArray(length) {
var num = this | 0, length = +length, result = [];
if (0 < arguments.length && !length) return result;
@xulapp
xulapp / symbol.js
Created March 24, 2010 05:11
symbol
[p for(p in Iterator(#1={
0: +'',
1: -~'',
2: -~-~'',
3: -~-~-~'',
4: -~-~-~-~'',
5: -~-~-~-~-~'',
6: '$$$$$$'[~''],
7: '$$$$$$$'[~''],
8: -~''<<-~-~-~'',
@xulapp
xulapp / trim_comment.js
Created March 28, 2010 04:50
JS のコメントを除去
// できないこと
// ・演算子(/, /=) の後ろにあるコメントを除去できない
// ・演算子(/, /=) の後ろにある正規表現リテラルを無視できない
// ・<xml>{0/*消えて*/}/*消えないで*/</xml>
function trimComment(str) {
// コメント___________________ 文字列リテラル(")_______ 文字列リテラル(')_______ CDATA セクション________ 正規表現リテラル___________________________
return str.replace(/(\/)(?:\*[\s\S]*?\*\/|\/.*)|"(?:\\[\s\S]|[^\\\n"])*"|'(?:\\[\s\S]|[^\\\n'])*'|<!\[CDATA\[[\s\S]*?\]\]>|\/(?:\\.|\[(?:\\.|[^\n\]])*\]|[^\n/])+\/\w*/g, function($0, $1) {
return $1 ? '' : $0;
});
@xulapp
xulapp / lastModifiedPanel.uc.js
Created March 30, 2010 04:23
lastModifiedPanel.uc.js
// ==UserScript==
// @name lastModifiedPanel.uc.js
// @description adds toolbaritem that indicates Last-Modified.
// @include main
// @compatibility Firefox 4.0+
// @namespace http://twitter.com/xulapp
// @author xulapp
// @license MIT License
// @version 2011/04/03 19:00 +09:00 addon-bar
// ==/UserScript==
@xulapp
xulapp / showFxVersionInTitlebar.uc.js
Created March 31, 2010 09:07
showFxVersionInTitlebar.uc.js
// ==UserScript==
// @name showFxVersionInTitlebar.uc.js
// @description the version number is displayed behind "Mozilla Firefox".
// @include main
// @compatibility Firefox 3.5+
// @namespace http://twitter.com/xulapp
// @author xulapp
// @license MIT License
// @version 2010/03/31 18:00 +09:00
// ==/UserScript==
@xulapp
xulapp / showTabsCountInTitlebar.uc.js
Created March 31, 2010 09:11
showTabsCountInTitlebar.uc.js
// ==UserScript==
// @name showTabsCountInTitlebar.uc.js
// @description the tabs count is displayed in the end of the title string.
// @include main
// @compatibility Firefox 3.5+
// @namespace http://twitter.com/xulapp
// @author xulapp
// @license MIT License
// @version 2011/04/03 15:40 +09:00
// ==/UserScript==
@xulapp
xulapp / prediction.js
Created March 31, 2010 18:18
PPM 法
function Prediction(level) {
this.level = +level || 5;
this.history = '';
this.recent = '';
this.accum = {};
this.tokens = {};
}
Prediction.prototype.add = function add(c) {
c = ('' + c).charAt(0);
this.tokens[c] = true;
@xulapp
xulapp / altTooltip.uc.js
Created April 1, 2010 12:03
altTooltip.uc.js
// ==UserScript==
// @name altTooltip.uc.js
// @description title がなければ alt を出す
// @include main
// @compatibility Firefox 3.5+
// @namespace http://twitter.com/xulapp
// @author xulapp
// @license MIT License
// @version 2010/04/01 21:00 +09:00
// ==/UserScript==