-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontent.ts
80 lines (73 loc) · 2.63 KB
/
content.ts
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
import type { PlasmoCSConfig } from "plasmo";
export {};
export const config: PlasmoCSConfig = {
run_at: "document_end",
matches: ["*://*.freshrelease.com/*"],
world: "MAIN"
};
let interval;
(async () => {
const permissionStatus = await navigator.permissions.query({
name: "clipboard-read",
allowWithoutGesture: false
});
// Will be 'granted', 'denied' or 'prompt':
console.log(permissionStatus.state);
// Listen for changes to the permission state
permissionStatus.onchange = () => {
console.log(permissionStatus.state);
};
})();
//run function on dom changes
export function run() {
const link = document.createElement("link");
link.rel = "stylesheet";
link.href =
"https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@48,400,0,0";
document.querySelector("head").appendChild(link);
interval = setInterval(() => {
const newElements = document.querySelectorAll("div[class='pull-right']");
if (newElements.length > 0) {
clearInterval(interval);
newElements.forEach((element) => {
const newElement = document.createElement("span");
newElement.classList.add("text--sec-color");
newElement.classList.add("text--ultra-semibold");
newElement.classList.add("material-symbols-outlined");
newElement.style.color = "#4766C3";
newElement.style.backgroundColor = "white";
newElement.style.padding = "0.1rem";
newElement.style.borderRadius = "0.1rem";
newElement.onclick = async () => {
const listOfTasks =
element.parentElement.nextElementSibling.children[0].children || [];
let tasks = [];
for (let i = 0; i < listOfTasks.length; i++) {
const task = listOfTasks[i];
const name = task.querySelector("figure")?.children?.[0]?.ariaLabel;
const texts = listOfTasks[i].textContent
.split("\n")
.map((e) => e.trim())
.filter(Boolean);
tasks.push(
`${texts[0]} - ${texts[1]}` + (name ? ` - ${name}` : "")
);
}
try {
await window.navigator.clipboard.writeText(tasks.join("\n"));
alert("Copied to clipboard");
} catch (error) {
console.log(error);
alert(
"No permission to access clipboard. Please allow access to clipboard in the browser settings. (Chrome: chrome://settings/content/clipboard)"
);
}
// copy(tasks)
};
newElement.innerHTML = `content_copy`;
element.appendChild(newElement);
});
}
}, 1000);
}
run();