Latest topics > 他の拡張機能やFirefoxの機能を破壊しないための基本テク 宣伝。日経LinuxにてLinuxの基礎?を紹介する漫画「シス管系女子」を連載させていただいています。 以下の特設サイトにて、単行本まんがでわかるLinux シス管系女子の試し読みが可能! « いちばんになりたい Main ISBNコードからAmazonのアフィリエイトのリンクを生成するカスタムスクリプト for ContextMenu Extensions » 他の拡張機能やFirefoxの機能を破壊しないための基本テク - Sep 04, 2007 拡張機能勉強会の時に焚き付けられた、Text Shadowのコード(textshadow.js)を教材にして拡張機能開発のノウハウを解説していくシリーズ。 JavaScriptでは、普通に宣言した変数や関数はグローバルな物になる。 var name
論理演算2で現れた ・コード1 var x = 0; for (var i = 0; i < 1000000; i++) { x += i; } の処理時間はFirefox(Fx)では1046(ここでは比率のみが焦点なので単位は考えない)でした.ちなみにIEでは141です(小さい方が速い).Fxはかなり分が悪いようです. 一見これ以上いじりようのない単純なコードをFxでどこまで速くできるのか少し詳しく考えてみます.前回見たように30bitを超えないようにxを二つの変数に分けてみましょう. ・コード2 /* [x[1]:x[0]] += [y[1]:y[0]]を求める. ここで[a:b]はa * (1<<30) + bを意味する(0 <= a, b < (1<<30)). */ function add(x, y) { var t = x[0] += y[0]; x[1] += y[1];
UAIdentifier - JavaScript によるユーザエージェント判別 © 2006-2007 Magicant / 1.9.2 (2007-02-02) JavaScript を実行しているブラウザの種類およびそのレンダリングエンジン・オペレーティングシステムの種類を判別します。 テストページで実際に試すことができます。 uai.js は自由に使用していただいて構いません。 目次 uai.js の使い方 uai.js の API 仕様 UAIdentifier コンストラクタ toString メソッド 各プロパティ 判別機能の詳細 判定結果の使い方 uai.js の使い方 実装ファイルは uai.js です。 このファイルは単独では実行しても意味がありません。 uai.js には UAIdentifier オブジェクトの定義が含まれ
JavaScript簡単なようで、とても難しく、情報もあまり見つからなかったので、知らない方はぜひ読んで。 選択範囲の移動でもなく、選択範囲の内容の取得でもありません。選択範囲がテキストエリアの中で何文字目から何文字目に渡っているかをIEで調べる方法です。 まずFirefoxではElement#selectionStart/selectionEndで簡単に取れます。 次に、テキストエリアではなく一行のインプットボックスならば以下で大丈夫です。 setEndPointメソッドは、rangeTo.setEndPoint('EndToStart', rangeFrom)のように使い、rangeFromの範囲をrangeToにコピーします。名前はEndPointですが、始点/終点のどちらの端もこのメソッド一つで動かすことができます。'EndToStart'は、「rangeToの終点を、rangeF
asActionScript の関数を JavaScript から呼び出すときに、ExternalInterface.addCallback で関数を使うと便利なのですが、ここで公開された関数は apply, call, toString といったメソッドが定義されていません。実験した ActionScript はこんなの。要は draw 関数を ExternalInterface を使って公開してます。 package { import flash.display.*; import flash.external.ExternalInterface; public class ExtTest extends Sprite { public function ExtTest() { draw(0); ExternalInterface.addCallback("draw", draw);
id:n_shuyo:20070118:firefox にても書いたが、チュートリアルがないために Firefox 拡張開発の敷居が高くなってしまっているんじゃないかと感じている。 XUL とかは人に説明できるほど詳しくないが、「開発の始め方」のチュートリアルであれば自分にも書けそう。ということで以下にさっくりまとめてみた。 より詳しい人が突っ込んでくれてさらに親切なものになると嬉しい。 ★★2/8 一部追記:GUIDについての記述を追加した ちなみに http://firefox.geckodev.org/index.php?%E6%8B%A1%E5%BC%B5%E3%81%AE%E4%BD%9C%E6%88%90 でも同じサンプルを使ってチュートリアル的にまとめてあるが、サンプルを改変した後にわざわざ jar を作り直す手順になっているのが面倒である。ここではそれが不要(コードを書き換
昨日のエントリに引き続き、今度はスクロールバーで隠れている領域を含むサイズを取得するためのプロパティをまとめてみました。 Enjoy×Study - ブラウザの表示領域のサイズを取得する方法。 調査したのは、下記のプロパティです。 window.innerWidth window.innerHeight document.body.scrollWidth document.body.scrollHeight document.body.offsetWidth document.body.offsetHeight document.body.clientWidth document.body.clientHeight document.documentElement.scrollWidth document.documentElement.scrollHeight document.docu
ブラウザの表示領域を取得するに当たって、「ブラウザの種類」×「表示モード(標準/互換)」によって参照するプロパティが変わってきます。 IE、FireFox、Opera、Safariにて、表示モード毎に参照すべきプロパティをまとめてみました。(Safariについては2007/05/20に追記) 調査したのは、下記のプロパティです。 window.innerWidth window.innerHeight document.body.scrollWidth document.body.scrollHeight document.body.offsetWidth document.body.offsetHeight document.body.clientWidth document.body.clientHeight document.documentElement.scrollWidth d
またFirefoxは短縮形で取得しようとすると、設定していないプロパティにデフォルト値が入った状態で返ってくるので注意する。 getStyleValue( "div.hoge", "background" ) //Mozilla : rgb(17, 34, 51) none repeat scroll 0% 0% ルールを削除する function deleteRule( index, sheetindex ) { if( sheetindex == undefined ) sheetindex = 0; document.styleSheets[ sheetindex ].deleteRule( index ); } 全てのルールにはインデックスが振られており、それを指定することでルールから消すことができる。 ただ、同じセレクタで上書きするのとほとんど変わらないので、あまり必要にならない
とてもシンプルに自分自身が属する script 要素を取得 http://d.hatena.ne.jp/amachang/20061201/1164986067 document.writeをDOM仕様にする http://nyarla.net/blog/javascript-tips1 あたりに着想を受けて、作ってみました。 http://la.ma.la/misc/js/lazy_writer/ 特定のscript src内のdocument.writeをピンポイントに置き換えることができます。 制限事項としては、document.writeを使ってscriptタグを生成するようなコードの場合、IEではinnerHTMLにscriptを書いても実行されないという仕様があるので実行されません。その点を除けば、IFRAMEをdocument.writeで挿入するような、良くある広告系のdo
I’ve been experimenting with running code in an iframe and the results are very encouraging. Sandbox.eval() I’m currently developing a templating system in JavaScript and ran into a problem with scope. The problem is that my template scripts have access to all of the global (window) object’s properties and methods. I don’t want this. I want my template scripts to run in a separate, closed environm
JavaScript #5= {}について、Days on the Moonのnanto_viさんから、詳細な情報を頂きました。いつもいつもありがとうございます。(無断で、コメントをブログ本文に転載してしまいごめんなさいね。) nanto_vi これはシャープ変数(sharp variables)と呼ばれるJavaScriptの拡張機能ですね。循環参照を持つオブジェクトをリテラル形式で書くときなどに用いられます。#n=の後にオブジェクトを指定することで、#n#を使いそのオブジェクトを参照することができるようになります。 var o = #1= { next: { next: { next: #1# } } }; o == o.next.next.next; // true Enumerable.prototype = { map: #1= function () { ... }, col
2006年09月24日16:00 カテゴリLightweight Languages javascript + perl - yubin2jsonp どうせなら、JSONPを使ってどこにでも設置できたらいいじゃんと思ったのでこんなのこさえました。 [Ajax] CGI不要の郵便番号→住所変換フォーム Kawa.net Blog /ウェブリブログ JavaScript のみで稼動するため、サーバサイドで稼動するCGIプログラムは不要です。こんな感じです。 〒(7けた) 都道府県 市区町村 町域以降 HTMLまで含めたsourceはこんな感じです。 <script> function Yubin2JSONP(root){ this.root = root; this.parse = function(yubin){ if (! yubin.match(/[0-9]{7}/) ) return
JavaScriptテストコードのため書きっぱなしです。以下は、テキストエリアのカーソルの下に、候補窓がついてくるサンプルです。これをちゃんと書き直して、補完と組み合わせてみよう。 サンプル pre要素にborderやwidth/height、font-familyやword-spacingなど全ての属性をコピーしてテキストエリアのクローンを作り、その中のカーソルを真似たspan要素の座標を取得しています。もしかして、eventなどから簡単に位置を割り出せるのかなぁ。 カーソルの位置(文字数)はid:kosekiさんのCross Browser selectionStart/selectionEndをコピーして真似ました。 EditArea(コードが大変な感じ)も、テキストエリア(編集領域)とDIV要素(表示領域)を重ね合わせて色々なことをやってる。大量のspan要素で色づけ。 infog
IE でのメモリリーク ちょこちょこと紹介されているので知っている人も多いと思うが、IE には DOM ノードに絡んだメモリリークの問題がある。これに関しては Microsoft 自身の記事である「Understanding and Solving Internet Explorer Leak Patterns」に詳しいが、簡単にいえば DOM ノードオブジェクトに関する循環参照を作ると、IE を終了させるまでそのオブジェクトが解放されないというものだ。記事によればメモリリークには以下のようなパターンがあるという。 1. 単純な循環参照 ある DOM ノードオブジェクトのプロパティをたどっていくと自分自身に行き着く場合。以下のようなパターンが考えられる。 element.property == element element1.property1 == element2, element2
Updated Entry: http://p2b.jp/200805-events-order 今日は七夕Wですね。小学生の頃は、学校総出で「♪笹の葉さーらさら〜」ってやって、七夕伝説に思いを馳せたものですが。いつになってもガキの頃の心を忘れない大人でいたいものです。 さて、Ajaxの隆盛によって、その根幹であるJavaScriptはブログに欠かせないものとなっています。ppBlogも例外ではなく、至るところで活躍してます。一般にブログの(トップ)ページは、色々な情報を詰め込んでいるために、ファイルサイズは大きくなる傾向にあり、また、画像も至るところで使われるために、読み込むべきコンテンツサイズは更に大きくなります。ブロードバンドが当たり前の今日でもページの表示にちょっと待たされるのは珍しいことではありません。で、JavaScriptは(画像も含めた)ページの内容物が全部読み込まれた後に
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く