-
Notifications
You must be signed in to change notification settings - Fork 1
/
popup.js
57 lines (44 loc) · 1.72 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
function saveCredentials(username, repo, token, fileName) {
chrome.storage.local.set({
username: username,
repo: repo,
token: token,
});
}
function loadCredentials() {
chrome.storage.local.get(["username", "repo", "token"], function (result) {
const username = result.username || "";
const repo = result.repo || "";
const token = result.token || "";
document.getElementById("username").value = username;
document.getElementById("repo").value = repo;
document.getElementById("token").value = token;
});
}
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
var currentURL = tabs[0].url;
var urlPattern = /^https:\/\/leetcode\.com\/submissions\/detail\/\d*\/?$/;
console.log(urlPattern.test(currentURL))
if (urlPattern.test(currentURL)) {
document.getElementById(
"popupContent"
).innerHTML = `<label for="username">GitHub Username:</label>
<input type="text" id="username" />
<label for="repo">GitHub Repository:</label>
<input type="text" id="repo" />
<label for="token">Personal Access Token:</label>
<input type="text" id="token" />
<button id="commitButton">Commit to GitHub</button>`;
loadCredentials();
document
.getElementById("commitButton")
.addEventListener("click", function () {
const username = document.getElementById("username").value;
const repo = document.getElementById("repo").value;
const token = document.getElementById("token").value;
saveCredentials(username, repo, token);
console.log(username, repo, token);
chrome.tabs.executeScript(tabs[0].id, { file: "content.js" });
});
}
});