forked from avwo/whistle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu.html
121 lines (119 loc) · 3.38 KB
/
menu.html
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<script>
;(function() {
var config = window.whistleMenuConfig;
var list = [];
var networkListeners = [];
var rulesListeners = [];
var valuesListeners = [];
var handleOnLoad = function() {
timer = null;
list.forEach(emit);
list = null;
};
var timer = setTimeout(handleOnLoad, 12000);
function execListeners(listeners, options) {
listeners.forEach(function(fn) {
try {
fn(options)
} catch (e) {
console.error(e);
}
});
}
function emit(options) {
switch(options.type) {
case 'rules':
execListeners(rulesListeners, options);
break;
case 'values':
execListeners(valuesListeners, options);
break;
default:
execListeners(networkListeners, options);
}
}
window.onWhistleContextMenuClick = function(options) {
if (list) {
list.push(options);
} else {
emit(options);
}
};
var delayOnLoad = function() {
if (timer) {
setTimeout(handleOnLoad, 100);
clearTimeout(timer);
timer = null;
}
};
window.onload = delayOnLoad;
try {
window.addEventListener('load', delayOnLoad);
} catch (e) {}
var toast = {};
var modal = {};
window.whistleBridge = {
config: config,
modal: modal,
toast: toast,
addNetworkListener: function(l) {
if (typeof l === 'function' && networkListeners.indexOf(l) === -1) {
networkListeners.push(l);
}
},
removeNetworkListener: function(l) {
l = networkListeners.indexOf(l);
if (l !== -1) {
networkListeners.splice(l, 1);
}
},
removeAllNetworkListeners: function() {
networkListeners = [];
},
addRulesListener: function(l) {
if (typeof l === 'function' && rulesListeners.indexOf(l) === -1) {
rulesListeners.push(l);
}
},
removeRulesListener: function(l) {
l = rulesListeners.indexOf(l);
if (l !== -1) {
rulesListeners.splice(l, 1);
}
},
removeAllRulesListeners: function() {
rulesListeners = [];
},
addValuesListener: function(l) {
if (typeof l === 'function' && valuesListeners.indexOf(l) === -1) {
valuesListeners.push(l);
}
},
removeValuesListener: function(l) {
l = valuesListeners.indexOf(l);
if (l !== -1) {
valuesListeners.splice(l, 1);
}
},
removeAllValuesListeners: function() {
valuesListeners = [];
}
};
try {
window.initWhistleBridge = function(options) {
window.initWhistleBridge = function() {};
Object.keys(options.msgBox).forEach(function(name) {
toast[name] = options.msgBox[name];
});
window.whistleBridge.importSessions = options.importSessions;
window.whistleBridge.request = options.request;
window.whistleBridge.createRequest = options.createRequest;
window.whistleBridge.showModal = options.showModal;
window.whistleBridge.createModal = options.createModal;
window.whistleBridge.importRules = options.importRules;
window.whistleBridge.importValues = options.importValues;
};
window.parent.onPluginContextMenuReady(window);
} catch (e) {}
})();
</script>