- template:: youtube
tags:: #📥/🎥️YouTube
status:: #to/process
presenter::
link::
title::
published-on::
processed-on::
- [[YouTube Embed]]
- [[Notes]]
- [[YouTube Embed]]
Created
February 12, 2022 17:46
-
-
Save aadimator/87b8411e12a2499f83c1cab2cfdf9e22 to your computer and use it in GitHub Desktop.
LogSeq Timestamp Process
This file contains 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
const notice = (msg) => new Notice(msg, 5000); | |
const log = (msg) => console.log(msg); | |
module.exports = async function processLogseq(params) { | |
const {app, quickAddApi: {yesNoPrompt, inputPrompt, utility}} = params; | |
const shouldRemove = await yesNoPrompt("Should I remove timestamps?", `If you say no, I'll process them to be default youtube timestamp links. If you say yes, I'll simply remove them.`); | |
let text = await utility.getClipboard(); | |
text = text.toString(); | |
if (shouldRemove) { | |
text = removeTimestamps(text); | |
} else { | |
const link = await inputPrompt( | |
"Enter YouTube Video Link: " | |
); | |
if (!link) { | |
notice("No link entered."); | |
throw new Error("No link entered."); | |
} | |
text = processTimestamps(text, link); | |
} | |
console.log(text); | |
await utility.setClipboard(text); | |
console.log("Finished!"); | |
} | |
function removeTimestamps(text) { | |
console.log("Remove Timestamps"); | |
return text.replace(/\{\{youtube-timestamp\([0-9]+\)\}\}\s/g, ""); | |
} | |
function processTimestamps(text, link) { | |
function convert(str, p1, offset, s) { | |
let time = parseInt(p1); | |
let parsedTime = new Date(time * 1000).toISOString(); | |
if (time < 3600) { | |
// MM:SS | |
parsedTime = parsedTime.substring(14, 19); | |
} else { | |
// HH:MM:SS | |
parsedTime = parsedTime.substring(11, 19); | |
} | |
return "[🕒 " + parsedTime + "](" + link + "?t=" + time + ")"; | |
} | |
text = text.replace(/\{\{youtube-timestamp\(([0-9]+)\)\}\}\s/g, convert); | |
return text; | |
} | |
This file contains 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
iframe[id^='youtube-player'] { | |
height: 700px !important; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment