「雑多なメモ」の編集履歴(バックアップ)一覧はこちら
「雑多なメモ」(2016/04/29 (金) 11:22:46) の最新版変更点
追加された行は緑色になります。
削除された行は赤色になります。
#contents()
*拡張開発メモ
**ローカルパスを色々と操作
-[[Path manipulation - JavaScript OS.File | MDN>https://developer.mozilla.org/en-US/docs/JavaScript_OS.File/OS.Path]]
**nsIFile, nsIURI
***ローカルパスからnsIFileを作成
-[[FileUtils.jsm - Mozilla | MDN>https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/FileUtils.jsm]]
#highlight(javascript){{
Cu.import("resource://gre/modules/FileUtils.jsm");
var path = "C:\\temp\\sample.txt"; // ローカルパス文字列
var file = new FileUtils.File(path); }}
***URLからnsIURIを作成
-[[nsIIOService - Mozilla | MDN>https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIIOService#newURI()]]
#highlight(javascript){{
Cu.import("resource://gre/modules/Services.jsm");
var url = "http://www.sample.com/"; // URL文字列
Services.io.newURI(url, null, null); }}
-[[NetUtil.jsm - Mozilla | MDN>https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/NetUtil.jsm#newURI()]]
#highlight(javascript){{
Cu.import("resource://gre/modules/NetUtil.jsm");
var url = "http://www.sample.com/"; // URL文字列
NetUtil.newURI(url); }}
***nsIFileからnsIURIを作成
#highlight(javascript){{
Cu.import("resource://gre/modules/Services.jsm");
var file = new FileUtils.File(xxxx); // nsIFile
Services.io.newFileURI(file); }}
#highlight(javascript){{
Cu.import("resource://gre/modules/NetUtil.jsm");
var file = new FileUtils.File(xxxx); // nsIFile
NetUtil.newURI(file); }}
**http通信を監視してキャンセルする
通信をキャンセルするだけなので、タブやウィンドウが開いたりとかはする
#highlight(javascript){{
const Ci = Components.interfaces;
const Cu = Components.utils;
const Cr = Components.results;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
this.httpRequestObserver = {
QueryInterface : XPCOMUtils.generateQI([Ci.nsIObserver]),
observe: function(aSubject, aTopic, aData) {
let request = aSubject.QueryInterface(Ci.nsIHttpChannel);
let exp = new RegExp('^http://sample\\.com/');
if (exp.test(request.URI.spec)) {
Services.console.logStringMessage("[http-on-modify-request] [CANCEL]\n" + request.URI.spec);
request.cancel(Cr.NS_BINDING_ABORTED);
}
},
}
Services.obs.addObserver(httpRequestObserver, "http-on-modify-request", false);}}
-[[FirefoxでHTTPリクエストのURLを書き換えるアドオンを作成する - 遥かへのスピードランナー>http://poly.hatenablog.com/entry/20080604/1212561182]]
-[[片鱗懐古のブログ: firefoxアドオン : httpリクエストのキャンセルをするアドオンのサンプル>http://pieceofnostalgy.blogspot.jp/2013/01/firefox-http.html]]
**[[タイトルバー左のアイコンを独自の物にする]]
**XPCOMを読み込む方法
[[SCRAPBLOG : XPCOM サービスへの頻繁なアクセスを効率化するテクニック>http://www.xuldev.org/blog/?p=566]]
**label の value を書き換えるときは setAttribute を使う
#highlight(XML){
<toolbarbutton>
<tooltip id="mytooltip">
<label value="test tooltip"/>
<label value=""/>
</tooltip>
</toolbarbutton>}
上のような xul で、
#highlight(javascript){
var tooltip = document.getElementById('mytooltip');
tooltip.lastChild.value = 'test message';}
みたいな事をしてみたら、Firefox 起動直後は大丈夫なのだが、ツールバーのカスタマイズ後では value がまったく書き換わらない状態になった。
(正確には、javascriptオブジェクトでは書き換わっているのだが、xulオブジェクトは書き換わっていない。)
#highlight(javascript){
tooltip.lastChild.setAttribute('value', 'test message');}
と、setAttribute を使用すると問題なく動く。
**イベント
-[[Mozilla event reference - Document Object Model (DOM) | MDN>https://developer.mozilla.org/en-US/docs/DOM/Mozilla_event_reference]]
-[[event - MDC Doc Center>https://developer.mozilla.org/ja/DOM/event]]
-[[element - MDC Doc Center>https://developer.mozilla.org/ja/DOM/element#Event_Handlers]]
-[[DOM Events - MDC Doc Center>https://developer.mozilla.org/ja/DOM_Events]]
-[[Gecko 固有の DOM Event - MDC Doc Center>https://developer.mozilla.org/ja/Gecko-Specific_DOM_Events]]
-[[Toolbar customization events - MDC Doc Center>https://developer.mozilla.org/en/XUL/Toolbars/Toolbar_customization_events]]
-[[Using Firefox 1.5 caching - MDN>https://developer.mozilla.org/ja/Using_Firefox_1.5_caching]]
-[[gBrowser/イベント]]
**SQLite
-[[Storage | MDN>https://developer.mozilla.org/en-US/docs/Storage]]
同期・基本
#highlight(javascript){{
// sql はSQL文
var Cu = Components.utils;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/FileUtils.jsm");
var file = FileUtils.getFile("ProfD", ["sample.sqlite"]);
var dbConn = Services.storage.openDatabase(file);
var statement = dbConn.createStatement(sql);
statement.execute();
statement.finalize();
dbConn.close();}}
同期・パラメーター設定と結果の取得
#highlight(javascript){{
var statement = dbConn.createStatement("SELECT * FROM table_name WHERE id = :row_id");
statement.params.row_id = 1234;
while (statement.executeStep()) {
let value = statement.row.column_name;
} }}
#contents()
*拡張開発メモ
**ローカルパスを色々と操作
-[[Path manipulation - JavaScript OS.File | MDN>https://developer.mozilla.org/en-US/docs/JavaScript_OS.File/OS.Path]]
**nsIFile, nsIURI
***ローカルパスからnsIFileを作成
-[[FileUtils.jsm - Mozilla | MDN>https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/FileUtils.jsm]]
#highlight(javascript){{
Cu.import("resource://gre/modules/FileUtils.jsm");
var path = "C:\\temp\\sample.txt"; // ローカルパス文字列
var file = new FileUtils.File(path); }}
***URLからnsIURIを作成
-[[nsIIOService - Mozilla | MDN>https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIIOService#newURI()]]
#highlight(javascript){{
Cu.import("resource://gre/modules/Services.jsm");
var url = "http://www.sample.com/"; // URL文字列
Services.io.newURI(url, null, null); }}
-[[NetUtil.jsm - Mozilla | MDN>https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/NetUtil.jsm#newURI()]]
#highlight(javascript){{
Cu.import("resource://gre/modules/NetUtil.jsm");
var url = "http://www.sample.com/"; // URL文字列
NetUtil.newURI(url); }}
***nsIFileからnsIURIを作成
#highlight(javascript){{
Cu.import("resource://gre/modules/Services.jsm");
var file = new FileUtils.File(xxxx); // nsIFile
Services.io.newFileURI(file); }}
#highlight(javascript){{
Cu.import("resource://gre/modules/NetUtil.jsm");
var file = new FileUtils.File(xxxx); // nsIFile
NetUtil.newURI(file); }}
**[[タイトルバー左のアイコンを独自の物にする]]
**XPCOMを読み込む方法
[[SCRAPBLOG : XPCOM サービスへの頻繁なアクセスを効率化するテクニック>http://www.xuldev.org/blog/?p=566]]
**label の value を書き換えるときは setAttribute を使う
#highlight(XML){
<toolbarbutton>
<tooltip id="mytooltip">
<label value="test tooltip"/>
<label value=""/>
</tooltip>
</toolbarbutton>}
上のような xul で、
#highlight(javascript){
var tooltip = document.getElementById('mytooltip');
tooltip.lastChild.value = 'test message';}
みたいな事をしてみたら、Firefox 起動直後は大丈夫なのだが、ツールバーのカスタマイズ後では value がまったく書き換わらない状態になった。
(正確には、javascriptオブジェクトでは書き換わっているのだが、xulオブジェクトは書き換わっていない。)
#highlight(javascript){
tooltip.lastChild.setAttribute('value', 'test message');}
と、setAttribute を使用すると問題なく動く。
**イベント
-[[Mozilla event reference - Document Object Model (DOM) | MDN>https://developer.mozilla.org/en-US/docs/DOM/Mozilla_event_reference]]
-[[event - MDC Doc Center>https://developer.mozilla.org/ja/DOM/event]]
-[[element - MDC Doc Center>https://developer.mozilla.org/ja/DOM/element#Event_Handlers]]
-[[DOM Events - MDC Doc Center>https://developer.mozilla.org/ja/DOM_Events]]
-[[Gecko 固有の DOM Event - MDC Doc Center>https://developer.mozilla.org/ja/Gecko-Specific_DOM_Events]]
-[[Toolbar customization events - MDC Doc Center>https://developer.mozilla.org/en/XUL/Toolbars/Toolbar_customization_events]]
-[[Using Firefox 1.5 caching - MDN>https://developer.mozilla.org/ja/Using_Firefox_1.5_caching]]
-[[gBrowser/イベント]]
**SQLite
-[[Storage | MDN>https://developer.mozilla.org/en-US/docs/Storage]]
同期・基本
#highlight(javascript){{
// sql はSQL文
var Cu = Components.utils;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/FileUtils.jsm");
var file = FileUtils.getFile("ProfD", ["sample.sqlite"]);
var dbConn = Services.storage.openDatabase(file);
var statement = dbConn.createStatement(sql);
statement.execute();
statement.finalize();
dbConn.close();}}
同期・パラメーター設定と結果の取得
#highlight(javascript){{
var statement = dbConn.createStatement("SELECT * FROM table_name WHERE id = :row_id");
statement.params.row_id = 1234;
while (statement.executeStep()) {
let value = statement.row.column_name;
} }}