title: Semester Period
startDate: 2025-10-01
startTime: 08:00:00
endDate: 2026-03-29
endTime: 14:00:00
type: circle
color: #ff5722
trailColor: #f5f5f5
infoFormat: {percent}% complete - {remaining} until {end:LLL d, yyyy}
updateInRealTime: true
updateIntervalInSeconds: 30
Last active
October 27, 2025 13:06
-
-
Save mo-karbalaee/30ad922206e52ba9fc033df86b12099d to your computer and use it in GitHub Desktop.
Useful Obsidian code snippets for my daily use. Feel free to copy and enjoy.
// Get all tasks in the current note
let tasks = dv.current().file.tasks;
// Store counts in variables
let totalTasks = tasks.length;
let completedTasks = tasks.filter(t => t.checked).length;
let notCompletedTasks = tasks.filter(t => !t.checked).length;
// Compute ratio of undone/done if needed
let ratioUndoneToDone = notCompletedTasks / completedTasks;
// Now all numbers are stored in variables and can be used in code
// Example: using them in a string
let statusSummary = `Total: ${totalTasks}, Completed: ${completedTasks}, Not Completed: ${notCompletedTasks}, Ratio Undone/Done: ${ratioUndoneToDone}`;
statusSummary // this line "returns" the string in the note
// Get tasks
let tasks = dv.current().file.tasks;
let totalTasks = tasks.length;
let completedTasks = tasks.filter(t => t.checked).length;
let notCompletedTasks = totalTasks - completedTasks;
// Calculate ratio
let ratio = totalTasks === 0 ? 0 : completedTasks / totalTasks;
// Progress bar styling
let barWidth = 300; // total width in pixels
let filledWidth = barWidth * ratio;
// Generate HTML progress bar
let htmlBar = `
<div style="background-color:#eee; border-radius:8px; width:${barWidth}px; height:20px; overflow:hidden;">
<div style="background-color:#4caf50; width:${filledWidth}px; height:100%; transition: width 0.3s;"></div>
</div>
<div style="margin-top:4px; font-weight:bold;">${completedTasks}/${totalTasks} completed</div>
</div>
`;
// Render HTML
dv.el("div", htmlBar, {allowHTML: true});
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment