返回 Noise icon Noise: Firefox 附加元件 English ver.

事件過濾

  • more info 請注意,胡亂設定很可能造成麻煩(例如讓 Firefox 當機),直接在 使用範例 中挑選項目會比較保險。
  • more info 進階使用者,或者您真的想要胡亂設定,請繼續閱讀 設定說明

設定說明

在 Noise 編輯視窗的「事件」欄位,通常只會填上 topicevent 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 - MDCComparison of Event Targets 找到。


Noise 特有事件主題

Noise 特有事件主題
主題SubjectData簡介
noise-TypeAheadFind.FIND_WRAPPEDnullaFindPreviousaFindPrevious 為 truefalse,true 表示往回尋找(找上一筆)
noise-toggleSidebarnullcommandIDcommandID 為側邊欄的指令 id,例如開啟歷史欄時是 viewHistorySidebar
noise-alert-loadednullnull
noise-WebProgress-startaReqaStatusaReq 是一個 nsIRequest 物件,參考 nsIWebProgressListener
noise-WebProgress-stopaReqaStatusaReq 是一個 nsIRequest 物件,參考 nsIWebProgressListener
noise-WebProgress-locationChangeaLocationaLocation.specaLocation 是一個 nsIURI 物件,參考 nsIWebProgressListener
noise-dl.addnewdlnulldl 是當時的 Download 物件,參考 DownloadList#addView 中的 onDownloadAdded
noise-dl.removenewdlnulldl 是當時的 Download 物件,參考 DownloadList#addView 中的 onDownloadRemoved
noise-dl.stopnewdlstatusdl 是當時的 Download 物件,參考 DownloadList#addView 中的 onDownloadChanged;
data 代表停止時的下載狀態,值是 'succeeded''canceled''stopped' 其中之一
noise-dl.errornewdlerrordl 是當時的 Download 物件,參考 DownloadList#addView 中的 onDownloadChanged;
data 為 error 物件的 result,參考 DownloadError

使用範例

類型: 1 = 事件主題 2 = 瀏覽器事件 3 = 視窗事件

註:範例在較舊版本的 Noise 上不一定有效。

Noise 事件過濾 - 使用範例
名稱事件字串類型簡介
404 找不到網頁noise-WebProgress-stop&subject.QueryInterface(Components.interfaces.nsIHttpChannel).responseStatus=='404'1404 錯誤,找不到網頁
404 找不到資源http-on-examine-response&subject.QueryInterface(Components.interfaces.nsIHttpChannel).responseStatus=='404'1每次得到 404 回應時
找不到網址noise-WebProgress-stop&data==0x804B001E1找不到網址(伺服器)
連線失敗noise-WebProgress-stop&data==0x804B000D1無法與伺服器建立連線,不過網址似乎是正確的
已知的有害網站!noise-WebProgress-stop&data==0x805D001E1錯誤:NS_ERROR_MALWARE_URI
進入隱私瀏覽模式private-browsing&data=='enter'1exit 取代 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 也可嘗試 xpinstallxpinstall-disabled
blocked-pluginsmissing-plugins
refresh-blockedoffline-app-usage
安裝附加元件em-action-requested&data=='item-installed'1 也可嘗試 item-uninstalled
item-enableditem-disabled
item-upgradeditem-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),關閉尋找列

其他參考資源