diff --git a/hackbeanpot/.DS_Store b/hackbeanpot/.DS_Store index 5008ddf..04ba079 100644 Binary files a/hackbeanpot/.DS_Store and b/hackbeanpot/.DS_Store differ diff --git a/hackbeanpot/background.js b/hackbeanpot/background.js index c07aca9..4ae8264 100644 --- a/hackbeanpot/background.js +++ b/hackbeanpot/background.js @@ -1,12 +1,93 @@ -chrome.tabs.onUpdated.addListener((tabId, tab) => { - if (tab.url && tab.url.includes("youtube.com/watch")) { - const queryParameters = tab.url.split("?")[1]; - const urlParameters = new URLSearchParams(queryParameters); - - chrome.tabs.sendMessage(tabId, { - type: "NEW", - videoId: urlParameters.get("v"), - }); - } - }); +function saveURLs(urls) { + chrome.storage.sync.set({ 'userUrls': urls }, function() { + console.log('User URLs saved:', urls); + }); +} + +function getUserUrls(callback) { + chrome.storage.sync.get('userUrls', function(data) { + const userUrls = data.userUrls || []; + console.log('User URLs retrieved:', userUrls); + if(callback) { + callback(userUrls); + } + }) +} + +function addUrlToList(url) { + const urlList = document.getElementById('urlList'); + const listItem = document.createElement('li'); + listItem.textContent = url; + urlList.appendChild(listItem); +} + +document.addEventListener('DOMContentLoaded', function() { + const urlForm = document.getElementById('urlForm'); + const urlInput = document.getElementById('urlInput'); + + getUserUrls(function(userUrls) { + userUrls.forEach(function(url) { + addUrlToList(url); + }); + }); + + urlForm.addEventListener('submit', function(event) { + event.preventDefault(); + const url = urlInput.value.trim(); + if(url) { + addUrlToList(url); + getUserUrls(function(userUrls) { + userUrls.push(url); + saveURLs(userUrls); + }); + urlInput.value = ''; + } + }) +}) + +saveURLs(userinput); + +const userCountdown = 60; +let countdownInterval; + +function checkURL() { + chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { + const currentUrl = tabs[0].url; + + const isMatch = urlList.some(url => currentUrl.includes(url)); + + if(isMatch) { + console.log("Current URL matches"); + startCountdown(); + } else { + console.log("Current URL does not match"); + pauseCountdown(); + } + }) + +} + +function beginCounting() { + let remainingSecs = countdown; + countdownInterval = setInterval(() => { + console.log(secondsLeft + " seconds left"); + if(secondsLeft === 0) { + clearInterval(countdownInterval); + console.log("Countdown finished!"); + } else { + remainingSecs--; + } + }, 1000) +} + +function pauseCountdown() { + clearInterval(countdownInterval); + isCountdownRunning = false; +} + +checkURL(); + +setInterval(checkURL, 1000); + + \ No newline at end of file diff --git a/hackbeanpot/contentScript.js b/hackbeanpot/contentScript.js index 2ab1c09..8bc6701 100644 --- a/hackbeanpot/contentScript.js +++ b/hackbeanpot/contentScript.js @@ -1,73 +1,13 @@ -(() => { - let youtubeLeftControls, youtubePlayer; - let currentVideo = ""; - let currentVideoBookmarks = []; - - const fetchBookmarks = () => { - return new Promise((resolve) => { - chrome.storage.sync.get([currentVideo], (obj) => { - resolve(obj[currentVideo] ? JSON.parse(obj[currentVideo]) : []); - }); - }); - }; - - const addNewBookmarkEventHandler = async () => { - const currentTime = youtubePlayer.currentTime; - const newBookmark = { - time: currentTime, - desc: "Bookmark at " + getTime(currentTime), - }; - - currentVideoBookmarks = await fetchBookmarks(); - - chrome.storage.sync.set({ - [currentVideo]: JSON.stringify([...currentVideoBookmarks, newBookmark].sort((a, b) => a.time - b.time)) - }); - }; - - const newVideoLoaded = async () => { - const bookmarkBtnExists = document.getElementsByClassName("bookmark-btn")[0]; - - currentVideoBookmarks = await fetchBookmarks(); - - if (!bookmarkBtnExists) { - const bookmarkBtn = document.createElement("img"); - - bookmarkBtn.src = chrome.runtime.getURL("assets/bookmark.png"); - bookmarkBtn.className = "ytp-button " + "bookmark-btn"; - bookmarkBtn.title = "Click to bookmark current timestamp"; - - youtubeLeftControls = document.getElementsByClassName("ytp-left-controls")[0]; - youtubePlayer = document.getElementsByClassName('video-stream')[0]; - - youtubeLeftControls.appendChild(bookmarkBtn); - bookmarkBtn.addEventListener("click", addNewBookmarkEventHandler); - } - }; - - chrome.runtime.onMessage.addListener((obj, sender, response) => { - const { type, value, videoId } = obj; - - if (type === "NEW") { - currentVideo = videoId; - newVideoLoaded(); - } else if (type === "PLAY") { - youtubePlayer.currentTime = value; - } else if ( type === "DELETE") { - currentVideoBookmarks = currentVideoBookmarks.filter((b) => b.time != value); - chrome.storage.sync.set({ [currentVideo]: JSON.stringify(currentVideoBookmarks) }); - - response(currentVideoBookmarks); - } - }); - - newVideoLoaded(); - })(); - - const getTime = t => { - var date = new Date(0); - date.setSeconds(t); - - return date.toISOString().substr(11, 8); - }; - \ No newline at end of file +function manipulateDOMBasedOnTime(elapsedTime) { + //CHANGE THIS + //if the elapsedTime is greater than or equal to the user inputted time, add waves + if(elapsedTime >= userCountdown) { + document.body.style.backgroundColor = 'lightblue'; + } +} + +let elapsedTime = 0; +const timerInterval = setInterval(() => { + elapsedTime++; + manipulateDOMBasedOnTime(elapsedTime); +}, 1000); \ No newline at end of file diff --git a/hackbeanpot/logo.png b/hackbeanpot/logo.png new file mode 100644 index 0000000..21766b7 Binary files /dev/null and b/hackbeanpot/logo.png differ diff --git a/hackbeanpot/manifest.json b/hackbeanpot/manifest.json index 57337bf..9104d19 100644 --- a/hackbeanpot/manifest.json +++ b/hackbeanpot/manifest.json @@ -4,13 +4,12 @@ "description": "Extension to facilitate productivity online", "version": "1.0", "permissions": ["storage", "tabs", "activeTab"], - "host_permissions": ["https://*.youtube.com/*"], "background": { "service_worker": "background.js" }, "action": { "default_popup": "popup.html", - "default_icon": "testimage.png" + "default_icon": "logo.png" }, "content_scripts": [ { diff --git a/hackbeanpot/options.css b/hackbeanpot/options.css new file mode 100644 index 0000000..e69de29 diff --git a/hackbeanpot/options.html b/hackbeanpot/options.html new file mode 100644 index 0000000..e69de29 diff --git a/hackbeanpot/popup.css b/hackbeanpot/popup.css index b83085e..ba4ce2c 100644 --- a/hackbeanpot/popup.css +++ b/hackbeanpot/popup.css @@ -1,56 +1,20 @@ -.container { - width: 380px; - height: 220px; - color: #314d3e; +body{ background-color: lightblue; - } - - .title { - font-size: 20px; - font-weight: bold; - padding: 8px; - } - - .textbox { - width: 100%; - font-size: 12px; - margin: 0; - padding: 0px 2px; - } - - .textbox:focus { - outline: 0; - border-color: #66afe9; - } - - .bookmarks { - margin: 5px 5px; - padding: 3px; - } - - .bookmark { - display: flex; - border-bottom-color: #00254d; - border-bottom-width: 1px; - border-bottom-style: solid; - border-radius: 0.8rem; - padding: 3px; - padding-bottom: 7px; - margin-bottom: 7px; - } - - .bookmark-title { - padding-left: 2px; - } - - .bookmark-controls img { - margin: 0 4px; - width: 18px; - height: 18px; - cursor: pointer; - } - .bookmark-controls { - flex: auto; - text-align: right; - } - \ No newline at end of file + font-size: 25px; + width: 400px; + height: 240px; +} +#timer{ + background: #fff; + color: #000; + width: 150px; + margin: 50px auto; + margin-left: center; + margin-top: 20px; + text-align: center; +} +.settings { + background-color: transparent; + max-width: 50%; + max-height: 50%; +} \ No newline at end of file diff --git a/hackbeanpot/popup.html b/hackbeanpot/popup.html index 7591a8c..69a40e8 100644 --- a/hackbeanpot/popup.html +++ b/hackbeanpot/popup.html @@ -1,10 +1,28 @@ - - + + +
+ + +Example Message
+ + + +