-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.js
More file actions
71 lines (63 loc) · 1.73 KB
/
options.js
File metadata and controls
71 lines (63 loc) · 1.73 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
var replyApp = angular.module("replyApp", []);
replyApp.controller("OptionsController", ["$scope", function ($scope) {
angular.element(document).ready(function () {
$scope.retrieveStorage();
});
$scope.savePasta = function(tag, pasta) {
chrome.storage.sync.set(createObj(tag, pasta), $scope.retrieveStorage);
};
$scope.retrieveStorage = function() {
chrome.storage.sync.get(null, function(items) {
console.log(items);
$scope.tags = Object.keys(items);
$scope.tags.sort();
$scope.items = items;
$scope.$apply();
});
};
$scope.addPasta = function() {
if ($scope.newTag && $scope.newPasta) {
var t = $scope.newTag.toUpperCase();
var p = $scope.newPasta;
chrome.storage.sync.get(t, function(items) {
if (Object.keys(items).length === 0) {
var pasta = [];
pasta.push(p);
$scope.savePasta(t, pasta);
} else {
items[t].push(p);
$scope.savePasta(t, items[t]);
}
});
$scope.newPasta = "";
$scope.newTag = "";
}
};
$scope.deletePasta = function(tag, pasta) {
chrome.storage.sync.get(tag, function(items) {
var pastas = items[tag];
var arrayLength = pastas.length;
for (i = 0; i < arrayLength; i++) {
if (pasta === pastas[i]) {
pastas.splice(i,1);
}
}
if (pastas.length === 0) {
$scope.deleteTag(tag);
} else {
$scope.savePasta(tag, pastas);
}
});
};
$scope.deleteTag = function(tag) {
chrome.storage.sync.remove(tag, function() {
$scope.retrieveStorage();
});
};
}]);
function createObj(tag, pastas) {
var obj = {};
obj[tag] = pastas;
console.log(obj);
return obj;
}