-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent_script.js
42 lines (36 loc) · 1.25 KB
/
content_script.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
//content script
var activeTarget;
var contextMenuIsOpen = false;
function addEvent( obj, type, fn ) {
if ( obj.attachEvent ) {
obj['e'+type+fn] = fn;
obj[type+fn] = function(){obj['e'+type+fn]( window.event );};
obj.attachEvent( 'on'+type, obj[type+fn] );
} else
obj.addEventListener( type, fn, false );
}
var contextMenuEventFunc = function(event) {
activeTarget = event.target;
// console.log('right-clicked (contextmenu)', event.target);
// add activeTarget identifier class
activeTarget.classList.add('specialWebSpeechClass');
var contextMenuIsOpen = true;
};
var contextMenuExitEventFunc = function(event) {
if(contextMenuIsOpen){
// remove active target identifier class
var theSpeechTargets = document.querySelectorAll('.specialWebSpeechClass');
if(theSpeechTargets.length>0){
[].forEach.call(theSpeechTargets, function(obj, idx){
obj.classList.remove('specialWebSpeechClass');
});
}
}
};
var theTargets = document.querySelectorAll('input');
for(var i = 0; i<theTargets.length; i++){
// add contextmenu event listener to theTargets
addEvent(theTargets[i], 'contextmenu', contextMenuEventFunc);
}
addEvent(window, 'blur', contextMenuExitEventFunc);
//console.log('content scripts loaded');