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 @@ - - + + + + + + Countdown Timer + + + -
-
-
Your bookmarks for this video
+ -
-
+
+

Example Message

+ + + +
+
00:00:00
+ +
+ +Settings + + + + \ No newline at end of file diff --git a/hackbeanpot/popup.js b/hackbeanpot/popup.js index 6e1390c..d4ee8bb 100644 --- a/hackbeanpot/popup.js +++ b/hackbeanpot/popup.js @@ -1,93 +1,139 @@ -import { getActiveTabURL } from "./utils.js"; - -const addNewBookmark = (bookmarks, bookmark) => { - const bookmarkTitleElement = document.createElement("div"); - const controlsElement = document.createElement("div"); - const newBookmarkElement = document.createElement("div"); - - bookmarkTitleElement.textContent = bookmark.desc; - bookmarkTitleElement.className = "bookmark-title"; - controlsElement.className = "bookmark-controls"; - - setBookmarkAttributes("play", onPlay, controlsElement); - setBookmarkAttributes("delete", onDelete, controlsElement); - - newBookmarkElement.id = "bookmark-" + bookmark.time; - newBookmarkElement.className = "bookmark"; - newBookmarkElement.setAttribute("timestamp", bookmark.time); - - newBookmarkElement.appendChild(bookmarkTitleElement); - newBookmarkElement.appendChild(controlsElement); - bookmarks.appendChild(newBookmarkElement); -}; - -const viewBookmarks = (currentBookmarks=[]) => { - const bookmarksElement = document.getElementById("bookmarks"); - bookmarksElement.innerHTML = ""; - - if (currentBookmarks.length > 0) { - for (let i = 0; i < currentBookmarks.length; i++) { - const bookmark = currentBookmarks[i]; - addNewBookmark(bookmarksElement, bookmark); - } +const urlList = []; + +document.addEventListener('DOMContentLoaded', function() { + // Select DOM elements + const countdownInput = document.getElementById('countdownInput'); + const startButton = document.getElementById('startButton'); + const pauseButton = document.getElementById('pauseButton'); + const resetButton = document.getElementById('resetButton'); // Select the reset button + const timerDisplay = document.getElementById('timer'); + + let productive = ['Fish-tastic Job!', 'Keep Swimming', 'You(\'re) really fish-tastic!', +'I sea you working...', 'A true ocean master!', `You're such a starfish!`] +let unproductive = [`Don't forget about your fish!`, 'Oh, barnacles.', + `I don't sea you working hard`, `I'm getting flooded...`, ':(((', 'Wrong tab!'] + +function chooseMessage() { + let num = Math.floor(Math.random() * 6) + if(urlList.some(url => currentUrl.includes(url))) { + return productive[num]; } else { - bookmarksElement.innerHTML = 'No bookmarks to show'; + return unproductive[num]; + } +} + +const chosenMessageText = document.getElementById('chosenMessage'); +chosenMessageText.innerText = chooseMessage(); + + let timerInterval; // Variable to hold the setInterval ID + let countdownTime; // Variable to hold the remaining countdown time + let isPaused = false; // Variable to track pause state + + // Function to update the timer display + function updateTimer(seconds) { + const hours = Math.floor(seconds / 3600); + const minutes = Math.floor((seconds % 3600) / 60); + const remainingSeconds = seconds % 60; + const formattedTime = `${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}:${String(remainingSeconds).padStart(2, '0')}`; + timerDisplay.textContent = formattedTime; } - return; -}; - -const onPlay = async e => { - const bookmarkTime = e.target.parentNode.parentNode.getAttribute("timestamp"); - const activeTab = await getActiveTabURL(); - - chrome.tabs.sendMessage(activeTab.id, { - type: "PLAY", - value: bookmarkTime, - }); -}; - -const onDelete = async e => { - const activeTab = await getActiveTabURL(); - const bookmarkTime = e.target.parentNode.parentNode.getAttribute("timestamp"); - const bookmarkElementToDelete = document.getElementById( - "bookmark-" + bookmarkTime - ); - - bookmarkElementToDelete.parentNode.removeChild(bookmarkElementToDelete); - - chrome.tabs.sendMessage(activeTab.id, { - type: "DELETE", - value: bookmarkTime, - }, viewBookmarks); -}; - -const setBookmarkAttributes = (src, eventListener, controlParentElement) => { - const controlElement = document.createElement("img"); - - controlElement.src = "assets/" + src + ".png"; - controlElement.title = src; - controlElement.addEventListener("click", eventListener); - controlParentElement.appendChild(controlElement); -}; - -document.addEventListener("DOMContentLoaded", async () => { - const activeTab = await getActiveTabURL(); - const queryParameters = activeTab.url.split("?")[1]; - const urlParameters = new URLSearchParams(queryParameters); + // Function to start the countdown timer + function startCountdown() { + countdownTime = parseInt(countdownInput.value) * 60; + if (isNaN(countdownTime) || countdownTime <= 0) { + alert('Please enter a valid countdown time (greater than 0).'); + return; + } + + updateTimer(countdownTime); + + // Start the countdown + timerInterval = setInterval(function() { + if (!isPaused) { + countdownTime--; + updateTimer(countdownTime); + } + + if (countdownTime <= 0) { + clearInterval(timerInterval); + // Send a message to the content script + chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { + chrome.tabs.sendMessage(tabs[0].id, {action: 'startWaterAnimation'}); + }); + } + }, 1000); + + // Enable pause button and disable start button + startButton.disabled = true; + pauseButton.disabled = false; + resetButton.disabled = false; + } - const currentVideo = urlParameters.get("v"); + // Function to start the countdown timer after resuming + function resumeCountdownHelper(remainingTime) { + countdownTime = remainingTime; + if (isNaN(countdownTime) || countdownTime <= 0) { + alert('Invalid countdown time.'); + return; + } + updateTimer(countdownTime); + // Start the countdown + timerInterval = setInterval(function() { + if (!isPaused) { + countdownTime--; + updateTimer(countdownTime); + } + + if (countdownTime <= 0) { + clearInterval(timerInterval); + // Send a message to the content script + chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { + chrome.tabs.sendMessage(tabs[0].id, {action: 'startWaterAnimation'}); + }); + } + }, 1000); + + // Enable pause, reset buttons and disable start button + startButton.disabled = true; + pauseButton.disabled = false; + resetButton.disabled = false; + } - if (activeTab.url.includes("youtube.com/watch") && currentVideo) { - chrome.storage.sync.get([currentVideo], (data) => { - const currentVideoBookmarks = data[currentVideo] ? JSON.parse(data[currentVideo]) : []; + // Function to pause the countdown timer + function pauseCountdown() { + clearInterval(timerInterval); + isPaused = true; + startButton.disabled = false; + pauseButton.disabled = true; + resetButton.disabled = false; + } - viewBookmarks(currentVideoBookmarks); - }); - } else { - const container = document.getElementsByClassName("container")[0]; + // Function to resume the countdown timer + function resumeCountdown(remainingTime) { + isPaused = false; + resumeCountdownHelper(remainingTime); + } - container.innerHTML = '
This is not a youtube video page.
'; + // Function to reset the countdown timer + function resetCountdown() { + clearInterval(timerInterval); + countdownTime = 0; + updateTimer(countdownTime); + isPaused = false; + startButton.disabled = false; + pauseButton.disabled = true; + resetButton.disabled = true; // Disable the reset button after resetting the timer } -}); + // Event listeners + startButton.addEventListener('click', function() { + if (isPaused) { + resumeCountdown(countdownTime); + } else { + startCountdown(); + } + }); + pauseButton.addEventListener('click', pauseCountdown); + resetButton.addEventListener('click', resetCountdown); +}); \ No newline at end of file diff --git a/hackbeanpot/settings.png b/hackbeanpot/settings.png new file mode 100644 index 0000000..d130a22 Binary files /dev/null and b/hackbeanpot/settings.png differ