-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.js
More file actions
112 lines (105 loc) · 3.55 KB
/
Copy pathoptions.js
File metadata and controls
112 lines (105 loc) · 3.55 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
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
// Saves options to chrome.storage.sync.
function save_options() {
const labels = document.getElementById("labels").value;
const owner = document.getElementById("owner").value;
const repository = document.getElementById("repository").value;
const oauthToken = document.getElementById("oauthToken").value;
const debug = document.getElementById("debug").checked;
// clean callback message
document.querySelector("#testConfig").textContent = "";
chrome.storage.sync.set(
{
labels: labels,
owner: owner,
repository: repository,
oauthToken: oauthToken,
debug: debug
},
function() {
// Update status to let user know options were saved.
var status = document.querySelector("#status");
status.textContent = "Options saved.";
setTimeout(function() {
status.textContent = "";
}, 1000);
// test config
updateTestConfig("Testing your configuration");
chrome.runtime.sendMessage({ action: "pingAPI" }, function(response) {
if (response === VALID_CONFIG) {
updateTestConfig("You're all setup!");
chrome.browserAction.enable();
setTimeout(function() {
updateTestConfig();
}, 5000);
} else if (response === BAD_CONFIG) {
updateTestConfig(
"API reached, but can't find your repository ; plz check your configuration."
);
chrome.browserAction.disable();
} else if (response === INVALID_TOKEN) {
updateTestConfig(
"API can't be reach, you probably have a pb with your token"
);
chrome.browserAction.disable();
} else {
log("wtf", response);
}
});
}
);
}
// Restores select box and checkbox state using the preferences
// stored in chrome.storage.
function restore_options() {
chrome.storage.sync.get(
{
labels: "",
owner: "",
repository: "",
oauthToken: "",
debug: false
},
function(items) {
document.getElementById("labels").value = items.labels;
document.getElementById("owner").value = items.owner;
document.getElementById("repository").value = items.repository;
document.getElementById("oauthToken").value = items.oauthToken;
document.getElementById("debug").checked = items.debug;
}
);
}
document.addEventListener("DOMContentLoaded", restore_options);
document.getElementById("save").addEventListener("click", save_options);
const testKey = () => {
getParameters(config => {
call(
getRateLimitQuery(),
config.oauthToken,
response => {
if (!response.errors) {
const data = response.data;
const resetDate = new Date(data.rateLimit.resetAt);
updateTestConfig(`RateLimit remaining:
${data.rateLimit.remaining}/${data.rateLimit.limit} for
user: ${data.viewer.login}
reset at: ${resetDate.toUTCString()}.`);
} else {
updateTestConfig("[testKey] a problem happen with github API");
}
},
errorReason => {
log("[testKey] error with reason: ", errorReason);
error(errorReason);
}
);
});
};
document.getElementById("testKey").addEventListener("click", testKey);
const testConfig = document.querySelector("#testConfig");
const updateTestConfig = (text = "") => {
if (testConfig) testConfig.textContent = text;
};
document.querySelector("#dev legend").addEventListener("click", () => {
const fieldset = document.querySelector("#dev");
fieldset.className = !fieldset.className ? "open" : "";
});