Skip to content

Instantly share code, notes, and snippets.

@GitMurf
GitMurf / filter-focus.js
Last active March 12, 2021 16:46
Roam JavaScript to focus on search box when opening a filter
document.addEventListener('click', function (evt) {
if (evt.target.className === 'bp3-icon bp3-icon-filter') {
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function removeFilters(event) {
var filteredButtons = event.target.parentElement.parentElement.parentElement.getElementsByTagName('BUTTON')
if (filteredButtons.length == 0 || filteredButtons == null) { return }
@GitMurf
GitMurf / query-todo-daily.js
Last active October 16, 2020 23:31
Query TODO due dates, filtering out Daily Note page
//v0.3
//To apply TODO filter, use Shift + Click on the query syntax when a query is loaded with results
//Use this link to see GIF of DEMO: https://user-images.githubusercontent.com/64155612/95497690-9c0f8680-0957-11eb-94a7-e0cd49d62a06.gif
//The goal of this script is to filter out TODOs that only show up because they were added on daily notes page
//Mainly it is if you want to find overdue tasks, like from the last week, by default a TODO due next week will still
//show up if you added that TODO on a daily notes page from last week (within the between range)
//Resources about the script:
//For detailed discussion, see this Slack thread: https://roamresearch.slack.com/archives/C012WK8E9DK/p1601992542022100
//Here is my github repo: https://github.com/GitMurf/roam-javascript
@GitMurf
GitMurf / attr-table-filters.js
Last active June 13, 2023 03:16
Filtering attribute tables
/*
****************************************************************************************
****************************************************************************************
****************************************************************************************
NOW HOSTING CODE VIA MY MAIN GITHUB REPOSITORY FOR ROAM SO THAT USERS CAN LINK DIRECTLY TO THE CODE AND AUTO UPDATE
GO HERE FOR INSTALLATION INSTRUCTIONS: https://github.com/GitMurf/roam-javascript#installation
****************************************************************************************
@GitMurf
GitMurf / obsidian.templater.create-and-copy-block-ref-id.js
Last active January 10, 2024 11:32
Credit to: @shabegom - Add a block ref to the current line by adding a ^uniqueId on the end and copying to the clipboard the embed reference link so you can quickly paste the block ref somewhere else in your vault. Similar to Roam ctrl + click and drag to create block ref.
<%*
//v1.1: Changed to using the new "view.editor" instead of deprecated "view.sourceMode.cmEditor"
let cmEditorAct = this.app.workspace.activeLeaf.view.editor;
let curLine = cmEditorAct.getCursor().line;
cmEditorAct.setSelection({ line: curLine, ch: 0 }, { line: curLine, ch: 9999 });
function createBlockHash() {
let result = '';
var characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
@GitMurf
GitMurf / obsidian.templater.replace-block-ref-with-text.js
Last active January 27, 2023 21:42
Replace a block ref in the current line with the actual text from the block ref. It replicates Roam's feature where you right-click a block ref and choose "Replace as text".
<%*
//v1.1: Changed to using the new "view.editor" instead of deprecated "view.sourceMode.cmEditor"
let thisFile = this.app.workspace.getActiveFile();
let thisFileCache = this.app.metadataCache.getFileCache(thisFile);
let embedsOnPage = thisFileCache.embeds;
if(embedsOnPage) {
let cmEditorAct = this.app.workspace.activeLeaf.view.editor;
let curLine = cmEditorAct.getCursor().line;
@GitMurf
GitMurf / obsidian.templater.quick-capture.js
Last active April 22, 2024 15:14
Obsidian Quick Capture using templater. Activate from anywhere in your vault to record quick ideas, notes, time logging, etc. The Quick Capture file does NOT need to be open.
<%*
//v1.4: Adding option for including a header for each DNP day to fold
//'first' will add to top of file. 'last' will add to bottom of file
let firstOrLastLine = 'first';
//Name of the Quick Capture file. Do NOT include extension '.md'
let qcFileName = 'Quick Capture';
//Leave this blank if you want to use the default file path location (set to '/' to use root of vault)
@GitMurf
GitMurf / obsidian.templater.nlp-date-input.js
Created April 22, 2021 19:04
Requires @argenos Natural Language Dates Plugin. Pop up input box asks for date and then parses it as a date and turns it into a [[Daily Notes Page]] page ref.
<%*
//v1.0
let dueDateStr = await tp.system.prompt("Due Date");
let parseResult;
let parseResultLink;
if(dueDateStr) {
let nlDatesPlugin = this.app.plugins.getPlugin('nldates-obsidian');
parseResult = nlDatesPlugin.parseDate(dueDateStr);
if(parseResult){parseResultLink = '[' + '[' + parseResult.formattedString + ']]';}
@GitMurf
GitMurf / obsidian.css.block-ref-inline.css
Created April 22, 2021 19:41
This CSS allows for block references to show inline as well as less "bulky" when they are on their own line.
/* INLINE BLOCK REFS v1.0 */
:root {
--block-ref-color: yellow;
--block-ref-link-color: transparent;
}
.markdown-preview-view span[src*="^"].internal-embed:not(.image-embed) > div.markdown-embed {
border-top: none;
border-bottom-color: var(--block-ref-color);
border-bottom-style: dashed;
padding: 0px;
@GitMurf
GitMurf / obsidian.templater.move-line.js
Last active October 10, 2023 11:56
Move the active line of the active file to a chosen file.
<%*
//v1.6.2: Fix with update to Templater where wasn't removing the selected text/line "on move"
//'first' will add to top of file. 'last' will add to bottom of file
let firstOrLastLine = 'last';
//Choose a specific line to move to underneath; overrules firstOrLastLine if true
const bChooseLine = false;
//After moving the line, open the file it was moved to
@GitMurf
GitMurf / obsidian.templater.pull-line.js
Last active May 5, 2021 22:43
Pull a line to the active file from a specified file without having to open it.
<%*
//v1.2: For block refs / embeds need to add line breaks above and below otherwise block ref extends to lines around it
//"pull" = default: removes the line, "pull-copy" leaves line, "pull-embed" leaves embed, "pull-ref" adds block ref
const pullMode = "pull";
const pullFromFile = await tp.system.suggester((item) => item.path, this.app.vault.getMarkdownFiles(), false);
if(pullFromFile) {
let cmEditorAct = this.app.workspace.activeLeaf.view.editor;