Skip to content

Instantly share code, notes, and snippets.

@temberature
Created April 16, 2022 10:34
Show Gist options
  • Save temberature/51eb690378cabbf32d2fb2be35b4bd7f to your computer and use it in GitHub Desktop.
Save temberature/51eb690378cabbf32d2fb2be35b4bd7f to your computer and use it in GitHub Desktop.
(function () {
const ea = window.ExcalidrawAutomate;
ea.onDropHook = async function (data) {
console.log(data);
if (
data.payload.text &&
data.payload.text.substring(0, 11) == "obsidian://"
) {
ea.reset();
ea.setView("active");
const path =
decodeURIComponent(data.payload.text.split("&")[1].split("=")[1]) +
".md";
await ea.addImage(
data.pointerPosition.y,
data.pointerPosition.x,
app.vault.getAbstractFileByPath(path)
);
ea.addElementsToView(true, false, true);
return true;
} else if (data.payload.files) {
ea.reset();
ea.setView("active");
const path = data.payload.files[0].path;
await ea.addImage(
data.pointerPosition.y,
data.pointerPosition.x,
app.vault.getAbstractFileByPath(path)
);
ea.addElementsToView(true, false, true);
return true;
} else if (data.payload.text) {
ea.reset();
ea.setView("active");
await ea.addText(
data.pointerPosition.y,
data.pointerPosition.x,
data.payload.text,
{ width: 300, box: true, wrapAt: 250 }
);
await ea.addElementsToView(true, false, true);
return true;
}
return false;
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment