Skip to content

Instantly share code, notes, and snippets.

@aadimator
Created February 12, 2022 17:46
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aadimator/87b8411e12a2499f83c1cab2cfdf9e22 to your computer and use it in GitHub Desktop.
Save aadimator/87b8411e12a2499f83c1cab2cfdf9e22 to your computer and use it in GitHub Desktop.
LogSeq Timestamp Process
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;
}
iframe[id^='youtube-player'] {
height: 700px !important;
}
  • template:: youtube tags:: #📥/🎥️YouTube status:: #to/process presenter:: link:: title:: published-on:: processed-on::
    • [[YouTube Embed]]
    • [[Notes]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment