-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
59 lines (54 loc) · 2.01 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
const problemName = document.getElementById("problemNameButton");
const problemSkeleton = document.getElementById("problemSkeletonButton");
problemName.addEventListener("click", function () {
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
chrome.tabs.sendMessage(tabs[0].id, { action: "grabProblemName" });
});
});
problemSkeleton.addEventListener("click", function () {
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
chrome.tabs.sendMessage(tabs[0].id, { action: "grabProblemSkeleton" });
});
});
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
if (request.data) {
const data = request.data;
document.body.focus();
navigator.clipboard.writeText(data).then(() => {
let element =
request.type === "problemName"
? problemName
: request.type === "problemSkeleton"
? problemSkeleton
: null;
if (!element) return;
const originalText = element.textContent;
element.textContent = "Copied!";
setTimeout(() => {
element.textContent = originalText;
}, 2500);
});
}
});
async function validateVersion() {
const response = await fetch(
"https://raw.githubusercontent.com/zhao-stanley/leetcode-problem-grabber/main/manifest.json"
);
const json = await response.json();
let officialVersion = json.version;
let localVersion = chrome.runtime.getManifest().version;
if (officialVersion !== localVersion) {
let a = document.createElement("a");
a.href =
"https://github.com/zhao-stanley/leetcode-problem-grabber/archive/refs/heads/main.zip";
a.target = "_blank";
a.innerText = `v${localVersion} (Update Available)`;
a.className = "text-red-500";
return document.getElementById("version").appendChild(a);
}
return (document.getElementById("version").innerText = `v${localVersion}`);
}
validateVersion();
// document.getElementById("version").innerText = `v${
// // chrome.runtime.getManifest().version
// }`;