設定說明
在 Noise 編輯視窗的「事件」欄位,通常只會填上 topic 或 event type 字串,例如 dblclick
可以捕捉「點兩下滑鼠」的事件。
而事件過濾就是在其後加上 &
與事件處理式,
這樣在事件發生時,就會評估處理式的結果,如果是 true 才發出聲音,
例如,dblclick&event['target'].tagName=='H1'
會檢查被點選的對象(target)是不是 H1 元素,是的話發出聲音,否則就沒反應。
在 Noise 1.0 內部,前述的 &
與事件處理式
會變成名為 filtertFx
的函數,在事件發生時執行,
這時與事件相關的參數(event 或者是 subject, data)會傳入 filtertFx,成為可供使用者操作的資料。
更加具體的細節如下:
若事件類型為「事件主題 - 由 addObserver」則 Noise 1.0 內部的相關程式碼是:
observe: function(subject, topic, data) {
try {
if( filtertFx(subject,data) ) Noise.play( i['se'] );
} catch(e) { dump('Noise: '+e); }
}
subject, data 的意義可參考 nsIObserver - MDC;
事實上根據 topic 不同,參數的內容也不同,請參考 Global Notifications 等;
Noise 特有的事件主題,其參數內容請參考 Noise 特有事件主題。
若事件類型為「瀏覽器事件 - 由 gBrowser.addEventListener」或「視窗事件 - 由 window.addEventListener」,則相關程式碼是:
this.listeners[i['urn']] = function(event) {
try {
if( filtertFx(event) ) Noise.play( i['se'] );
} catch(e) { dump('Noise: '+e); }
}
event 規格請參考 DOM-Level-2-Events。
更多資料可於 event - MDC 或 Comparison of Event Targets 找到。
Noise 特有事件主題
主題 | Subject | Data | 簡介 |
---|---|---|---|
noise-TypeAheadFind.FIND_WRAPPED | null | aFindPrevious | aFindPrevious 為 true 或 false,true 表示往回尋找(找上一筆) |
noise-toggleSidebar | null | commandID | commandID 為側邊欄的指令 id,例如開啟歷史欄時是 viewHistorySidebar |
noise-alert-loaded | null | null | |
noise-WebProgress-start | aReq | aStatus | aReq 是一個 nsIRequest 物件,參考 nsIWebProgressListener |
noise-WebProgress-stop | aReq | aStatus | aReq 是一個 nsIRequest 物件,參考 nsIWebProgressListener |
noise-WebProgress-locationChange | aLocation | aLocation.spec | aLocation 是一個 nsIURI 物件,參考 nsIWebProgressListener |
noise-dl.addnew | dl | null | dl 是當時的 Download 物件,參考 DownloadList#addView 中的 onDownloadAdded |
noise-dl.removenew | dl | null | dl 是當時的 Download 物件,參考 DownloadList#addView 中的 onDownloadRemoved |
noise-dl.stopnew | dl | status | dl 是當時的 Download 物件,參考 DownloadList#addView 中的 onDownloadChanged; data 代表停止時的下載狀態,值是 'succeeded'、'canceled'、'stopped' 其中之一 |
noise-dl.errornew | dl | error | dl 是當時的 Download 物件,參考 DownloadList#addView 中的 onDownloadChanged; data 為 error 物件的 result,參考 DownloadError |
使用範例
類型: 1 = 事件主題 2 = 瀏覽器事件 3 = 視窗事件
註:範例在較舊版本的 Noise 上不一定有效。
名稱 | 事件字串 | 類型 | 簡介 |
---|---|---|---|
404 找不到網頁 | noise-WebProgress-stop&subject.QueryInterface(Components.interfaces.nsIHttpChannel).responseStatus=='404' | 1 | 404 錯誤,找不到網頁 |
404 找不到資源 | http-on-examine-response&subject.QueryInterface(Components.interfaces.nsIHttpChannel).responseStatus=='404' | 1 | 每次得到 404 回應時 |
找不到網址 | noise-WebProgress-stop&data==0x804B001E | 1 | 找不到網址(伺服器) |
連線失敗 | noise-WebProgress-stop&data==0x804B000D | 1 | 無法與伺服器建立連線,不過網址似乎是正確的 |
已知的有害網站! | noise-WebProgress-stop&data==0x805D001E | 1 | 錯誤:NS_ERROR_MALWARE_URI |
進入隱私瀏覽模式 | private-browsing&data=='enter' | 1 | 以 exit 取代 enter 可捕捉「離開」隱私瀏覽模式事件 |
編輯加入書籤 | popupshowing&event.target.id=='editBookmarkPanel' | 3 | 新增書籤時顯示的面板 |
載入特定網址 | DOMContentLoaded&event.target.baseURI=='http://127.0.0.1/' | 2,3 | 網址部分可自行代換 |
特定資訊列通知 | AlertActive&event.originalTarget.value=='popup-blocked' | 2,3 | 也可嘗試 xpinstall、xpinstall-disabled、 blocked-plugins、missing-plugins、 refresh-blocked、offline-app-usage |
安裝附加元件 | em-action-requested&data=='item-installed' | 1 | 也可嘗試 item-uninstalled、 item-enabled、item-disabled、 item-upgraded、item-cancel-action |
Google Reader 發現未讀項目 | DOMAttrModified&event.target.id=='reading-list-unread-count'&&event.prevValue=='unread-count hidden' | 3 | 已開啟 Google Reader 網頁,且「所有項目 (4)」的數字部分出現時 |
尋找已達頁尾 | noise-TypeAheadFind.FIND_WRAPPED&data=='false' | 1 | 反之(返回最後一項)就不會發生 |
開啟書籤側邊欄 | noise-toggleSidebar&data=='viewBookmarksSidebar' | 1 | |
發現 OpenSearch 搜尋引擎 | DOMLinkAdded&event.target.rel=='search'&&event.target.type=='application/opensearchdescription+xml' | 2,3 | 即使已安裝,仍會每次發生 |
SearchWP 搜尋按鈕選單 | AlertActive&event.originalTarget.getAttribute('anonid')=='tokens-menu-popup' | 3 | |
開啟 FoxAge2ch 側邊欄 | noise-toggleSidebar&data=='viewFoxage2chSidebar' | 1 | |
FoxAge2ch 錯誤通知 | foxage2ch-global&data=='error-notify' | 1 | |
FoxAge2ch 檢查完畢 | foxage2ch-global&data=='finish-checking' | 1 | |
FoxAge2ch 新增訂閱 | foxage2ch-show-message&data=='(・∀・)完了' | 1 | |
dblclick 關閉尋找列 | dblclick&event.button=='2'&&!gFindBar.hidden&&(gFindBar.close()||true) | 2 | 連按兩下滑鼠右鍵(Windows),關閉尋找列 |