This repository has been archived by the owner on Jun 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathswitch.js
60 lines (51 loc) · 1.79 KB
/
switch.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
var main = function () {
var menu = document.getElementById('menu');
var none = document.getElementById('none');
chrome.storage.sync.get('my_projects', function (obj) {
var projects = obj.my_projects;
for (name in projects) {
if (name != 'my_current_project') {
var a = document.createElement('a');
var linkText = document.createTextNode(name);
a.appendChild(linkText);
a.href = "#";
a.id = name;
if (name === projects.my_current_project) {
a.className = "choice selected";
none.className = "choice";
}
else {
a.className = "choice";
}
a.onclick = function (event) {
oldProj = document.getElementById(projects.my_current_project);
oldProj.className = "choice";
none.className = "choice";
event.target.className = "choice selected";
projects.my_current_project = event.target.id;
chrome.storage.sync.set({'my_projects': projects});
};
menu.appendChild(a);
var d = document.createElement('li');
d.className = "divider";
menu.appendChild(d);
}
}
});
var newProj = document.getElementById('newProject');
newProj.onclick = newProject;
none.onclick = function (event) {
chrome.storage.sync.get('my_projects', function (obj) {
var projects = obj.my_projects || {};
oldProj = document.getElementById(projects.my_current_project);
oldProj.className = "choice";
event.target.className = "choice selected";
projects.my_current_project = 'none';
chrome.storage.sync.set({'my_projects': projects});
});
}
}
var newProject = function () {
window.location.replace("new_project.html");
}
document.addEventListener('DOMContentLoaded', main);