-
Notifications
You must be signed in to change notification settings - Fork 73
/
popup.js
87 lines (73 loc) · 2.02 KB
/
popup.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
var app = angular.module('cors', ['ionic']);
app.controller('PopupCtrl', ['$scope', function($scope) {
$scope.active = false;
$scope.urls = [];
$scope.url = '';
$scope.exposedHeaders = '';
chrome.storage.local.get({'active': false, 'urls': [], 'exposedHeaders': ''}, function(result) {
$scope.active = result.active;
$scope.urls = result.urls;
$scope.exposedHeaders = result.exposedHeaders;
$scope.$apply();
$scope.$watch('active', function(newValue, oldValue) {
chrome.storage.local.set({'active': $scope.active});
chrome.extension.getBackgroundPage().reload();
});
$scope.$watch('exposedHeaders', function(newValue, oldValue) {
chrome.storage.local.set({'exposedHeaders': $scope.exposedHeaders});
chrome.extension.getBackgroundPage().reload();
});
$scope.$watch('urls', function(newValue, oldValue) {
chrome.storage.local.set({'urls': $scope.urls});
chrome.extension.getBackgroundPage().reload();
});
});
$scope.openInNewTab = function(url) {
chrome.tabs.create({ url: url });
};
$scope.addUrl = function() {
if($scope.url && $.inArray($scope.url, $scope.urls) == -1) {
$scope.urls.unshift($scope.url);
}
$scope.url = '';
};
$scope.removeUrl = function(index) {
$scope.urls.splice(index, 1);
};
}]);
app.directive("textOption", function() {
return {
restrict: 'E',
scope: {
option: '=',
placeholder: '@'
},
templateUrl: 'text-option.html',
controller : function($scope) {
$scope.editing = false;
$scope.onEdit = function() {
$scope.editableOption = $scope.option;
$scope.editing = true;
};
$scope.onCancel = function() {
$scope.editing = false;
};
$scope.onSave = function() {
$scope.option = $scope.editableOption;
$scope.editing = false;
};
}
};
});
app.directive('submitOnEnter', function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
$(element).on('keydown', function(e) {
if (e.which == 13) {
$(element).parents('.item').find('.submit-action').trigger('click');
}
});
}
};
});