-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpopup.js
More file actions
85 lines (65 loc) · 1.87 KB
/
popup.js
File metadata and controls
85 lines (65 loc) · 1.87 KB
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
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
'use strict';
let submit = document.getElementById('button-saved');
let regHost = document.getElementById('input-reg-host');
let regPath = document.getElementById('input-reg-path');
//let textarea = document.getElementById('textarea-script');
// pass options to ace.edit
var editor = ace.edit("editor", {
mode: "ace/mode/javascript",
selectionStyle: "text"
})
// use setOptions method to set several options at once
editor.setOptions({
autoScrollEditorIntoView: true,
copyWithEmptySelection: true,
});
editor.setTheme("ace/theme/monokai");
function getNdN(hostname)
{
return hostname.split('.').slice(-2).join('.')
}
let ndn = null;
let ndnScripts = null;
chrome.tabs.query({
active: true,
lastFocusedWindow: true
}, function(tabs) {
// and use that tab to fill in out title and url
var tab = tabs[0];
const url = new URL(tab.url);
ndn = getNdN(url.hostname);
chrome.storage.sync.get([ndn], function(data) {
if(!data[ndn])
{
ndnScripts = [{
regHost:url.hostname,
regPath:'*',
code:''
}];
} else {
ndnScripts = JSON.parse(data[ndn]);
}
editor.setValue(ndnScripts[0].code);
regHost.value = ndnScripts[0].regHost;
regPath.value = ndnScripts[0].regPath;
});
});
function saveCode()
{
ndnScripts[0].regHost = regHost.value;
ndnScripts[0].regPath = regPath.value;
ndnScripts[0].code = editor.getValue();
let obj = {};
obj[ndn] = JSON.stringify(ndnScripts);
chrome.storage.sync.set(obj, function() {
console.log(ndn, '=>', ndnScripts);
});
}
window.onblur = saveCode;
// some options are also available as methods e.g.
//editor.setTheme(...)
// to get the value of the option use
//editor.getOption("optionName");