diff --git a/dist/birb.js b/dist/birb.js index ae6f91e..00f20ee 100644 --- a/dist/birb.js +++ b/dist/birb.js @@ -1148,6 +1148,11 @@ return path === this.getPath(); } + /** @override */ + areStickyNotesEnabled() { + return this.getPath() !== ROOT_PATH; + } + /** @returns {HTMLElement|null} */ getActiveEditorElement() { // @ts-expect-error @@ -1313,6 +1318,9 @@ * @param {(note: StickyNote) => void} onDelete */ function createNewStickyNote(stickyNotes, onSave, onDelete) { + if (getContext().areStickyNotesEnabled() === false) { + return; + } const id = Date.now().toString(); const site = getContext().getPath(); const stickyNote = new StickyNote(id, site, ""); @@ -1334,23 +1342,34 @@ * @param {string} text * @param {() => void} action * @param {boolean} [removeMenu] - * @param {boolean} [isDebug] */ - constructor(text, action, removeMenu = true, isDebug = false) { + constructor(text, action, removeMenu = true) { this.text = text; this.action = action; this.removeMenu = removeMenu; - this.isDebug = isDebug; } } - class DebugMenuItem extends MenuItem { + class ConditionalMenuItem extends MenuItem { + /** + * @param {string} text + * @param {() => void} action + * @param {() => boolean} condition + * @param {boolean} [removeMenu] + */ + constructor(text, action, condition, removeMenu = true) { + super(text, action, removeMenu); + this.condition = condition; + } + } + + class DebugMenuItem extends ConditionalMenuItem { /** * @param {string} text * @param {() => void} action */ constructor(text, action, removeMenu = true) { - super(text, action, removeMenu, true); + super(text, action, () => isDebug(), removeMenu); } } @@ -1396,7 +1415,7 @@ let content = makeElement("birb-window-content"); const removeCallback = () => removeMenu(); for (const item of menuItems) { - if (!item.isDebug || isDebug()) { + if (!(item instanceof ConditionalMenuItem) || item.condition()) { content.appendChild(makeMenuItem(item, removeCallback)); } } @@ -1453,7 +1472,7 @@ } const removeCallback = () => removeMenu(); for (const item of menuItems) { - if (!item.isDebug || isDebug()) { + if (!(item instanceof ConditionalMenuItem) || item.condition()) { content.appendChild(makeMenuItem(item, removeCallback)); } } @@ -1955,9 +1974,7 @@ const menuItems = [ new MenuItem(`Pet ${birdBirb()}`, pet), new MenuItem("Field Guide", insertFieldGuide), - ...(getContext().areStickyNotesEnabled() ? [ - new MenuItem("Sticky Note", () => createNewStickyNote(stickyNotes, save, deleteStickyNote)) - ] : []), + new ConditionalMenuItem("Sticky Note", () => createNewStickyNote(stickyNotes, save, deleteStickyNote), () => getContext().areStickyNotesEnabled()), new MenuItem(`Hide ${birdBirb()}`, () => birb.setVisible(false)), new DebugMenuItem("Freeze/Unfreeze", () => { frozen = !frozen; @@ -1994,7 +2011,7 @@ insertModal(`${birdBirb()} Mode`, message); }), new Separator(), - new MenuItem("2025.11.14.16", () => { alert("Thank you for using Pocket Bird! You are on version: 2025.11.14.16"); }, false), + new MenuItem("2025.11.14.47", () => { alert("Thank you for using Pocket Bird! You are on version: 2025.11.14.47"); }, false), ]; const styleElement = document.createElement("style"); diff --git a/dist/extension.zip b/dist/extension.zip index 94c87e9..5525574 100644 Binary files a/dist/extension.zip and b/dist/extension.zip differ diff --git a/dist/extension/birb.js b/dist/extension/birb.js index ae6f91e..00f20ee 100644 --- a/dist/extension/birb.js +++ b/dist/extension/birb.js @@ -1148,6 +1148,11 @@ return path === this.getPath(); } + /** @override */ + areStickyNotesEnabled() { + return this.getPath() !== ROOT_PATH; + } + /** @returns {HTMLElement|null} */ getActiveEditorElement() { // @ts-expect-error @@ -1313,6 +1318,9 @@ * @param {(note: StickyNote) => void} onDelete */ function createNewStickyNote(stickyNotes, onSave, onDelete) { + if (getContext().areStickyNotesEnabled() === false) { + return; + } const id = Date.now().toString(); const site = getContext().getPath(); const stickyNote = new StickyNote(id, site, ""); @@ -1334,23 +1342,34 @@ * @param {string} text * @param {() => void} action * @param {boolean} [removeMenu] - * @param {boolean} [isDebug] */ - constructor(text, action, removeMenu = true, isDebug = false) { + constructor(text, action, removeMenu = true) { this.text = text; this.action = action; this.removeMenu = removeMenu; - this.isDebug = isDebug; } } - class DebugMenuItem extends MenuItem { + class ConditionalMenuItem extends MenuItem { + /** + * @param {string} text + * @param {() => void} action + * @param {() => boolean} condition + * @param {boolean} [removeMenu] + */ + constructor(text, action, condition, removeMenu = true) { + super(text, action, removeMenu); + this.condition = condition; + } + } + + class DebugMenuItem extends ConditionalMenuItem { /** * @param {string} text * @param {() => void} action */ constructor(text, action, removeMenu = true) { - super(text, action, removeMenu, true); + super(text, action, () => isDebug(), removeMenu); } } @@ -1396,7 +1415,7 @@ let content = makeElement("birb-window-content"); const removeCallback = () => removeMenu(); for (const item of menuItems) { - if (!item.isDebug || isDebug()) { + if (!(item instanceof ConditionalMenuItem) || item.condition()) { content.appendChild(makeMenuItem(item, removeCallback)); } } @@ -1453,7 +1472,7 @@ } const removeCallback = () => removeMenu(); for (const item of menuItems) { - if (!item.isDebug || isDebug()) { + if (!(item instanceof ConditionalMenuItem) || item.condition()) { content.appendChild(makeMenuItem(item, removeCallback)); } } @@ -1955,9 +1974,7 @@ const menuItems = [ new MenuItem(`Pet ${birdBirb()}`, pet), new MenuItem("Field Guide", insertFieldGuide), - ...(getContext().areStickyNotesEnabled() ? [ - new MenuItem("Sticky Note", () => createNewStickyNote(stickyNotes, save, deleteStickyNote)) - ] : []), + new ConditionalMenuItem("Sticky Note", () => createNewStickyNote(stickyNotes, save, deleteStickyNote), () => getContext().areStickyNotesEnabled()), new MenuItem(`Hide ${birdBirb()}`, () => birb.setVisible(false)), new DebugMenuItem("Freeze/Unfreeze", () => { frozen = !frozen; @@ -1994,7 +2011,7 @@ insertModal(`${birdBirb()} Mode`, message); }), new Separator(), - new MenuItem("2025.11.14.16", () => { alert("Thank you for using Pocket Bird! You are on version: 2025.11.14.16"); }, false), + new MenuItem("2025.11.14.47", () => { alert("Thank you for using Pocket Bird! You are on version: 2025.11.14.47"); }, false), ]; const styleElement = document.createElement("style"); diff --git a/dist/extension/manifest.json b/dist/extension/manifest.json index 43c5156..b0b3fee 100644 --- a/dist/extension/manifest.json +++ b/dist/extension/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 3, "name": "Pocket Bird", "description": "It's a pet bird in your browser, what more could you want?", - "version": "2025.11.14.16", + "version": "2025.11.14.47", "homepage_url": "https://idreesinc.com", "icons": { "48": "images/icons/transparent/48x48x1.png", diff --git a/dist/obsidian/main.js b/dist/obsidian/main.js index 145d3ce..a1a46d3 100644 --- a/dist/obsidian/main.js +++ b/dist/obsidian/main.js @@ -2,7 +2,7 @@ const { Plugin, Notice } = require('obsidian'); module.exports = class PocketBird extends Plugin { onload() { - console.log("Loading Pocket Bird version 2025.11.14.16..."); + console.log("Loading Pocket Bird version 2025.11.14.47..."); const OBSIDIAN_PLUGIN = this; (function () { 'use strict'; @@ -1154,6 +1154,11 @@ module.exports = class PocketBird extends Plugin { return path === this.getPath(); } + /** @override */ + areStickyNotesEnabled() { + return this.getPath() !== ROOT_PATH; + } + /** @returns {HTMLElement|null} */ getActiveEditorElement() { // @ts-expect-error @@ -1319,6 +1324,9 @@ module.exports = class PocketBird extends Plugin { * @param {(note: StickyNote) => void} onDelete */ function createNewStickyNote(stickyNotes, onSave, onDelete) { + if (getContext().areStickyNotesEnabled() === false) { + return; + } const id = Date.now().toString(); const site = getContext().getPath(); const stickyNote = new StickyNote(id, site, ""); @@ -1340,23 +1348,34 @@ module.exports = class PocketBird extends Plugin { * @param {string} text * @param {() => void} action * @param {boolean} [removeMenu] - * @param {boolean} [isDebug] */ - constructor(text, action, removeMenu = true, isDebug = false) { + constructor(text, action, removeMenu = true) { this.text = text; this.action = action; this.removeMenu = removeMenu; - this.isDebug = isDebug; } } - class DebugMenuItem extends MenuItem { + class ConditionalMenuItem extends MenuItem { + /** + * @param {string} text + * @param {() => void} action + * @param {() => boolean} condition + * @param {boolean} [removeMenu] + */ + constructor(text, action, condition, removeMenu = true) { + super(text, action, removeMenu); + this.condition = condition; + } + } + + class DebugMenuItem extends ConditionalMenuItem { /** * @param {string} text * @param {() => void} action */ constructor(text, action, removeMenu = true) { - super(text, action, removeMenu, true); + super(text, action, () => isDebug(), removeMenu); } } @@ -1402,7 +1421,7 @@ module.exports = class PocketBird extends Plugin { let content = makeElement("birb-window-content"); const removeCallback = () => removeMenu(); for (const item of menuItems) { - if (!item.isDebug || isDebug()) { + if (!(item instanceof ConditionalMenuItem) || item.condition()) { content.appendChild(makeMenuItem(item, removeCallback)); } } @@ -1459,7 +1478,7 @@ module.exports = class PocketBird extends Plugin { } const removeCallback = () => removeMenu(); for (const item of menuItems) { - if (!item.isDebug || isDebug()) { + if (!(item instanceof ConditionalMenuItem) || item.condition()) { content.appendChild(makeMenuItem(item, removeCallback)); } } @@ -1961,9 +1980,7 @@ module.exports = class PocketBird extends Plugin { const menuItems = [ new MenuItem(`Pet ${birdBirb()}`, pet), new MenuItem("Field Guide", insertFieldGuide), - ...(getContext().areStickyNotesEnabled() ? [ - new MenuItem("Sticky Note", () => createNewStickyNote(stickyNotes, save, deleteStickyNote)) - ] : []), + new ConditionalMenuItem("Sticky Note", () => createNewStickyNote(stickyNotes, save, deleteStickyNote), () => getContext().areStickyNotesEnabled()), new MenuItem(`Hide ${birdBirb()}`, () => birb.setVisible(false)), new DebugMenuItem("Freeze/Unfreeze", () => { frozen = !frozen; @@ -2000,7 +2017,7 @@ module.exports = class PocketBird extends Plugin { insertModal(`${birdBirb()} Mode`, message); }), new Separator(), - new MenuItem("2025.11.14.16", () => { alert("Thank you for using Pocket Bird! You are on version: 2025.11.14.16"); }, false), + new MenuItem("2025.11.14.47", () => { alert("Thank you for using Pocket Bird! You are on version: 2025.11.14.47"); }, false), ]; const styleElement = document.createElement("style"); diff --git a/dist/obsidian/manifest.json b/dist/obsidian/manifest.json index 8066f1f..4f6128c 100644 --- a/dist/obsidian/manifest.json +++ b/dist/obsidian/manifest.json @@ -1,7 +1,7 @@ { "id": "pocket-bird", "name": "Pocket Bird", - "version": "2025.11.14.16", + "version": "2025.11.14.47", "minAppVersion": "0.15.0", "description": "It's a pet bird in your Obsidian, what more could you want?", "author": "Idrees Hassan", diff --git a/dist/userscript/birb.user.js b/dist/userscript/birb.user.js index 4741ba3..765098d 100644 --- a/dist/userscript/birb.user.js +++ b/dist/userscript/birb.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name Pocket Bird // @namespace https://idreesinc.com -// @version 2025.11.14.16 +// @version 2025.11.14.47 // @description It's a bird that hops around your web browser, the future is here // @author Idrees // @downloadURL https://github.com/IdreesInc/Pocket-Bird/raw/refs/heads/main/dist/userscript/birb.user.js @@ -1162,6 +1162,11 @@ return path === this.getPath(); } + /** @override */ + areStickyNotesEnabled() { + return this.getPath() !== ROOT_PATH; + } + /** @returns {HTMLElement|null} */ getActiveEditorElement() { // @ts-expect-error @@ -1327,6 +1332,9 @@ * @param {(note: StickyNote) => void} onDelete */ function createNewStickyNote(stickyNotes, onSave, onDelete) { + if (getContext().areStickyNotesEnabled() === false) { + return; + } const id = Date.now().toString(); const site = getContext().getPath(); const stickyNote = new StickyNote(id, site, ""); @@ -1348,23 +1356,34 @@ * @param {string} text * @param {() => void} action * @param {boolean} [removeMenu] - * @param {boolean} [isDebug] */ - constructor(text, action, removeMenu = true, isDebug = false) { + constructor(text, action, removeMenu = true) { this.text = text; this.action = action; this.removeMenu = removeMenu; - this.isDebug = isDebug; } } - class DebugMenuItem extends MenuItem { + class ConditionalMenuItem extends MenuItem { + /** + * @param {string} text + * @param {() => void} action + * @param {() => boolean} condition + * @param {boolean} [removeMenu] + */ + constructor(text, action, condition, removeMenu = true) { + super(text, action, removeMenu); + this.condition = condition; + } + } + + class DebugMenuItem extends ConditionalMenuItem { /** * @param {string} text * @param {() => void} action */ constructor(text, action, removeMenu = true) { - super(text, action, removeMenu, true); + super(text, action, () => isDebug(), removeMenu); } } @@ -1410,7 +1429,7 @@ let content = makeElement("birb-window-content"); const removeCallback = () => removeMenu(); for (const item of menuItems) { - if (!item.isDebug || isDebug()) { + if (!(item instanceof ConditionalMenuItem) || item.condition()) { content.appendChild(makeMenuItem(item, removeCallback)); } } @@ -1467,7 +1486,7 @@ } const removeCallback = () => removeMenu(); for (const item of menuItems) { - if (!item.isDebug || isDebug()) { + if (!(item instanceof ConditionalMenuItem) || item.condition()) { content.appendChild(makeMenuItem(item, removeCallback)); } } @@ -1969,9 +1988,7 @@ const menuItems = [ new MenuItem(`Pet ${birdBirb()}`, pet), new MenuItem("Field Guide", insertFieldGuide), - ...(getContext().areStickyNotesEnabled() ? [ - new MenuItem("Sticky Note", () => createNewStickyNote(stickyNotes, save, deleteStickyNote)) - ] : []), + new ConditionalMenuItem("Sticky Note", () => createNewStickyNote(stickyNotes, save, deleteStickyNote), () => getContext().areStickyNotesEnabled()), new MenuItem(`Hide ${birdBirb()}`, () => birb.setVisible(false)), new DebugMenuItem("Freeze/Unfreeze", () => { frozen = !frozen; @@ -2008,7 +2025,7 @@ insertModal(`${birdBirb()} Mode`, message); }), new Separator(), - new MenuItem("2025.11.14.16", () => { alert("Thank you for using Pocket Bird! You are on version: 2025.11.14.16"); }, false), + new MenuItem("2025.11.14.47", () => { alert("Thank you for using Pocket Bird! You are on version: 2025.11.14.47"); }, false), ]; const styleElement = document.createElement("style"); diff --git a/src/application.js b/src/application.js index 8ba58fe..a7b6ef1 100644 --- a/src/application.js +++ b/src/application.js @@ -31,6 +31,7 @@ import { } from './stickyNotes.js'; import { MenuItem, + ConditionalMenuItem, DebugMenuItem, Separator, insertMenu, @@ -193,9 +194,7 @@ Promise.all([ const menuItems = [ new MenuItem(`Pet ${birdBirb()}`, pet), new MenuItem("Field Guide", insertFieldGuide), - ...(getContext().areStickyNotesEnabled() ? [ - new MenuItem("Sticky Note", () => createNewStickyNote(stickyNotes, save, deleteStickyNote)) - ] : []), + new ConditionalMenuItem("Sticky Note", () => createNewStickyNote(stickyNotes, save, deleteStickyNote), () => getContext().areStickyNotesEnabled()), new MenuItem(`Hide ${birdBirb()}`, () => birb.setVisible(false)), new DebugMenuItem("Freeze/Unfreeze", () => { frozen = !frozen; diff --git a/src/context.js b/src/context.js index 1600065..5811414 100644 --- a/src/context.js +++ b/src/context.js @@ -305,6 +305,11 @@ export class ObsidianContext extends Context { return path === this.getPath(); } + /** @override */ + areStickyNotesEnabled() { + return this.getPath() !== ROOT_PATH; + } + /** @returns {HTMLElement|null} */ getActiveEditorElement() { // @ts-expect-error diff --git a/src/menu.js b/src/menu.js index f4e7c68..1d67c18 100644 --- a/src/menu.js +++ b/src/menu.js @@ -15,23 +15,34 @@ export class MenuItem { * @param {string} text * @param {() => void} action * @param {boolean} [removeMenu] - * @param {boolean} [isDebug] */ - constructor(text, action, removeMenu = true, isDebug = false) { + constructor(text, action, removeMenu = true) { this.text = text; this.action = action; this.removeMenu = removeMenu; - this.isDebug = isDebug; } } -export class DebugMenuItem extends MenuItem { +export class ConditionalMenuItem extends MenuItem { + /** + * @param {string} text + * @param {() => void} action + * @param {() => boolean} condition + * @param {boolean} [removeMenu] + */ + constructor(text, action, condition, removeMenu = true) { + super(text, action, removeMenu); + this.condition = condition; + } +} + +export class DebugMenuItem extends ConditionalMenuItem { /** * @param {string} text * @param {() => void} action */ constructor(text, action, removeMenu = true) { - super(text, action, removeMenu, true); + super(text, action, () => isDebug(), removeMenu); } } @@ -77,7 +88,7 @@ export function insertMenu(menuItems, title, updateLocationCallback) { let content = makeElement("birb-window-content"); const removeCallback = () => removeMenu(); for (const item of menuItems) { - if (!item.isDebug || isDebug()) { + if (!(item instanceof ConditionalMenuItem) || item.condition()) { content.appendChild(makeMenuItem(item, removeCallback)); } } @@ -134,7 +145,7 @@ export function switchMenuItems(menuItems, updateLocationCallback) { } const removeCallback = () => removeMenu(); for (const item of menuItems) { - if (!item.isDebug || isDebug()) { + if (!(item instanceof ConditionalMenuItem) || item.condition()) { content.appendChild(makeMenuItem(item, removeCallback)); } } diff --git a/src/stickyNotes.js b/src/stickyNotes.js index 130f52d..8fc8ecf 100644 --- a/src/stickyNotes.js +++ b/src/stickyNotes.js @@ -129,6 +129,9 @@ export function drawStickyNotes(stickyNotes, onSave, onDelete) { * @param {(note: StickyNote) => void} onDelete */ export function createNewStickyNote(stickyNotes, onSave, onDelete) { + if (getContext().areStickyNotesEnabled() === false) { + return; + } const id = Date.now().toString(); const site = getContext().getPath(); const stickyNote = new StickyNote(id, site, "");