-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcontent.js
119 lines (108 loc) · 5.31 KB
/
content.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
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
var EEXCESS = EEXCESS || {};
/**
* Flag for indicating the widget's current visibility state
* @memberOf EEXCESS
* @type Boolean
*/
EEXCESS.widgetVisible = false;
/**
* Changes the widget's visibility to the provided value.
* When the widget is to be shown, the width of the current page is reduced
* by the widget's width and the widget is displayed at the right border.
* Upon hiding the widget, the size limits for the current page are reset.
* @memberOf EEXCESS
* @param {Boolean} visible
*/
EEXCESS.handleWidgetVisibility = function(visible) {
if (EEXCESS.widgetVisible !== visible) {
if (visible) { // show widget
// var width = $(window).width() - 333;
$('#eexcess_sidebar').show('fast');
$('#eexcess_toggler').css('background-image', 'url(chrome-extension://' + EEXCESS.utils.extID + '/media/icons/hide.png)').show();
// $('#eexcess_sidebar').show();
// $('html').css('overflow', 'auto').css('position', 'absolute').css('height', '100%').css('width', width + 'px');
// $('body').css('overflow-x', 'auto').css('position', 'relative').css('overflow-y', 'scroll').css('height', '100%');
} else { // hide widget
$('#eexcess_toggler').css('background-image', 'url(chrome-extension://' + EEXCESS.utils.extID + '/media/icons/show.png)').hide();
$('#eexcess_sidebar').hide('fast');
// $('#eexcess_sidebar').hide();
// $('html').css('overflow', '').css('position', '').css('height', '').css('width', '');
// $('body').css('overflow-x', '').css('position', '').css('overflow-y', '').css('height', '');
}
EEXCESS.widgetVisible = visible;
}
};
/*
* Adds the eexcess widget as an iframe, calls the background script with
* visibility handler as callback, to determine the current state of
* visibility in the background's model.
*/
$('<iframe id="eexcess_sidebar" src="chrome-extension://' + EEXCESS.utils.extID + '/widget/widget.html" style="border-left:1px solid gray"></iframe>').appendTo('body');
$('<div id="eexcess_toggler"></div>').appendTo('body').click(function() {
if ($('#eexcess_sidebar').is(':visible')) {
$('#eexcess_sidebar').hide('fast');
$('#eexcess_toggler').css('background-image', 'url(chrome-extension://' + EEXCESS.utils.extID + '/media/icons/show.png)');
} else {
$('#eexcess_sidebar').show('fast');
$('#eexcess_toggler').css('background-image', 'url(chrome-extension://' + EEXCESS.utils.extID + '/media/icons/hide.png)');
}
});
//$('<div id="eexcess_button"><img src="chrome-extension://' + EEXCESS.utils.extID + '/media/icons/page_curl2.png" /></div>').mouseenter(function(){
// if($('#eexcess_sidebar').is(':visible')) {
// $('#eexcess_sidebar').hide('fast');
// } else {
// $('#eexcess_sidebar').show('fast');
// }
//}).appendTo('body');
//$('<div id="eexcess_invisible" style="position:fixed;width:5px;height:100%;top:20px;right:0px;background-color:red;z-index:10100"></div>').mouseenter(function(){
//// if($('#eexcess_sidebar').is(':visible')) {
//// $('#eexcess_sidebar').hide('fast');
//// } else {
//// $('#eexcess_sidebar').show('fast');
//// }
// $('#eexcess_sidebar').hide('fast');
// $('#eexcess_button').show();
//}).appendTo('body');
EEXCESS.messaging.callBG({method: {parent: 'model', func: 'visibility'}}, EEXCESS.handleWidgetVisibility);
// Listen to messages from the background script
EEXCESS.messaging.listener(
function(request, sender, sendResponse) {
switch (request.method) {
case 'visibility':
// change widget's visibility
EEXCESS.handleWidgetVisibility(request.data);
break;
case 'privacySandbox':
// change widget's visibility
EEXCESS.handlePrivacyBoxVisibility(request.data);
break;
case 'fancybox':
// open fancybox preview of the url provided in request.data
$('<a href="' + request.data + '"></a>').fancybox({
'autoSize': false,
'type': 'iframe',
'width': '90%',
'height': '90%'
}).trigger('click');
break;
case 'getTextualContext':
sendResponse({selectedText: document.getSelection().toString(), url: document.URL});
break;
}
}
);
/*
* privacy initialization stuff
*/
EEXCESS.handlePrivacyBoxVisibility = function() {
var visible = !$('#eexcess_privacy').is(':visible');
if (EEXCESS.privacyVisible !== visible) {
if (visible) {
$('#eexcess_privacy').show();
} else {
$('#eexcess_privacy').hide();
}
EEXCESS.privacyVisible = visible;
}
};
$('<div style="border: 0; margin:0; padding: 0; display:none; position:fixed; bottom: 100px; right: 349px; width: 40%; height: 60%;" id="eexcess_privacy"><iframe style="border: 0; width:100%; height: 100%" id="eexcess_privacy_frame" src="chrome-extension://' + EEXCESS.utils.extID + '/privacy/policy.html"></iframe></div>').appendTo('body');