Last active
December 6, 2025 02:01
-
-
Save ALifeLivedFully/5f9acb22a9caf6dc703f01e3cb0363c5 to your computer and use it in GitHub Desktop.
A modified version of another template with the added functions of allowing longer timestamps, and allowing youtube short links (Like so: https://youtu.be/dQw4w9WgXcQ) credit to https://github.com/torantine for the original timestamp script & https://github.com/duckpuppy for allowing longer timestamps. The original script discussion can be found…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <%* | |
| // define function to replace timestamps in file | |
| async function replaceTimestamp () { | |
| const regexHHMM = /YT=((\d+):([0-5]\d))/g; | |
| // change "YT=" if you want a different search term. currently videos cannot be longer than 99m59s | |
| var content = tp.file.content; // *content of file* | |
| var matches = content.matchAll(regexHHMM); // *find all regex matches in file* | |
| for(let match of matches){ | |
| content = content.replace( | |
| match[0], | |
| "["+match[1]+"]("+urlPrompt+"&t="+match[2]+"m"+match[3]+"s)" | |
| ); // *make YouTube URL from first match* | |
| } | |
| var file = app.workspace.activeLeaf.view.file; // *get current file* | |
| await app.vault.modify(file, content); // *replace content with new content* | |
| } | |
| // if url is in frontmatter and contains youtube, check if it contains http then run function, else prompt user for url | |
| var url = tp.frontmatter.url; // *get url field from frontmatter* | |
| if(url != undefined && url.contains("youtu") === true){ | |
| if (url.includes("https://") === false){ | |
| url = "https://" + url; | |
| }; | |
| urlPrompt = url; | |
| await replaceTimestamp(); | |
| } else { | |
| if(url === undefined){url = "Enter a YouTube URL"}; // *if url doesnt exist* | |
| var urlPrompt; | |
| while(urlPrompt == null || urlPrompt.length < 1 || urlPrompt.contains("youtu") === false){urlPrompt = (await tp.system.prompt("YouTube URL:", url, 1))}; | |
| // *proper conditions are not met, reprompt* | |
| if (urlPrompt.includes("https://") === false){urlPrompt = "https://" + urlPrompt} | |
| await replaceTimestamp(); | |
| } | |
| %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment