Move sticky note element to context

This commit is contained in:
Idrees Hassan
2025-11-13 22:53:44 -05:00
parent fbbfd25f30
commit 3ec124a1b3
9 changed files with 93 additions and 38 deletions

25
dist/birb.js vendored
View File

@@ -900,6 +900,14 @@
return window.location.href;
}
/**
* @returns {HTMLElement} The current active page element where sticky notes can be applied
*/
getActivePage() {
// Default to root element
return document.documentElement;
}
/**
* Checks if a path is applicable given the context
* @param {string} path Can be a site URL or another context-specific path
@@ -1173,11 +1181,12 @@
/**
* @param {StickyNote} stickyNote
* @param {HTMLElement} page
* @param {() => void} onSave
* @param {() => void} onDelete
* @returns {HTMLElement}
*/
function renderStickyNote(stickyNote, onSave, onDelete) {
function renderStickyNote(stickyNote, page, onSave, onDelete) {
const noteElement = makeElement("birb-window");
noteElement.classList.add("birb-sticky-note");
@@ -1202,7 +1211,7 @@
noteElement.style.top = `${stickyNote.top}px`;
noteElement.style.left = `${stickyNote.left}px`;
document.body.appendChild(noteElement);
page.appendChild(noteElement);
makeDraggable(header, true, (top, left) => {
stickyNote.top = top;
@@ -1253,10 +1262,11 @@
const existingNotes = document.querySelectorAll(".birb-sticky-note");
existingNotes.forEach(note => note.remove());
// Render all sticky notes
const pageElement = getContext().getActivePage();
const context = getContext();
for (let stickyNote of stickyNotes) {
if (context.isPathApplicable(stickyNote.site)) {
renderStickyNote(stickyNote, onSave, () => onDelete(stickyNote));
renderStickyNote(stickyNote, pageElement, onSave, () => onDelete(stickyNote));
}
}
}
@@ -1270,9 +1280,10 @@
const id = Date.now().toString();
const site = getContext().getPath();
const stickyNote = new StickyNote(id, site, "");
const element = renderStickyNote(stickyNote, onSave, () => onDelete(stickyNote));
element.style.left = `${window.innerWidth / 2 - element.offsetWidth / 2}px`;
element.style.top = `${window.scrollY + window.innerHeight / 2 - element.offsetHeight / 2}px`;
const page = getContext().getActivePage();
const element = renderStickyNote(stickyNote, page, onSave, () => onDelete(stickyNote));
element.style.left = `${page.clientWidth / 2 - element.offsetWidth / 2}px`;
element.style.top = `${page.scrollTop + page.clientHeight / 2 - element.offsetHeight / 2}px`;
stickyNote.top = parseInt(element.style.top, 10);
stickyNote.left = parseInt(element.style.left, 10);
stickyNotes.push(stickyNote);
@@ -1946,7 +1957,7 @@
insertModal(`${birdBirb()} Mode`, message);
}),
new Separator(),
new MenuItem("2025.11.13.64", () => { alert("Thank you for using Pocket Bird! You are on version: 2025.11.13.64"); }, false),
new MenuItem("2025.11.13.80", () => { alert("Thank you for using Pocket Bird! You are on version: 2025.11.13.80"); }, false),
];
const styleElement = document.createElement("style");

BIN
dist/extension.zip vendored

Binary file not shown.

View File

@@ -900,6 +900,14 @@
return window.location.href;
}
/**
* @returns {HTMLElement} The current active page element where sticky notes can be applied
*/
getActivePage() {
// Default to root element
return document.documentElement;
}
/**
* Checks if a path is applicable given the context
* @param {string} path Can be a site URL or another context-specific path
@@ -1173,11 +1181,12 @@
/**
* @param {StickyNote} stickyNote
* @param {HTMLElement} page
* @param {() => void} onSave
* @param {() => void} onDelete
* @returns {HTMLElement}
*/
function renderStickyNote(stickyNote, onSave, onDelete) {
function renderStickyNote(stickyNote, page, onSave, onDelete) {
const noteElement = makeElement("birb-window");
noteElement.classList.add("birb-sticky-note");
@@ -1202,7 +1211,7 @@
noteElement.style.top = `${stickyNote.top}px`;
noteElement.style.left = `${stickyNote.left}px`;
document.body.appendChild(noteElement);
page.appendChild(noteElement);
makeDraggable(header, true, (top, left) => {
stickyNote.top = top;
@@ -1253,10 +1262,11 @@
const existingNotes = document.querySelectorAll(".birb-sticky-note");
existingNotes.forEach(note => note.remove());
// Render all sticky notes
const pageElement = getContext().getActivePage();
const context = getContext();
for (let stickyNote of stickyNotes) {
if (context.isPathApplicable(stickyNote.site)) {
renderStickyNote(stickyNote, onSave, () => onDelete(stickyNote));
renderStickyNote(stickyNote, pageElement, onSave, () => onDelete(stickyNote));
}
}
}
@@ -1270,9 +1280,10 @@
const id = Date.now().toString();
const site = getContext().getPath();
const stickyNote = new StickyNote(id, site, "");
const element = renderStickyNote(stickyNote, onSave, () => onDelete(stickyNote));
element.style.left = `${window.innerWidth / 2 - element.offsetWidth / 2}px`;
element.style.top = `${window.scrollY + window.innerHeight / 2 - element.offsetHeight / 2}px`;
const page = getContext().getActivePage();
const element = renderStickyNote(stickyNote, page, onSave, () => onDelete(stickyNote));
element.style.left = `${page.clientWidth / 2 - element.offsetWidth / 2}px`;
element.style.top = `${page.scrollTop + page.clientHeight / 2 - element.offsetHeight / 2}px`;
stickyNote.top = parseInt(element.style.top, 10);
stickyNote.left = parseInt(element.style.left, 10);
stickyNotes.push(stickyNote);
@@ -1946,7 +1957,7 @@
insertModal(`${birdBirb()} Mode`, message);
}),
new Separator(),
new MenuItem("2025.11.13.64", () => { alert("Thank you for using Pocket Bird! You are on version: 2025.11.13.64"); }, false),
new MenuItem("2025.11.13.80", () => { alert("Thank you for using Pocket Bird! You are on version: 2025.11.13.80"); }, false),
];
const styleElement = document.createElement("style");

View File

@@ -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.13.64",
"version": "2025.11.13.80",
"homepage_url": "https://idreesinc.com",
"icons": {
"48": "images/icons/transparent/48x48x1.png",

27
dist/obsidian/main.js vendored
View File

@@ -2,7 +2,7 @@
const { Plugin, Notice } = require('obsidian');
module.exports = class PocketBird extends Plugin {
onload() {
console.log("Loading Pocket Bird version 2025.11.13.64...");
console.log("Loading Pocket Bird version 2025.11.13.80...");
const OBSIDIAN_PLUGIN = this;
(function () {
'use strict';
@@ -906,6 +906,14 @@ module.exports = class PocketBird extends Plugin {
return window.location.href;
}
/**
* @returns {HTMLElement} The current active page element where sticky notes can be applied
*/
getActivePage() {
// Default to root element
return document.documentElement;
}
/**
* Checks if a path is applicable given the context
* @param {string} path Can be a site URL or another context-specific path
@@ -1179,11 +1187,12 @@ module.exports = class PocketBird extends Plugin {
/**
* @param {StickyNote} stickyNote
* @param {HTMLElement} page
* @param {() => void} onSave
* @param {() => void} onDelete
* @returns {HTMLElement}
*/
function renderStickyNote(stickyNote, onSave, onDelete) {
function renderStickyNote(stickyNote, page, onSave, onDelete) {
const noteElement = makeElement("birb-window");
noteElement.classList.add("birb-sticky-note");
@@ -1208,7 +1217,7 @@ module.exports = class PocketBird extends Plugin {
noteElement.style.top = `${stickyNote.top}px`;
noteElement.style.left = `${stickyNote.left}px`;
document.body.appendChild(noteElement);
page.appendChild(noteElement);
makeDraggable(header, true, (top, left) => {
stickyNote.top = top;
@@ -1259,10 +1268,11 @@ module.exports = class PocketBird extends Plugin {
const existingNotes = document.querySelectorAll(".birb-sticky-note");
existingNotes.forEach(note => note.remove());
// Render all sticky notes
const pageElement = getContext().getActivePage();
const context = getContext();
for (let stickyNote of stickyNotes) {
if (context.isPathApplicable(stickyNote.site)) {
renderStickyNote(stickyNote, onSave, () => onDelete(stickyNote));
renderStickyNote(stickyNote, pageElement, onSave, () => onDelete(stickyNote));
}
}
}
@@ -1276,9 +1286,10 @@ module.exports = class PocketBird extends Plugin {
const id = Date.now().toString();
const site = getContext().getPath();
const stickyNote = new StickyNote(id, site, "");
const element = renderStickyNote(stickyNote, onSave, () => onDelete(stickyNote));
element.style.left = `${window.innerWidth / 2 - element.offsetWidth / 2}px`;
element.style.top = `${window.scrollY + window.innerHeight / 2 - element.offsetHeight / 2}px`;
const page = getContext().getActivePage();
const element = renderStickyNote(stickyNote, page, onSave, () => onDelete(stickyNote));
element.style.left = `${page.clientWidth / 2 - element.offsetWidth / 2}px`;
element.style.top = `${page.scrollTop + page.clientHeight / 2 - element.offsetHeight / 2}px`;
stickyNote.top = parseInt(element.style.top, 10);
stickyNote.left = parseInt(element.style.left, 10);
stickyNotes.push(stickyNote);
@@ -1952,7 +1963,7 @@ module.exports = class PocketBird extends Plugin {
insertModal(`${birdBirb()} Mode`, message);
}),
new Separator(),
new MenuItem("2025.11.13.64", () => { alert("Thank you for using Pocket Bird! You are on version: 2025.11.13.64"); }, false),
new MenuItem("2025.11.13.80", () => { alert("Thank you for using Pocket Bird! You are on version: 2025.11.13.80"); }, false),
];
const styleElement = document.createElement("style");

View File

@@ -1,7 +1,7 @@
{
"id": "pocket-bird",
"name": "Pocket Bird",
"version": "2025.11.13.64",
"version": "2025.11.13.80",
"minAppVersion": "0.15.0",
"description": "It's a pet bird in your Obsidian, what more could you want?",
"author": "Idrees Hassan",

View File

@@ -1,7 +1,7 @@
// ==UserScript==
// @name Pocket Bird
// @namespace https://idreesinc.com
// @version 2025.11.13.64
// @version 2025.11.13.80
// @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
@@ -914,6 +914,14 @@
return window.location.href;
}
/**
* @returns {HTMLElement} The current active page element where sticky notes can be applied
*/
getActivePage() {
// Default to root element
return document.documentElement;
}
/**
* Checks if a path is applicable given the context
* @param {string} path Can be a site URL or another context-specific path
@@ -1187,11 +1195,12 @@
/**
* @param {StickyNote} stickyNote
* @param {HTMLElement} page
* @param {() => void} onSave
* @param {() => void} onDelete
* @returns {HTMLElement}
*/
function renderStickyNote(stickyNote, onSave, onDelete) {
function renderStickyNote(stickyNote, page, onSave, onDelete) {
const noteElement = makeElement("birb-window");
noteElement.classList.add("birb-sticky-note");
@@ -1216,7 +1225,7 @@
noteElement.style.top = `${stickyNote.top}px`;
noteElement.style.left = `${stickyNote.left}px`;
document.body.appendChild(noteElement);
page.appendChild(noteElement);
makeDraggable(header, true, (top, left) => {
stickyNote.top = top;
@@ -1267,10 +1276,11 @@
const existingNotes = document.querySelectorAll(".birb-sticky-note");
existingNotes.forEach(note => note.remove());
// Render all sticky notes
const pageElement = getContext().getActivePage();
const context = getContext();
for (let stickyNote of stickyNotes) {
if (context.isPathApplicable(stickyNote.site)) {
renderStickyNote(stickyNote, onSave, () => onDelete(stickyNote));
renderStickyNote(stickyNote, pageElement, onSave, () => onDelete(stickyNote));
}
}
}
@@ -1284,9 +1294,10 @@
const id = Date.now().toString();
const site = getContext().getPath();
const stickyNote = new StickyNote(id, site, "");
const element = renderStickyNote(stickyNote, onSave, () => onDelete(stickyNote));
element.style.left = `${window.innerWidth / 2 - element.offsetWidth / 2}px`;
element.style.top = `${window.scrollY + window.innerHeight / 2 - element.offsetHeight / 2}px`;
const page = getContext().getActivePage();
const element = renderStickyNote(stickyNote, page, onSave, () => onDelete(stickyNote));
element.style.left = `${page.clientWidth / 2 - element.offsetWidth / 2}px`;
element.style.top = `${page.scrollTop + page.clientHeight / 2 - element.offsetHeight / 2}px`;
stickyNote.top = parseInt(element.style.top, 10);
stickyNote.left = parseInt(element.style.left, 10);
stickyNotes.push(stickyNote);
@@ -1960,7 +1971,7 @@
insertModal(`${birdBirb()} Mode`, message);
}),
new Separator(),
new MenuItem("2025.11.13.64", () => { alert("Thank you for using Pocket Bird! You are on version: 2025.11.13.64"); }, false),
new MenuItem("2025.11.13.80", () => { alert("Thank you for using Pocket Bird! You are on version: 2025.11.13.80"); }, false),
];
const styleElement = document.createElement("style");