Add no workey extension
This commit is contained in:
34
extension/content.js
Normal file
34
extension/content.js
Normal file
@@ -0,0 +1,34 @@
|
||||
const URL = `http://localhost:5000/download`;
|
||||
let lastRightClickCoords = { x: 0, y: 0 };
|
||||
|
||||
document.addEventListener("contextmenu", (event) => {
|
||||
lastRightClickCoords = { x: event.clientX, y: event.clientY };
|
||||
console.log("Right-click coordinates:", lastRightClickCoords);
|
||||
});
|
||||
|
||||
browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
||||
const { x, y } = lastRightClickCoords;
|
||||
let element = document.elementFromPoint(x, y);
|
||||
|
||||
while (element && element.tagName != "YTD-RICH-ITEM-RENDERER") {
|
||||
element = element.parentElement;
|
||||
}
|
||||
if (!element.tagName == "YTD-RICH-ITEM-RENDERER") {
|
||||
console.error("No video element found.");
|
||||
return;
|
||||
}
|
||||
|
||||
const link = element.querySelector("a#video-title-link").href;
|
||||
fetch(URL, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
link: link,
|
||||
}),
|
||||
}).then((res) => {
|
||||
console.log(res);
|
||||
res.json().then((data) => console.log(data));
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user