javascript:(function(){ /* Config variables. */ var heightSavedPageNotesToNotebox = /* set initial height for notes */ "50px"; /* Global DOM variables */ var noteAreaYouTubeSavedNotesToNotebox = /* parent for note elements */ document.getElementById("noteArea"); var noteBoxTakeNotesYouTubeSavedNotesToNotebox = /* textare element for taking notes */ document.getElementById("noteBox"); var aboveTheFoldSavedPageNotesYouTubeSavedNotesToNotebox = /* html after vidoe box */ document.getElementById("above-the-fold"); var playButtonYouTubeSavedNotesToNotebox = /* play button - needed to update time mark */ document.getElementsByClassName("ytp-play-button"); var currentTimeClassYouTubeSavedNotesToNotebox = /* class element with current time */ "ytp-time-current"; /* Global configuration variables */ var ignoredKeysYouTubeSavedNotesToNotebox = /* keys pressed that do not active not box */ "Home End PageUp PageDown"; var ignoredDOMElementsYouTubeSavedNotesToNotebox = /* stop function if one of these is active */ ["comments", "search", "contenteditable-root", "player"]; /* Switch variables. */ var savedNotesTimeAddedYouTubeSavedNotesToNotebox = 0; /* if time mark array saved with prior notes */ /* Declare global variables that will be defined later. */ var curTimeElementYouTubeSavedNotesToNotebox, curTimeElementTextYouTubeSavedNotesToNotebox, timePreCalYouTubeSavedNotesToNotebox, timeSecCalYouTubeSavedNotesToNotebox, storedNotesArrYouTubeSavedNotesToNotebox; /* CSS style sheet */ { var noteCSSSavedPageNotes = ` /* style close elements with constant styles */ button[id^="closeBMBtn"] { display: inline; position: relative; left: -5px; top: 5px; width: 25px; height: 25px; background: red; color: white; border: none; border-radius: 5px; z-index: 1; } button[id^="closeBMBtn"]:hover, button[id^="closeBMBtn"]:hover ~ input[id^="closeBMBtn"]:hover { cursor: pointer; border: 3px solid gray; } input[id^="closeBMBtn"] { box-sizing: content-box; display: inline-block; position: absolute; left: -5px; top: 5px; z-index: 2; opacity: 0; } input[id^="closeBMBtn"]:hover { cursor: pointer; width: 20px; height: 20px; border: 2px solid gray; opacity: .25; } input[data-close-bm-el^="hide"] + div { display: none !important; } input[data-close-bm-el^="show"] + div#noteArea { display: inline-flex; } /* style note area with constant styles */ div#noteArea { display: inline-flex; flex-wrap: nowrap; position: relative; top: 0px; width: 100%; } div #noteArea div { display: inline-block; position: relative; margin: 0px 10px; max-width: 450px; width: min-content; } div#noteArea div+div { display: inline-block; position: relative; max-width: 800px; width: auto !important; left: 0px; } /* style note box with constant style */ textarea#noteBox { max-width: 450px; width: 450px; height: ${heightSavedPageNotesToNotebox}; padding: 10px; border-radius: 10px; } /* style time mark area */ span#timeMarkButtonArea { box-sizing: border-box; display: inline-block; position: relative; float: left; max-width: 750px; width: auto; height: 100%; border-radius: 10px; margin-left: 10px; padding: 5px; padding-bottom: 40px; background: rgba(0, 0, 0, .025); } /* style close and time mark button parent */ span#timeMarkButtonArea div:first-of-type { display: inline; } span#timeMarkButtonArea div { display: inline-block; } /* style time mark buttons with constant styles */ span#timeMarkButtonArea a { box-sizing: border-box !important; display: inline-flex !important; position: relative; flex-wrap: wrap !important; top: 0px !important; left: unset !important; cursor: pointer; width: auto; height: 25px; border-radius: 3px; margin-left: 10px; margin-top: 3px; padding: 5px 10px 10px; background: rgba(40, 40, 40, .85); color: white; text-decoration: none; } span#timeMarkButtonArea a:hover { background: rgba(40, 40, 40, 1); } /* style close time mark buttons with constant styles */ span[id^="closeTimeMarkBtn"] { padding-left: 3px; padding-right: 3px; margin-left: 20px; border-left: 1px solid black; border-bottom: 1px solid black; border-width: medium; } /* style clear all time mark button at bottom right */ div#noteArea div div#clearAllTimeMarks { display: inline-block; position: absolute; cursor: pointer; bottom: 10px !important; right: 10px; background: rgba(255, 0, 0, .7); color: white; padding: 5px; border-radius: 5px; } div#noteArea div div#clearAllTimeMarks:hover { background: rgba(255, 0, 0, 1); padding: 6px; } `; } /* Note box setup. */ var noteTextAreaYouTubeSavedNotesToNotebox, noteAreaDivYouTubeSavedNotesToNotebox, noteBoxTakeNotesDivYouTubeSavedNotesToNotebox; /************************************* SUPPORT FUNCTIONS *************************************/ /* Create show, hide buttons for elements. */ const insertShowHideBtnYouTubeSavedNotesToNotebox = (el, curId, placeEl, placemnt) => { let closeNoteBoxBtn = document.createElement(el); closeNoteBoxBtn.id = "closeBMBtn" + curId; placeEl.insertAdjacentElement(placemnt, closeNoteBoxBtn); closeNoteBoxBtn.textContent = "X"; /* checkbox to show hide with css */ let closeCheckbox = document.createElement("input"); closeCheckbox.type = "checkbox"; closeCheckbox.id = "closeBMBtnCheckbox" + curId; closeNoteBoxBtn.insertAdjacentElement("afterend", closeCheckbox); closeCheckbox = document.getElementById("closeBMBtnCheckbox" + curId); closeCheckbox.setAttribute("checked", true); /* HOT-GLUE */ if (placeEl.hasAttribute("id") && placeEl.getAttribute("id") == "player") { closeCheckbox.style.position = "relative"; closeCheckbox.style.left = "-30px"; } /* alternate close button status */ closeCheckbox.addEventListener("mousedown", function() { if (this.previousElementSibling.textContent == "X") { this.previousElementSibling.textContent = "O"; /* HOT-GLUE */ if (placeEl.hasAttribute("id") && placeEl.getAttribute("id") == "player") { player.style.display = "none"; } else { this.setAttribute("data-close-bm-el", "hide"); } } else { this.previousElementSibling.textContent = "X"; /* HOT-GLUE */ if (placeEl.hasAttribute("id") && placeEl.getAttribute("id") == "player") { player.style.display = ""; } else { this.setAttribute("data-close-bm-el", "show"); } } }); }; /* Creeat note box. */ const addNoteBoxYouTubeSavedNotesToNotebox = () => { if (!noteAreaYouTubeSavedNotesToNotebox) { /* are for notes */ noteAreaDivYouTubeSavedNotesToNotebox = document.createElement("div"); noteAreaDivYouTubeSavedNotesToNotebox.id = "noteArea"; aboveTheFoldSavedPageNotesYouTubeSavedNotesToNotebox.insertAdjacentElement("beforebegin", noteAreaDivYouTubeSavedNotesToNotebox); let noteStyle = /* using noteCSSSavedPageNotes from above */ document.createElement("style"); noteStyle.textContent = /* add css properties */ noteCSSSavedPageNotes; noteAreaDivYouTubeSavedNotesToNotebox.insertAdjacentElement("beforebegin", noteStyle); noteAreaYouTubeSavedNotesToNotebox = document.getElementById("noteArea"); /* note box */ noteTextAreaYouTubeSavedNotesToNotebox = document.createElement("textarea"); noteTextAreaYouTubeSavedNotesToNotebox.id = "noteBox"; noteBoxTakeNotesDivYouTubeSavedNotesToNotebox = document.createElement("div"); /* insert div to hold textarea */ noteAreaYouTubeSavedNotesToNotebox.insertAdjacentElement("afterbegin", noteBoxTakeNotesDivYouTubeSavedNotesToNotebox); /* insert textare html elements to take notes */ noteBoxTakeNotesDivYouTubeSavedNotesToNotebox.insertAdjacentElement("afterbegin", noteTextAreaYouTubeSavedNotesToNotebox); noteBoxTakeNotesDivYouTubeSavedNotesToNotebox.id = "noteTextArea"; /* used for adding time marks */ /* close buttnon */ insertShowHideBtnYouTubeSavedNotesToNotebox( "button", /* insert button */ "NoteBoxBtn", /* set closeBMBtn += NoteBoxBtn */ noteStyle, /* placement based on element */ "afterend" /* placement after element */ ); /* close button for video */ let player = document.getElementById("player"); insertShowHideBtnYouTubeSavedNotesToNotebox( "button", /* insert button */ "VideoPlayer", /* set closeBMBtn += NoteBoxBtn */ player, /* placement based on element */ "beforebegin" /* placement before element */ ); } else { /* note box is on page, but apply bookmarklet style */ let noteStyle = /* using noteCSSSavedPageNotes from above */ document.createElement("style"); noteStyle.textContent = /* add css properties */ noteCSSSavedPageNotes; /* assuming on page and has id */ noteAreaDivYouTubeSavedNotesToNotebox = document.getElementById("noteArea"); noteAreaDivYouTubeSavedNotesToNotebox.insertAdjacentElement("beforebegin", noteStyle); } }; /* Copy notes in textare to clipboard. */ const copyNotesYouTubeSavedNotesToNotebox = () => { noteBoxTakeNotesYouTubeSavedNotesToNotebox.select(); navigator.clipboard.writeText( noteBoxTakeNotesYouTubeSavedNotesToNotebox.value ); }; /* Update current time - for time mark. */ const updateCurrentTimeYouTubeSavedNotesToNotebox = () => { /* update HTML element holding time value */ let playButtonData = playButtonYouTubeSavedNotesToNotebox[0].dataset.titleNoTooltip; /* to keep video paused */ if (playButtonData != "Play") { playButtonYouTubeSavedNotesToNotebox[0].click(); playButtonYouTubeSavedNotesToNotebox[0].click(); } /* update time value HTML element */ curTimeElementYouTubeSavedNotesToNotebox = /* select element with current time */ document.getElementsByClassName(currentTimeClassYouTubeSavedNotesToNotebox); curTimeElementTextYouTubeSavedNotesToNotebox = curTimeElementYouTubeSavedNotesToNotebox[0].textContent; /* extract time and calculate in seconds */ timePreCalYouTubeSavedNotesToNotebox = curTimeElementTextYouTubeSavedNotesToNotebox.split(":"); }; /* Add time mark button to the right of textarea. */ const markTimeYouTubeSavedNotesToNotebox = () => { /* func functions */ /* extract current time from video on ctrl + m */ let extracTCurTime = (ct) => { if (savedNotesTimeAddedYouTubeSavedNotesToNotebox == 1) { noteBoxTakeNotesYouTubeSavedNotesToNotebox.blur(); /* quickly deactivate note box */ noteBoxTakeNotesYouTubeSavedNotesToNotebox.setAttribute("disabled", true); } if (ct.length == 3) { /* not handling videos over 24 hours - no */ timeSecCalYouTubeSavedNotesToNotebox = Number(Number(ct[0]*60) * 60) + /* hours to seconds */ Number(ct[1]*60) + /* minutes to seconds */ Number(ct[2]); /* seconds */ } else if (ct.length == 2) { timeSecCalYouTubeSavedNotesToNotebox = Number(ct[0]*60) + /* minutes to seconds */ Number(ct[1]); /* seconds */ } else if (ct.length == 1) { timeSecCalYouTubeSavedNotesToNotebox = Number(ct[0]); /* seconds */ } }; /* add main area for time marks */ let addTimeMarkArea = () => { /* create time mark area and elements */ let timeMarkButtonAreaID = document.getElementById("timeMarkButtonArea"); let timeMarkButtonArea, clearAllTimeMarks; /* hold time marks and add clear button */ /* don't duplicate parent container */ if (!timeMarkButtonAreaID) { /* create area for time mark buttons */ let timeMarkDiv = /* parent for time mark box */ document.createElement("div"); timeMarkButtonArea = /* time mark box - parent for timemarks */ document.createElement("span"); timeMarkButtonArea.id = "timeMarkButtonArea"; clearAllTimeMarks = /* button to clear time marks from prior sessions */ document.createElement("div"); clearAllTimeMarks.id = /* class for style */ "clearAllTimeMarks"; clearAllTimeMarks.title = /* title for instructional hint */ "clear session time marks"; clearAllTimeMarks.innerText = "Clear"; /* button rendered text */ /* insert time mark box parent div */ noteBoxTakeNotesDivYouTubeSavedNotesToNotebox = /* if note aleady existed */ document.getElementById("noteTextArea"); noteBoxTakeNotesDivYouTubeSavedNotesToNotebox.insertAdjacentElement("afterend", timeMarkDiv); /* insert time mark box */ timeMarkDiv.insertAdjacentElement("afterbegin", timeMarkButtonArea); /* insert clear button */ timeMarkButtonArea.insertAdjacentElement("afterend", clearAllTimeMarks); } /* redefine clearAllTimeMarks */ clearAllTimeMarks = document.getElementById("clearAllTimeMarks"); clearAllTimeMarks /* function to clear all when clicked */ .addEventListener( "click", function() { let tmArea = this.previousElementSibling; let tmMark = tmArea.children; let tmMarkLen = tmMark.length; if (tmMarkLen > 0) { while (tmMarkLen > 0) { tmMark[0].remove(); tmMarkLen = tmMark.length; } this.style.display = "none"; /* hide until time marks are added */ } }); }; /* give new time marks unique id and add time */ let normalCall = 0; /* switch variable - 1 if called via ctrl + m */ let addTimeMarkItem = (ct) => { if (ct == undefined) { normalCall = 1; } /* run using ctrl + m */ if (ct == "empty") { return; } /* end function if saved session had empty marks */ /* check if mark already there */ let curTimeMarkBtnID = document.getElementById("timeMarkBtn" + timeSecCalYouTubeSavedNotesToNotebox); let curTimeMarkCloseBtn, curTimeMarkBtn, clearAllTimeMarks; /* variables for time and clear time */ /* show clear all time mark button */ clearAllTimeMarks = document.getElementById("clearAllTimeMarks"); /* ensure part of dom */ if (clearAllTimeMarks) { /* change display if all marks were previously cleared */ if (clearAllTimeMarks.style.display == "none") { /* set to value from inserted style tag */ clearAllTimeMarks.style.display = "inline-block"; } else { /* do nothing */ let skip; } } /* don't duplicate time marks */ if (!curTimeMarkBtnID) { /* create time mark buttons */ let timeMarkButtonAreaID = document.getElementById("timeMarkButtonArea"); /* CREATE AND ADD CLOSE TIME MARK BUTTONS ***************************************/ /* parent of close and time mark button */ let timeMarkBtn = document.createElement("div"); /* insert parent of close and time mark button */ timeMarkButtonAreaID.insertAdjacentElement("beforeend", timeMarkBtn); curTimeMarkCloseBtn = /* enable time marks to be removed */ document.createElement("span"); curTimeMarkCloseBtn /* give each a unique data attribute */ .id = "closeTimeMarkBtn" + timeSecCalYouTubeSavedNotesToNotebox; curTimeMarkCloseBtn /* style close btn - give pointers hover effect */ .style.cursor = "pointer"; curTimeMarkCloseBtn /* style close btn - give font-size */ .style.fontSize = "small"; curTimeMarkCloseBtn /* add mouse event - mouse over to style text */ .addEventListener( "mouseover", function() { this.style.fontWeight = "bold"; this.style.fontSize = "medium"; }); curTimeMarkCloseBtn /* add mouse event - mouse out to style text */ .addEventListener( "mouseout", function() { this.style.fontWeight = "initial"; this.style.fontSize = "small"; }); curTimeMarkCloseBtn /* add click event - remove time mark and this */ .addEventListener( "click", function() { this.parentElement.remove(); /* removes all elements of time mark button */ }); curTimeMarkCloseBtn /* give close symbol as string - x */ .innerText = "x"; /* insert close time mark button */ timeMarkBtn.insertAdjacentElement("afterbegin", curTimeMarkCloseBtn); /* CREATE AND ADD TIME MARK BUTTONS ********************************************/ let closeTimeBtn = /* get id of close button to insert time mark after it */ document.getElementById("closeTimeMarkBtn" + timeSecCalYouTubeSavedNotesToNotebox); curTimeMarkBtn = /* time mark linking tom marked times */ document.createElement("a"); curTimeMarkBtn.id = /* give each a unique id */ "timeMarkBtn" + timeSecCalYouTubeSavedNotesToNotebox; /* open link in new tab - _blank */ curTimeMarkBtn.target = "_blank"; let vidURL = location.href; /* extract current url */ /* conditions if url did not already have time value */ if (vidURL.indexOf("&t=") > -1) { /* had time value */ vidURL = vidURL.replace(/t=[0-9]+/, "t=" + timeSecCalYouTubeSavedNotesToNotebox); } else { /* no time value */ vidURL = vidURL + "&t=" + timeSecCalYouTubeSavedNotesToNotebox + "s"; } curTimeMarkBtn.href = vidURL; if (normalCall == 1) { /* called via ctrl + m */ /* use calculation for current video time */ /* use hour : minutes: seconds */ for (i in timePreCalYouTubeSavedNotesToNotebox) { if (i == Number(timePreCalYouTubeSavedNotesToNotebox.length-1)) { if (Number(timePreCalYouTubeSavedNotesToNotebox.length-1) == 0) { curTimeMarkBtn.innerText = "0:" + timePreCalYouTubeSavedNotesToNotebox[i]; } else { curTimeMarkBtn.innerText += timePreCalYouTubeSavedNotesToNotebox[i]; } } else { curTimeMarkBtn.innerText += timePreCalYouTubeSavedNotesToNotebox[i] + ":"; } } } else { curTimeMarkBtn.innerText = ct; /* using time from prior note session */ } /* insert time marked at key combo "Ctrl + m" */ timeMarkBtn.insertAdjacentElement("beforeend", curTimeMarkBtn); /* add click event to pause video if clicked and video is playing */ curTimeMarkBtn.addEventListener("click", function() { let playButtonData = playButtonYouTubeSavedNotesToNotebox[0].dataset.titleNoTooltip; if (playButtonData != "Play") { playButtonYouTubeSavedNotesToNotebox[0].click(); } }); } /* focus back on note box */ noteBoxTakeNotesYouTubeSavedNotesToNotebox.removeAttribute("disabled"); noteBoxTakeNotesYouTubeSavedNotesToNotebox.focus(); }; /* 0 => adding time markks from prior notes, 1 => add with crtl + m */ if (savedNotesTimeAddedYouTubeSavedNotesToNotebox == 0) { let priorTimeArr = /* array from prior time mark make-shift array */ storedNotesArrYouTubeSavedNotesToNotebox[2].split(","); let priorTimeArrLen = /* prep for loop */ priorTimeArr.length; /* sort time values */ priorTimeArr.sort(); /* add time marks from last note session */ for (i = 0; i < priorTimeArrLen; i++) { extracTCurTime(priorTimeArr[i].split(":")); if ( i == 0) { /* add time area on first iteration */ addTimeMarkArea(); } /* give each mark id with time appended, adding prior time */ addTimeMarkItem(priorTimeArr[i]); } } else { /* get current time spot of video */ extracTCurTime(timePreCalYouTubeSavedNotesToNotebox); /* check if time mark area needs to be added */ addTimeMarkArea(); /* give each mark id with time appended, adding current time */ addTimeMarkItem(); } }; /* Check if Control and Shift are sequentially keyup and keydown under 1 second. */ const checkCtrlShiftYouTubeSavedNotesToNotebox = (ms = 750) => { return new Promise(resolve => { let ctrlPressed = false; let ctrlReleased = false; let shiftPressed = false; let shiftReleased = false; let deadline = 0; let timeoutId = null; function cleanup(result) { document.removeEventListener('keydown', onKeyDown, true); document.removeEventListener('keyup', onKeyUp, true); if (timeoutId) { clearTimeout(timeoutId); timeoutId = null; } resolve(!!result); } function startTimeout() { /* start or restart the timeout for the shift window */ if (timeoutId) clearTimeout(timeoutId); deadline = Date.now() + ms; timeoutId = setTimeout(() => { /* timed out waiting for shift sequence */ cleanup(false); }, ms); } function onKeyDown(e) { const k = e.key; if (k === 'Control') { /* ctrl pressed */ ctrlPressed = true; } else if (k === 'Shift') { /* only pay attention to shift if ctrl has already been released */ if (ctrlReleased && !shiftPressed) { shiftPressed = true; } } } function onKeyUp(e) { const k = e.key; if (k === 'Control') { /* only consider a ctrl "release" if it was pressed first */ if (ctrlPressed) { ctrlPressed = false; ctrlReleased = true; startTimeout(); } } else if (k === 'Shift') { /* only consider shift release if we saw a shift press after ctrl release */ if (shiftPressed) { shiftPressed = false; shiftReleased = true; /* check timing and that neither key is currently held down */ const withinTime = Date.now() <= deadline; const ctrlStillHeld = ctrlPressed; /* should be false */ const shiftStillHeld = shiftPressed; /* should be false */ if (withinTime && !ctrlStillHeld && !shiftStillHeld) { cleanup(true); } else { cleanup(false); } } } } /* attach capturing listeners so they catch keys even if elements stop propagation */ document.addEventListener('keydown', onKeyDown, true); document.addEventListener('keyup', onKeyUp, true); /* safety: if nothing happens for (ms + 1000) ms, give up */ const globalTimeout = setTimeout(() => { if (timeoutId) { clearTimeout(timeoutId); timeoutId = null; } cleanup(false); }, ms + 1000); /* ensure the safety timeout cleared on final cleanup */ const origCleanup = cleanup; cleanup = function(result) { clearTimeout(globalTimeout); origCleanup(result); }; }); }; /* Focus on textarea whenever keydown occurs. */ const keypressToNoteYouTubeSavedNotesToNotebox = () => { let activeID = document.activeElement.id; let lastKeyPressSavedPageNotes; /* used to check for key combos */ lastKeyPressSavedPageNotes = sessionStorage.getItem("lastKeyPressSavedPageNotes"); /* for first key press */ if (lastKeyPressSavedPageNotes == null) { sessionStorage.setItem("lastKeyPressSavedPageNotes", event.key); lastKeyPressSavedPageNotes = sessionStorage.getItem("lastKeyPressSavedPageNotes"); } /* store key press and check active element */ let currentKeyPress = event.key; /* start conditions to activate note box or run function accordingly */ /* if any of these elements have focus */ /** ignoredDOMElementsYouTubeSavedNotesToNotebox = "comments search contenteditable-root playerSavedPageNotes"; **/ /* then don't take notes - note - variable defined at start */ for (i in ignoredDOMElementsYouTubeSavedNotesToNotebox) { if (activeID == ignoredDOMElementsYouTubeSavedNotesToNotebox[i]) { /* quit function */ return; } } /* else */ { /* the active element is not in ignored list, run function */ let checkKeyCombo = /* check for combos */ lastKeyPressSavedPageNotes + "+" + currentKeyPress; /* check key combos and run function accordingly */ checkCtrlShiftYouTubeSavedNotesToNotebox(750).then((ok) => { /* checkKeyCombo = "Control Shift" */ if (ok) { noteBox.blur(); } else { let skip; /* do nothing */ } }); /* add time marker adjacent to notes */ if (checkKeyCombo == "Control+m") { updateCurrentTimeYouTubeSavedNotesToNotebox(); markTimeYouTubeSavedNotesToNotebox(); } /* select and copy notes to clipboard */ else if (checkKeyCombo == "Alt+a") { copyNotesYouTubeSavedNotesToNotebox(); } else { /* only if note box is not active element */ if (activeID != "noteBox") { /* prevent fullscreen from occuring *//* ************************************** NOTE - THIS DOES NOT WORK ************************* if (currentKeyPress == "f") { document.activeElement.dispatchEvent(new KeyboardEvent('keydown', {'key': 'Esc'})); } ************************************** ***************************************/ /* USE VARIABLE FOR CONDITIONS */ let noIgnoredKeys = ignoredKeysYouTubeSavedNotesToNotebox.indexOf(event.key) == -1; let notPauseShortcut = checkKeyCombo != "Shift+ "; if (noIgnoredKeys) { if (notPauseShortcut) { noteBoxTakeNotesYouTubeSavedNotesToNotebox.focus(); } } } } } /* store key press for next key combo check */ sessionStorage.setItem("lastKeyPressSavedPageNotes", event.key); }; /* Quickly get back to notes */ const addKeyDownYouTubeSavedNotesToNotebox = () => { document.body.addEventListener("keydown", function() { keypressToNoteYouTubeSavedNotesToNotebox(); }); }; /* Format and prior saved notes to note box. */ const addYouTubeSavedNotesToNotebox = () => { /* get the video title */ let titlePar = document.getElementsByClassName("style-scope ytd-watch-metadata"); let videoTitle = titlePar[0].innerText.replace(/\n.*/g,""); /* get the id holding the username */ let username = document.getElementById("top-row"); /* extract all text from id holding user name */ let extractUserNameText = username.textContent; /* clean text to only get username only */ let usernameVal = extractUserNameText.replace(/\n/g,"") .replace(/^ {2,}(.*) {2,}(.*)subscribers(.*)$/g,"$1") .replace(/^(.*) {2,}.*$/g, "$1") .replace(/ {2,}/g,""); /* generate name for localStorage variable */ let storageVar = usernameVal + "--" + videoTitle; storageVar = storageVar.replace(/ {1,}/g, "-"); /* store notes in local storage as variable formatted: usename--Video-Title */ let storedNotes = localStorage.getItem(storageVar); if (storedNotes == null || storedNotes == undefined) { alert("There are no saved notes for the current page."); savedNotesTimeAddedYouTubeSavedNotesToNotebox = 1; /* run mark time as normal */ } else { storedNotesArrYouTubeSavedNotesToNotebox = storedNotes.split("--:--"); /* make saved notes array */ /* store previos notes */ let priorNotesTaken = storedNotesArrYouTubeSavedNotesToNotebox[1]; noteBoxTakeNotesYouTubeSavedNotesToNotebox.textContent = /* add prior notes to box */ storedNotesArrYouTubeSavedNotesToNotebox[0] + "\n" + /* add heading for title and date */ storedNotesArrYouTubeSavedNotesToNotebox[1].replace(/
/g, "\n"); /* replace with new lines */ /* check if time marks were saved */ if (!storedNotesArrYouTubeSavedNotesToNotebox[2] || /* was saved using prior bookmarklet */ storedNotesArrYouTubeSavedNotesToNotebox[2] == "empty") { /* no time marks from prior notes */ savedNotesTimeAddedYouTubeSavedNotesToNotebox = 1; /* run mark time as normal */ } else { /* add time marks from prior notes */ markTimeYouTubeSavedNotesToNotebox(); savedNotesTimeAddedYouTubeSavedNotesToNotebox = 1; /* run mark time as normal */ } alert("PRIOR NOTE SESSION LOADED: \n\n" + "NOTE - type \"clear\" or \"delete\", then save to alter log " + "accordingly, else all saves will be stored in running log of " + "note sessions.\n" + "NOTE - it is safe to remove these notes if saving this session " + "as they will remain in local storage for notes saved for video.\n" + "NOTE - to avoid clutter it is suggested that the notes from prior " + "sessions be cleaned or cleared before saving this session.\n" + "NOTE - To clear running log of notes, save page notes with only: \n" + "\"clear\" \n" + "typed into the note box.\n" + "and run bookmarklet " + "siteSpecific_YouTube_SavePageNotesToLocalStorage.\n" + "NOTE - To delete notes for this video, save page notes with only: \n" + "\"delete\" \n" + "typed into the note box." + "and run bookmarklet " + "siteSpecific_YouTube_SavePageNotesToLocalStorage." ); noteBoxTakeNotesYouTubeSavedNotesToNotebox.select(); } }; /* Delay each function and ensure all runs correctly. */ const delayYouTubeSavedNotesToNotebox = (cur) => { setTimeout(() => { cur; }, 50); }; /********************************************************************************************* MAIN FUNCTION *********************************************************************************************/ function youTubeSavedNotesToNotebox() { /* check and add note box if not present */ delayYouTubeSavedNotesToNotebox( addNoteBoxYouTubeSavedNotesToNotebox() ); /* redefine noteBoxTakeNotesYouTubeSavedNotesToNotebox */ delayYouTubeSavedNotesToNotebox( noteBoxTakeNotesYouTubeSavedNotesToNotebox = document.getElementById("noteBox") ); /* begin taking notes */ delayYouTubeSavedNotesToNotebox( noteBoxTakeNotesYouTubeSavedNotesToNotebox.focus() ); /* listen for keydonw event */ delayYouTubeSavedNotesToNotebox( addKeyDownYouTubeSavedNotesToNotebox() ); /* add prior notes to created or current note box */ delayYouTubeSavedNotesToNotebox( addYouTubeSavedNotesToNotebox() ); } /* Run bookmarklet. */ youTubeSavedNotesToNotebox(); })();