diff --git a/background.js b/background.js index bcb4dca..237f785 100644 --- a/background.js +++ b/background.js @@ -1,7 +1 @@ -function openPage() { - browser.tabs.create({ - url: "https://youtube.com" - }); -} - -browser.browserAction.onClicked.addListener(openPage); +// console.log(document.querySelector(".video-stream").getCurrentTime()); diff --git a/manifest.json b/manifest.json index df0f7bf..a5bc695 100644 --- a/manifest.json +++ b/manifest.json @@ -1,19 +1,28 @@ { - "manifest_version": 2, "name": "Upto", "version": "0.1", - + "description": "Uploads the URL+timestamp to the uptoserver", "icons": { "48": "icons/48.png" }, + "background": { + "scripts": ["background.js"] + }, + "content_scripts": [ + { + "matches": ["*://*.youtube.com/*"], + "js": ["test.js"] + } + ], + "permissions": ["*://home.lovelynet.net/*", "webRequest"], "browser_action": { - "browser_style": true, - "default_popup": "popup/choose.html", - "default_icon": { - "16": "icons/48.png" - } + "browser_style": true, + "default_popup": "popup/choose.html", + "default_icon": { + "16": "icons/48.png" + } } } diff --git a/test.js b/test.js new file mode 100644 index 0000000..43d40f0 --- /dev/null +++ b/test.js @@ -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);