-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.html
executable file
·228 lines (204 loc) · 8.04 KB
/
popup.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<!doctype html>
<html>
<head>
<script src="scripts/debug.js"></script>
<script src="scripts/sha1.js"></script>
<script src="scripts/oauth.js"></script>
<script src="scripts/operalink.js"></script>
<script src="scripts/common.js"></script>
<script src="scripts/jquery-1.8.0.min.js"></script>
<script src="scripts/bootstrap.min.js"></script>
<link type="text/css" rel="stylesheet" href="css/style.css">
<link type="text/css" rel="stylesheet" href="css/bootstrap.min.css">
<title>
Test
</title>
</head>
<body style="margin: 10px;">
<section id="auth" style="display: none;">
<h3>Sync Open Tabs Configurations</h3>
<p><u>To start using this extension:</u></p>
<p>Specify <b>Computer name: </b> <input type="text" onblur="saveCompName();" id="compName" />
<a title="Computer name can not be empty" class="validation" id="compNameValidation">*</a></p>
<p><button class="button" id="getCodeBtn" onclick="getCode();">Get Opera Link verifier code*</button></p>
<p class="tip"><b>* you need to reopen this window</b></p>
<p>Enter the code you have got </p>
<p><b>Opera Link verifier code: </b><input id="verifyCode" type=text>
<a title="Access code can not be empty" class="validation" id="verifyCodeValidation">*</a></p>
<p>When you finish - <button class="button" id="verify" onclick="verify();" >Save Configuration</button></p>
</section>
<section id="main" style="display: none;">
<h3 style="display: inline;">This Computer: </h3><h3 style="display: inline;" id="hostname"></h3>
<p><u>Shared computers:</u></p>
<img id="loading" style="display: none;" align="center" src="images/loading_icon.gif" />
<!-- Error alerts -->
<div id="linkError" class="alert alert-error" style="display: none;">
<strong>Error!</strong> Opera Link error. Please try again later.
</div>
<!-- End error alerts -->
<!-- Info allerts -->
<div id="firstTimeLoad" class="alert alert-info" style="display: none;">
<strong>Information!</strong> You use this extension for the first time. It'll take one minute to create initial structure. Please reopen this window later.
</div>
<!-- End info alerts -->
<div class="accordion" id="sharedComputers" style="display: none;"></div>
</section>
</p class="copyleft"><a href="http://druss.pp.ua/sync-open-tabs">Help</a>
<script>
// storage
var storage = widget.preferences;
window.addEventListener('DOMContentLoaded', function() {
debug('in DOMContentLoaded');
opera.link.consumer('I7okXUU5r18G6gciEPdfVK5TuMwQxUle', 'MjKroTXaGClpNaJxzAAxxSNIMUXeuqCt');
checkLogin();
opera.extension.onmessage = function (e) {
switch(e.data.action) {
case 'authorized':
checkLogin();
break;
}
}
}, false);
function saveCompName() {
storage['compName'] = $('#compName').val();
}
function getCode() {
opera.extension.postMessage({ action: 'request_token'});
}
function checkLogin() {
var authorized = false;
var authSection = document.getElementById('auth');
var mainSection = document.getElementById('main');
if (opera.link.loadToken()) {
opera.link.testAuthorization(function(result) {
authorized = result;
authSection.style.display = "none";
mainSection.style.display = "inline";
var hostName = document.getElementById('hostname');
hostName.innerText = storage['compName'];
debug("Ready for loading data.");
loadData();
});
}
else {
authSection.style.display = "inline";
if (storage['compName'] != null)
{
var compName = document.getElementById('compName');
compName.value = storage['compName'];
}
mainSection.style.display = "none";
}
}
function verify() {
var isValid = true;
var compName = document.getElementById('compName');
var compNameValidation = document.getElementById('compNameValidation');
if (compName.value == '') {
compNameValidation.style.display = "inline";
isValid = false;
}
else {
compNameValidation.style.display = "none";
}
var verifyCodeValidation = document.getElementById('verifyCodeValidation');
if (verifyCode.value == '') {
verifyCodeValidation.style.display = "inline";
isValid = false;
}
else {
verifyCodeValidation.style.display = "none";
}
if (!isValid)
return;
var code = document.getElementById('verifyCode');
debug('ver ' + code.value);
opera.extension.postMessage({action: "verifier", verifier: code.value });
}
function loadData() {
$('#loading').show();
var tabList = document.getElementById('sharedComputers');
opera.link.notes.getAll(function(result) {
if (isError(result)) {
$('#loading').hide();
$('#linkError').show();
return;
}
var isCreated = false;
for (var i = 0; i < result.response.length; i++) {
if (result.response[i].properties.title == '_sync-tabs'
&& result.response[i].item_type == 'note_folder') {
debug('in _sync-tabs');
isCreated = true;
var childs = result.response[i].children;
if (childs == null) {
$('#firstTimeLoad').show();
$('#loading').hide();
return;
}
for (var j = 0; j < childs.length; j++) {
var urls = '';
var lines = childs[j].properties.content.split('\n');
var count = 0;
if (lines.length > 1) {
var urlList = '<ul>';
for (var k = 1; k < lines.length; k++) {
if (lines[k] != '') {
debug('line: ' + lines[k]);
urls += lines[k] + ';';
count++;
urlList += '<li><a href="#" onclick="openTab(\'' + lines[k] + '\')">' + lines[k] + "</a></li>";
}
}
urlList += '</ul>';
tabList.innerHTML += '<div class="accordion-group">'
+ '<div class="accordion-heading" style="height:30px;">'
+ '<a class="accordion-toggle" style="display: inline; position:relative; top:5px; left:0px;" data-toggle="collapse" data-parent="#sharedComputers" href="#collapse' + j + '" id="#collapse' + j + '"><i class="icon-plus" style="margin-right:5px;"></i>'
+ lines[0]
+ '</a>'
+ '<div class="pull-right">'
+ '<div class="btn-group" style="display: inline;">'
+ '<button class="btn btn-mini" onclick="openTabs(\'' + urls + '\', false)">Open all </button>'
+ '<button class="btn btn-mini dropdown-toggle" data-toggle="dropdown">'
+ '<span class="caret"></span>'
+ '</button>'
+ '<ul class="dropdown-menu pull-right">'
+ '<li><a href="#" onclick="openTabs(\'' + urls + '\', false)">Open all </a></li>'
+ '<li><a href="#" id="openTabs" onclick="openTabs(\'' + urls + '\', true)">Open all in group</a></li>'
+ '<li class="divider"></li>'
+ '<li><a href="#" onclick="deleteFolder(\'' + childs[j].id + '\', \'' + j + '\')"><i class="icon-trash"></i>Delete</a></li>'
+ '</ul>'
+ '</div>'
+ '</div>'
+ '</div>'
+ '<div id="collapse' + j + '" class="accordion-body collapse">'
+ '<div class="accordion-inner">' + urlList;
tabList.innerHTML += '</div></div></div>';
}
}
}
}
debug ("data loading finished!");
$('#loading').hide();
$('#sharedComputers').show();
if (!isCreated) {
$('#firstTimeLoad').show();
}
});
}
function openTab(url)
{
debug("opne url: " + url);
openTabs(url + ";", false);
}
function deleteFolder(item, num) {
opera.extension.postMessage({ action: 'deleteFolder', item: item });
debug('deleting folder' + num);
$('#collapse' + num).parent().remove();
}
function openTabs(urls, group) {
opera.extension.postMessage({ action: 'openTab', url: urls, isGroup: group });
}
</script>
</body>
</html>