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

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");