-
Notifications
You must be signed in to change notification settings - Fork 123
/
000-windowhook.uc.js
56 lines (51 loc) · 1.45 KB
/
000-windowhook.uc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// ==UserScript==
// @name WindowHook
// @namespace http://forums.mozillazine.org/
// @description
// @include main
// ==/UserScript==
/* :::::::: WindowHook ::::::::::::::: */
var WindowHook = {
observe: function(aSubject, aTopic, aData)
{
if (!aSubject._WindowHook)
{
aSubject._WindowHook = this;
aSubject.addEventListener("load", this.onLoad_window, false);
}
},
onLoad_window: function()
{
this.removeEventListener("load", this._WindowHook.onLoad_window, false);
var funcs = this._WindowHook.mFuncs[this.document.location.href] || null;
if (funcs)
{
funcs.forEach(function(aFunc) { aFunc(this); }, this);
}
delete this._WindowHook;
},
register: function(aURL, aFunc)
{
if (!this.mFuncs)
{
this.mFuncs = {};
Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService).addObserver(this, "domwindowopened", false);
}
if (!this.mFuncs[aURL])
{
this.mFuncs[aURL] = [];
}
this.mFuncs[aURL].push(aFunc);
}
};
window.addEventListener("unload",function() {
try{
Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService).removeObserver(WindowHook, "domwindowopened");
}catch(e){}
try{
delete WindowHook.register;
delete WindowHook.onLoad_window;
delete WindowHook.observe;
delete WindowHook.mFuncs;
}catch(e){}
},false);