diff --git a/README.md b/README.md
index ce39d77..5c90cca 100644
--- a/README.md
+++ b/README.md
@@ -13,6 +13,9 @@ An extension that lets you search for words in a youtube video, and seeks to tha
- Write a function that will given a word and transcript get a list of timestamps
- Write a function that will seek a youtube video to a timestamp
- Searchbar + enter + shortcut logic
+- Reset transcript/search on new vids
+- Switch to indices starting at 1
+- Option F to toggle search bar off
## Development Usage
diff --git a/background.js b/background.js
index f570f0b..7613e38 100644
--- a/background.js
+++ b/background.js
@@ -2,8 +2,15 @@ let currVideoID;
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
if ( tab.url && tab.url.includes('watch?v') ) {
if(currVideoID != tab.url.split('?v=')[1].slice(0,11)) {
+ //New video
+ if (changeInfo.url) {
+ chrome.tabs.sendMessage( tabId, {
+ type: 'closeSearch',
+ url: changeInfo.url
+ })
+ }
currVideoID = tab.url.split('?v=')[1].slice(0,11);
- let endpoint = `http://3.137.212.199:5000/get-mapping?videoid=${currVideoID}`;
+ let endpoint = `http://youtubedl.acceleratedcloudone.com:5000/get-mapping?videoid=${currVideoID}`;
var xhr = new XMLHttpRequest();
xhr.open("GET", endpoint, true);
xhr.onreadystatechange = function () {
@@ -27,4 +34,3 @@ chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
}
});
-
diff --git a/content.js b/content.js
index 9dedac0..b1947b2 100644
--- a/content.js
+++ b/content.js
@@ -3,6 +3,15 @@ let word = '';
let idx = 0;
let numWords = 0;
let timestamps = [];
+
+chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
+ if (request.type == "closeSearch") {
+ closeSearch(true);
+ sendResponse(true);
+ }
+ return true;
+});
+
function openSearchBar(e) {
//Open search bar on option+f
if (window.location.href.includes('watch') && e.code=="KeyF" && e.altKey) {
@@ -17,7 +26,9 @@ function openSearchBar(e) {
document.getElementById('searchBarInput').value = '';
document.getElementById('wordCounter').innerHTML = `${idx} of ${numWords}`;
document.getElementById('searchBarOuter').style.display = "flex";
- }
+ } else {
+ closeSearch();
+ }
}
}
@@ -27,7 +38,7 @@ function nextTimeStamp(increment='up') {
} else {
idx -= 1;
}
- let timestamp = timestamps[idx];
+ let timestamp = timestamps[idx-1];
video = document.getElementsByTagName('video')[0];
video.pause();
video.currentTime = timestamp;
@@ -53,7 +64,7 @@ function incrementUp(e) {
}
function incrementDown(e) {
- if (idx > 0) {
+ if (idx > 1) {
nextTimeStamp('down');
}
}
@@ -67,9 +78,13 @@ function handleInput(e) {
chrome.runtime.sendMessage({type:"getTimestamp",word:word}, function(response){
if (response) {
numWords = response.length;
- document.getElementById('wordCounter').innerHTML = `${idx} of ${numWords}`;
timestamps = response;
+ } else {
+ idx = 0;
+ numWords = 0;
+ timestamps = [];
}
+ document.getElementById('wordCounter').innerHTML = `${idx} of ${numWords}`;
})
}
@@ -129,7 +144,6 @@ function createSearchBar(){
searchBarContainer.appendChild(close);
var list = document.getElementById('primary-inner');
- console.log(list.childNodes[0]);
list.insertBefore(searchBarOuter,list.childNodes[0]);
}
@@ -137,5 +151,3 @@ function createSearchBar(){
document.addEventListener('keydown',openSearchBar);
-
-
diff --git a/searchbars.html b/searchbars.html
deleted file mode 100644
index 0cd1e9c..0000000
--- a/searchbars.html
+++ /dev/null
@@ -1,37 +0,0 @@
-
0 of 0
-∧
-∨
-❌
-0 of 0
-∧
-∨
-×
-0 of 0
-∧
-∨
-×
-