Made work

This commit is contained in:
Benjamyn Love 2020-06-13 16:47:47 +10:00
parent a27898c41b
commit 5417618084
3 changed files with 57 additions and 14 deletions

View File

@ -1,7 +1 @@
function openPage() { // console.log(document.querySelector(".video-stream").getCurrentTime());
browser.tabs.create({
url: "https://youtube.com"
});
}
browser.browserAction.onClicked.addListener(openPage);

View File

@ -1,5 +1,4 @@
{ {
"manifest_version": 2, "manifest_version": 2,
"name": "Upto", "name": "Upto",
"version": "0.1", "version": "0.1",
@ -9,6 +8,16 @@
"icons": { "icons": {
"48": "icons/48.png" "48": "icons/48.png"
}, },
"background": {
"scripts": ["background.js"]
},
"content_scripts": [
{
"matches": ["*://*.youtube.com/*"],
"js": ["test.js"]
}
],
"permissions": ["*://home.lovelynet.net/*", "webRequest"],
"browser_action": { "browser_action": {
"browser_style": true, "browser_style": true,
"default_popup": "popup/choose.html", "default_popup": "popup/choose.html",

40
test.js Normal file
View File

@ -0,0 +1,40 @@
function getTime() {
// Youtube can get fucked, this is the worst way I can get this to work -_-
// console.log("Why does this not fucking work");
let url = window.location.href;
let d = document.querySelector(".video-stream");
return url + "&t=" + Math.ceil(d.currentTime);
}
function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
async function getTitleHTMLElement() {
await sleep(2000);
let test = document.querySelector("ytd-video-primary-info-renderer");
return test;
}
function postURL(url) {
console.log(url);
fetch("https://home.lovelynet.net/testingapi/", {
method: "POST",
body: JSON.stringify({
url: url,
authcode: "VGhlIGF1dGhjb2RlIGlzIHRoZSBhdXRoY29kZQ==",
}),
})
.then((resp) => resp.text())
.then((data) => console.log(data))
.catch((err) => console.log(err));
}
ele = document.createElement("p");
text = document.createTextNode("Save Timestamp");
ele.addEventListener("click", () => postURL(getTime()));
ele.appendChild(text);
getTitleHTMLElement().then((data) => data.appendChild(ele));
// setInterval(getTime, 10);
console.log(test);