javascript:(function() { /* OPTIONAL - alert with instructions. */ var alertInstructionsYoutTubeShortRelease = 1; /* Declare global variables. */ var checkPageInitYoutTubeShortRelease, youTubeShortReleaseURINotice, factoidsYoutTubeShortRelease, releaseDateYoutTubeShortRelease, actionsIDYoutTubeShortRelease, putReleaseYoutTubeShortRelease, youTubeShortPath, youTubeShortURI, reloadYouTubeShortRelease; /* Define ready global variables. */ youTubeShortPath = "https://www.youtube.com/shorts"; youTubeShortURI = location.href; youTubeShortReleaseURINotice = /* not on shorts page */ ` You must be watching "Shorts" for bookmarklet to start. `; /* HOT-GLUE variable values used for globals defined in support functions. */ var hotGlueDescrClassYouTubeShortRelease = /* CLASS parent of description */ "ytwFactoidRendererFactoid"; var hotGlueplaceDateYouTubeShortRelease = () => { /* DEPRECATED: actionsIDYoutTubeShortRelease = document.getElementById("actions"); */ return document.getElementsByTagName("reel-action-bar-view-model"); }; /***********************SUPPORT FUNCTIONS***********************/ /* Check if being run for first time, setting storage if not as to compensate for initialization bug. */ const runInitYoutTubeShortRelease = () => { if (reloadYouTubeShortRelease == undefined) { /* don't repeat alerts */ if (sessionStorage.getItem("initYoutTubeShortRelease") != true) { if (location.href.indexOf(youTubeShortPath) > -1) { alert( "BOOKMARKLET HAS NOT BEEN INITIALIZED:\n\n" + "Run bookmarklet again if release date is not displayed.\n" ); /* on shorts set storage */ sessionStorage.setItem("initYoutTubeShortRelease", "1"); /* only reload if on shorts page */ window.location.reload(); } else { alert(youTubeShortReleaseURINotice); } return 1; } else { checkPageInitYoutTubeShortRelease = /* define */ sessionStorage.getItem("initYoutTubeShortRelease"); return 0; } } }; /* End if bookmarklet has not been initialised. */ reloadYouTubeShortRelease = runInitYoutTubeShortRelease(); runInitYoutTubeShortRelease(); /* Define DOM global variables. *****/ const defineVarYoutTubeShortRelease = () => { /* select parent containing short description */ factoidsYoutTubeShortRelease = document.getElementsByClassName(hotGlueDescrClassYouTubeShortRelease); /* placing before this item*/ actionsIDYoutTubeShortRelease = hotGlueplaceDateYouTubeShortRelease(); /* get release date */ releaseDateYoutTubeShortRelease = factoidsYoutTubeShortRelease[2].textContent; }; /* Create and style HTML to hold date. *****/ const makeDateElementYoutTubeShortRelease = () => { /* create element to store release date */ putReleaseYoutTubeShortRelease = document.createElement("p"); /* make presentable */ putReleaseYoutTubeShortRelease .style.fontFamily = "Roboto"; putReleaseYoutTubeShortRelease .style.fontWeight = "bold"; putReleaseYoutTubeShortRelease .style.marginLeft = "10px"; putReleaseYoutTubeShortRelease .style.marginBottom = "10px"; putReleaseYoutTubeShortRelease .style.textAlign = "center"; putReleaseYoutTubeShortRelease .style.background = "rgba(0, 0, 0, .095)"; putReleaseYoutTubeShortRelease .style.borderRadius = "25px"; putReleaseYoutTubeShortRelease .style.width = "50px"; putReleaseYoutTubeShortRelease .style.height = "50px"; putReleaseYoutTubeShortRelease .style.paddingTop = "12px"; putReleaseYoutTubeShortRelease .style.boxSizing = "border-box"; putReleaseYoutTubeShortRelease .style.fontSize = "9pt"; putReleaseYoutTubeShortRelease .style.position = "absolute"; putReleaseYoutTubeShortRelease .style.top = "0px"; /* Give id to remove if duplicates */ putReleaseYoutTubeShortRelease .id = "putReleaseYoutTubeShortRelease"; }; /* Add item to right of short. *************/ const addRelDateYoutTubeShortRelease = () => { actionsIDYoutTubeShortRelease[0] .insertAdjacentElement("beforebegin", putReleaseYoutTubeShortRelease); /* Select again */ putReleaseYoutTubeShortRelease = document.getElementById("putReleaseYoutTubeShortRelease"); /* check if year is at end or beginning */ let atEndYear = /^[a-zA-Z]+ \d{5,}$/; let atStartYear = /^\d{4}.*$/; /* make easier to read */ if (atEndYear.test(releaseDateYoutTubeShortRelease)) { releaseDateYoutTubeShortRelease = /* year is at end */ releaseDateYoutTubeShortRelease.replace(/([0-9]{1,})([0-9]{4})$/g, "$1, $2"); } else if (atStartYear.test(releaseDateYoutTubeShortRelease)) { releaseDateYoutTubeShortRelease = /* year is at start */ releaseDateYoutTubeShortRelease.replace(/([0-9]{4})/g, "$1, "); } /* Put in text of short release date. */ putReleaseYoutTubeShortRelease.innerText = releaseDateYoutTubeShortRelease; }; /* Check if url for short changes. *************/ const checkCurrentShort = () => { /* check url */ if (location.href.indexOf(youTubeShortPath) == -1) { /* remove listeners */ document.body.removeEventListener("click", showShortReleaseDate); /* end bookmarklet */ return; } else { /* get short release date */ let curShort = location.href; /* recheck uri */ if (curShort == youTubeShortURI) { /* do nothing */ let skip; } else { /* change short release date */ showShortReleaseDate(); youTubeShortURI = location.href; /* redefine for next check */ } } }; /*************************************************************** MAIN FUNCTION ****************************************************************/ function showShortReleaseDate() { /* Have to delay a bit - using one second cause - seems right. */ setTimeout(function() { /* Check id that is made to remove if already placed. */ putReleaseYoutTubeShortRelease = document.getElementById("putReleaseYoutTubeShortRelease"); /* If already placed remove. */ if (putReleaseYoutTubeShortRelease) { putReleaseYoutTubeShortRelease.remove(); defineVarYoutTubeShortRelease(); } else { defineVarYoutTubeShortRelease(); } /* Prep element to be inserted. */ makeDateElementYoutTubeShortRelease(); /* insert short release date */ addRelDateYoutTubeShortRelease(); /* Delay for half a second for content loading. */ }, 500); } /* Adds interval to check for uri change. */ var runShortReleaseURIInterval; /* Check if page needs to be reloaded or if intialised. */ if (reloadYouTubeShortRelease == 0) { /* does not need reloading */ /* add functionality */ /* Show instructions if turned on and on short path. */ if (alertInstructionsYoutTubeShortRelease == 1) { if (location.href.indexOf(youTubeShortPath) == -1) { alert(youTubeShortReleaseURINotice); } else { alert(` INSTRUCTIONS - YOUTUBE SHOW SHORT RELEASE DATE \n ********************************************** \n After first short has loaded, remaining shorts \n will be automatically updated with release date. \n `); showShortReleaseDate(); runShortReleaseURIInterval = /* interval to update when short changes */ setInterval(checkCurrentShort, 500); } } } })();