Created
September 20, 2025 11:14
-
-
Save extratone/81444869942cace17a736d5e43312fcc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| class Bear { | |
| static get bearBaseURL() { | |
| return "bear://x-callback-url/"; | |
| } | |
| static formatNewNote(tags) { | |
| if (tags == undefined) tags = []; | |
| else if (!Array.isArray(tags)) tags = [tags]; | |
| return ( | |
| "# " + | |
| draft.content + | |
| "\n\n---\n(from a draft created on " + | |
| draft.createdAt + | |
| ")\n" + | |
| tags.map((t) => "#" + t).join(" ") + | |
| "\n" | |
| ); | |
| } | |
| static isNoteID(str) { | |
| return /^[A-Z0-9]+(\-[A-Z0-9]+)*$/.test(str); | |
| } | |
| static paramNameFor(note) { | |
| if (Bear.isNoteID(note)) return "id"; | |
| else return "title"; | |
| } | |
| static executeAction(action, parameters) { | |
| if (parameters == undefined) parameters = {}; | |
| var cb = CallbackURL.create(); | |
| cb.baseURL = Bear.bearBaseURL + action; | |
| cb.parameters = parameters; | |
| // open and wait for result | |
| var success = cb.open(); | |
| if (success) { | |
| return cb.callbackResponse; | |
| } else { | |
| // something went wrong or was cancelled | |
| console.log(cb.status); | |
| if (cb.status == "cancel") context.cancel(); | |
| else context.fail(); | |
| return false; | |
| } | |
| } | |
| static executeActionOn(action, note, parameters) { | |
| if (parameters == undefined) parameters = {}; | |
| parameters[Bear.paramNameFor(note)] = note; | |
| return Bear.executeAction(action, parameters); | |
| } | |
| static open(note) { | |
| var url = Bear.bearBaseURL + "open-note?" + Bear.paramNameFor(note) + "=" + encodeURIComponent(note); | |
| return app.openURL(url); | |
| } | |
| static create(text, options) { | |
| if (options == undefined) options = {}; | |
| if (options.pin == undefined) options.pin = false; | |
| return Bear.executeAction("create", { | |
| title: options.title, | |
| text: text, | |
| pin: options.pin ? "yes" : "no", | |
| }); | |
| } | |
| static createFromCurrentDraft(tags, options) { | |
| return Bear.create(Bear.formatNewNote(tags), options); | |
| } | |
| static addTextTo(note, mode, text) { | |
| if (text == undefined) text = draft.content; | |
| return Bear.executeActionOn("add-text", note, { | |
| mode: mode, | |
| text: text, | |
| exclude_trashed: "yes", | |
| }); | |
| } | |
| static prependTo(note, template, text) { | |
| if (text == undefined) text = draft.content; | |
| switch (template) { | |
| case "list": | |
| text = "- " + text; | |
| break; | |
| case "section": | |
| text = text + "\n---\n"; | |
| break; | |
| case "plain": | |
| default: | |
| text = text; | |
| } | |
| return Bear.addTextTo(note, "prepend", text); | |
| } | |
| static appendTo(note, template, text) { | |
| if (text == undefined) text = draft.content; | |
| switch (template) { | |
| case "list": | |
| text = "- " + text; | |
| break; | |
| case "section": | |
| text = "\n---\n" + text; | |
| break; | |
| case "plain": | |
| default: | |
| text = text; | |
| } | |
| return Bear.addTextTo(note, "append", text); | |
| } | |
| } | |
| class BearNote { | |
| constructor(data) { | |
| this._identifier = data.identifier; | |
| this._content = data.note; | |
| this._title = data.title; | |
| this._isTrashed = data.is_trashed == "yes"; | |
| this._creationDate = new Date(data.creationDate); | |
| this._modificationDate = new Date(data.modificationDate); | |
| } | |
| get identifier() { | |
| return this._identifier; | |
| } | |
| get title() { | |
| return this._title; | |
| } | |
| get isTrashed() { | |
| return this._isTrashed; | |
| } | |
| get creationDate() { | |
| return this._creationDate; | |
| } | |
| get modificationDate() { | |
| return this._modificationDate; | |
| } | |
| get content() { | |
| return this._content; | |
| } | |
| set content(newContent) { | |
| this.addText("replace_all", newContent); | |
| } | |
| trash() { | |
| var result = Bear.executeActionOn("trash", this.identifier); | |
| this._isTrashed = true; | |
| this._modificationDate = Date.now(); | |
| return result; | |
| } | |
| addText(mode, text) { | |
| var result = Bear.addTextTo(this.identifier, mode, text); | |
| this._title = result.title; | |
| this._content = result.note; | |
| this._modificationDate = Date.now(); | |
| return result; | |
| } | |
| prepend(text) { | |
| return this.addText("prepend", text); | |
| } | |
| append(text) { | |
| return this.addText("append", text); | |
| } | |
| static fetch(note) { | |
| return new BearNote(Bear.executeActionOn("open-note", note)); | |
| } | |
| static create(content) { | |
| return BearNote.fetch(Bear.create(content).identifier); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The Runt Por Placa allows you to check a vehicle's history in Colombia using only the license plate. It's useful for verifying fines, technical data, and whether it's registered with the RUNT. It's an essential tool before buying a used car and ensures informed decisions.