mirror of
https://github.com/NohamR/Pocket-Bird.git
synced 2026-05-25 12:17:22 +00:00
Add focusing on obsidian elements
This commit is contained in:
2
build.js
2
build.js
@@ -163,8 +163,10 @@ const obsidianPlugin = `
|
|||||||
const { Plugin, Notice } = require('obsidian');
|
const { Plugin, Notice } = require('obsidian');
|
||||||
module.exports = class PocketBird extends Plugin {
|
module.exports = class PocketBird extends Plugin {
|
||||||
onload() {
|
onload() {
|
||||||
|
console.log("Loading Pocket Bird version ${version}...");
|
||||||
const OBSIDIAN_PLUGIN = this;
|
const OBSIDIAN_PLUGIN = this;
|
||||||
${birbJs}
|
${birbJs}
|
||||||
|
console.log("Pocket Bird loaded!");
|
||||||
}
|
}
|
||||||
|
|
||||||
onunload() {
|
onunload() {
|
||||||
|
|||||||
32
dist/birb.js
vendored
32
dist/birb.js
vendored
@@ -881,6 +881,17 @@
|
|||||||
throw new Error("Method not implemented");
|
throw new Error("Method not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {string[]} A list of CSS selectors for focusable elements
|
||||||
|
*/
|
||||||
|
getFocusableElements() {
|
||||||
|
return ["img", "video", ".birb-sticky-note"];
|
||||||
|
}
|
||||||
|
|
||||||
|
getFocusElementTopMargin() {
|
||||||
|
return 80;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns {string} The current path of the active page in this context
|
* @returns {string} The current path of the active page in this context
|
||||||
*/
|
*/
|
||||||
@@ -1084,6 +1095,21 @@
|
|||||||
this.putSaveData({});
|
this.putSaveData({});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @override */
|
||||||
|
getFocusElementTopMargin() {
|
||||||
|
return 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @override */
|
||||||
|
getFocusableElements() {
|
||||||
|
const elements = [
|
||||||
|
".workspace-leaf",
|
||||||
|
".cm-callout",
|
||||||
|
".HyperMD-codeblock-begin"
|
||||||
|
];
|
||||||
|
return super.getFocusableElements().concat(elements);
|
||||||
|
}
|
||||||
|
|
||||||
/** @override */
|
/** @override */
|
||||||
areStickyNotesEnabled() {
|
areStickyNotesEnabled() {
|
||||||
return false;
|
return false;
|
||||||
@@ -1795,7 +1821,6 @@
|
|||||||
|
|
||||||
// Focus element constraints
|
// Focus element constraints
|
||||||
const MIN_FOCUS_ELEMENT_WIDTH = 100;
|
const MIN_FOCUS_ELEMENT_WIDTH = 100;
|
||||||
const MIN_FOCUS_ELEMENT_TOP = 80;
|
|
||||||
|
|
||||||
/** @type {Partial<Settings>} */
|
/** @type {Partial<Settings>} */
|
||||||
let userSettings = {};
|
let userSettings = {};
|
||||||
@@ -1924,7 +1949,7 @@
|
|||||||
insertModal(`${birdBirb()} Mode`, message);
|
insertModal(`${birdBirb()} Mode`, message);
|
||||||
}),
|
}),
|
||||||
new Separator(),
|
new Separator(),
|
||||||
new MenuItem("2025.11.13.16", () => { alert("Thank you for using Pocket Bird! You are on version: 2025.11.13.16"); }, false),
|
new MenuItem("2025.11.13.27", () => { alert("Thank you for using Pocket Bird! You are on version: 2025.11.13.27"); }, false),
|
||||||
];
|
];
|
||||||
|
|
||||||
const styleElement = document.createElement("style");
|
const styleElement = document.createElement("style");
|
||||||
@@ -2551,7 +2576,8 @@
|
|||||||
if (frozen) {
|
if (frozen) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const elements = document.querySelectorAll("img, video, .birb-sticky-note");
|
const MIN_FOCUS_ELEMENT_TOP = getContext().getFocusElementTopMargin();
|
||||||
|
const elements = document.querySelectorAll(getContext().getFocusableElements().join(", "));
|
||||||
const inWindow = Array.from(elements).filter((img) => {
|
const inWindow = Array.from(elements).filter((img) => {
|
||||||
const rect = img.getBoundingClientRect();
|
const rect = img.getBoundingClientRect();
|
||||||
return rect.left >= 0 && rect.top >= MIN_FOCUS_ELEMENT_TOP && rect.right <= window.innerWidth && rect.top <= getWindowHeight();
|
return rect.left >= 0 && rect.top >= MIN_FOCUS_ELEMENT_TOP && rect.right <= window.innerWidth && rect.top <= getWindowHeight();
|
||||||
|
|||||||
BIN
dist/extension.zip
vendored
BIN
dist/extension.zip
vendored
Binary file not shown.
32
dist/extension/birb.js
vendored
32
dist/extension/birb.js
vendored
@@ -881,6 +881,17 @@
|
|||||||
throw new Error("Method not implemented");
|
throw new Error("Method not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {string[]} A list of CSS selectors for focusable elements
|
||||||
|
*/
|
||||||
|
getFocusableElements() {
|
||||||
|
return ["img", "video", ".birb-sticky-note"];
|
||||||
|
}
|
||||||
|
|
||||||
|
getFocusElementTopMargin() {
|
||||||
|
return 80;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns {string} The current path of the active page in this context
|
* @returns {string} The current path of the active page in this context
|
||||||
*/
|
*/
|
||||||
@@ -1084,6 +1095,21 @@
|
|||||||
this.putSaveData({});
|
this.putSaveData({});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @override */
|
||||||
|
getFocusElementTopMargin() {
|
||||||
|
return 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @override */
|
||||||
|
getFocusableElements() {
|
||||||
|
const elements = [
|
||||||
|
".workspace-leaf",
|
||||||
|
".cm-callout",
|
||||||
|
".HyperMD-codeblock-begin"
|
||||||
|
];
|
||||||
|
return super.getFocusableElements().concat(elements);
|
||||||
|
}
|
||||||
|
|
||||||
/** @override */
|
/** @override */
|
||||||
areStickyNotesEnabled() {
|
areStickyNotesEnabled() {
|
||||||
return false;
|
return false;
|
||||||
@@ -1795,7 +1821,6 @@
|
|||||||
|
|
||||||
// Focus element constraints
|
// Focus element constraints
|
||||||
const MIN_FOCUS_ELEMENT_WIDTH = 100;
|
const MIN_FOCUS_ELEMENT_WIDTH = 100;
|
||||||
const MIN_FOCUS_ELEMENT_TOP = 80;
|
|
||||||
|
|
||||||
/** @type {Partial<Settings>} */
|
/** @type {Partial<Settings>} */
|
||||||
let userSettings = {};
|
let userSettings = {};
|
||||||
@@ -1924,7 +1949,7 @@
|
|||||||
insertModal(`${birdBirb()} Mode`, message);
|
insertModal(`${birdBirb()} Mode`, message);
|
||||||
}),
|
}),
|
||||||
new Separator(),
|
new Separator(),
|
||||||
new MenuItem("2025.11.13.16", () => { alert("Thank you for using Pocket Bird! You are on version: 2025.11.13.16"); }, false),
|
new MenuItem("2025.11.13.27", () => { alert("Thank you for using Pocket Bird! You are on version: 2025.11.13.27"); }, false),
|
||||||
];
|
];
|
||||||
|
|
||||||
const styleElement = document.createElement("style");
|
const styleElement = document.createElement("style");
|
||||||
@@ -2551,7 +2576,8 @@
|
|||||||
if (frozen) {
|
if (frozen) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const elements = document.querySelectorAll("img, video, .birb-sticky-note");
|
const MIN_FOCUS_ELEMENT_TOP = getContext().getFocusElementTopMargin();
|
||||||
|
const elements = document.querySelectorAll(getContext().getFocusableElements().join(", "));
|
||||||
const inWindow = Array.from(elements).filter((img) => {
|
const inWindow = Array.from(elements).filter((img) => {
|
||||||
const rect = img.getBoundingClientRect();
|
const rect = img.getBoundingClientRect();
|
||||||
return rect.left >= 0 && rect.top >= MIN_FOCUS_ELEMENT_TOP && rect.right <= window.innerWidth && rect.top <= getWindowHeight();
|
return rect.left >= 0 && rect.top >= MIN_FOCUS_ELEMENT_TOP && rect.right <= window.innerWidth && rect.top <= getWindowHeight();
|
||||||
|
|||||||
2
dist/extension/manifest.json
vendored
2
dist/extension/manifest.json
vendored
@@ -2,7 +2,7 @@
|
|||||||
"manifest_version": 3,
|
"manifest_version": 3,
|
||||||
"name": "Pocket Bird",
|
"name": "Pocket Bird",
|
||||||
"description": "It's a pet bird in your browser, what more could you want?",
|
"description": "It's a pet bird in your browser, what more could you want?",
|
||||||
"version": "2025.11.13.16",
|
"version": "2025.11.13.27",
|
||||||
"homepage_url": "https://idreesinc.com",
|
"homepage_url": "https://idreesinc.com",
|
||||||
"icons": {
|
"icons": {
|
||||||
"48": "images/icons/transparent/48x48x1.png",
|
"48": "images/icons/transparent/48x48x1.png",
|
||||||
|
|||||||
34
dist/obsidian/main.js
vendored
34
dist/obsidian/main.js
vendored
@@ -2,6 +2,7 @@
|
|||||||
const { Plugin, Notice } = require('obsidian');
|
const { Plugin, Notice } = require('obsidian');
|
||||||
module.exports = class PocketBird extends Plugin {
|
module.exports = class PocketBird extends Plugin {
|
||||||
onload() {
|
onload() {
|
||||||
|
console.log("Loading Pocket Bird version 2025.11.13.27...");
|
||||||
const OBSIDIAN_PLUGIN = this;
|
const OBSIDIAN_PLUGIN = this;
|
||||||
(function () {
|
(function () {
|
||||||
'use strict';
|
'use strict';
|
||||||
@@ -886,6 +887,17 @@ module.exports = class PocketBird extends Plugin {
|
|||||||
throw new Error("Method not implemented");
|
throw new Error("Method not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {string[]} A list of CSS selectors for focusable elements
|
||||||
|
*/
|
||||||
|
getFocusableElements() {
|
||||||
|
return ["img", "video", ".birb-sticky-note"];
|
||||||
|
}
|
||||||
|
|
||||||
|
getFocusElementTopMargin() {
|
||||||
|
return 80;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns {string} The current path of the active page in this context
|
* @returns {string} The current path of the active page in this context
|
||||||
*/
|
*/
|
||||||
@@ -1089,6 +1101,21 @@ module.exports = class PocketBird extends Plugin {
|
|||||||
this.putSaveData({});
|
this.putSaveData({});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @override */
|
||||||
|
getFocusElementTopMargin() {
|
||||||
|
return 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @override */
|
||||||
|
getFocusableElements() {
|
||||||
|
const elements = [
|
||||||
|
".workspace-leaf",
|
||||||
|
".cm-callout",
|
||||||
|
".HyperMD-codeblock-begin"
|
||||||
|
];
|
||||||
|
return super.getFocusableElements().concat(elements);
|
||||||
|
}
|
||||||
|
|
||||||
/** @override */
|
/** @override */
|
||||||
areStickyNotesEnabled() {
|
areStickyNotesEnabled() {
|
||||||
return false;
|
return false;
|
||||||
@@ -1800,7 +1827,6 @@ module.exports = class PocketBird extends Plugin {
|
|||||||
|
|
||||||
// Focus element constraints
|
// Focus element constraints
|
||||||
const MIN_FOCUS_ELEMENT_WIDTH = 100;
|
const MIN_FOCUS_ELEMENT_WIDTH = 100;
|
||||||
const MIN_FOCUS_ELEMENT_TOP = 80;
|
|
||||||
|
|
||||||
/** @type {Partial<Settings>} */
|
/** @type {Partial<Settings>} */
|
||||||
let userSettings = {};
|
let userSettings = {};
|
||||||
@@ -1929,7 +1955,7 @@ module.exports = class PocketBird extends Plugin {
|
|||||||
insertModal(`${birdBirb()} Mode`, message);
|
insertModal(`${birdBirb()} Mode`, message);
|
||||||
}),
|
}),
|
||||||
new Separator(),
|
new Separator(),
|
||||||
new MenuItem("2025.11.13.16", () => { alert("Thank you for using Pocket Bird! You are on version: 2025.11.13.16"); }, false),
|
new MenuItem("2025.11.13.27", () => { alert("Thank you for using Pocket Bird! You are on version: 2025.11.13.27"); }, false),
|
||||||
];
|
];
|
||||||
|
|
||||||
const styleElement = document.createElement("style");
|
const styleElement = document.createElement("style");
|
||||||
@@ -2556,7 +2582,8 @@ module.exports = class PocketBird extends Plugin {
|
|||||||
if (frozen) {
|
if (frozen) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const elements = document.querySelectorAll("img, video, .birb-sticky-note");
|
const MIN_FOCUS_ELEMENT_TOP = getContext().getFocusElementTopMargin();
|
||||||
|
const elements = document.querySelectorAll(getContext().getFocusableElements().join(", "));
|
||||||
const inWindow = Array.from(elements).filter((img) => {
|
const inWindow = Array.from(elements).filter((img) => {
|
||||||
const rect = img.getBoundingClientRect();
|
const rect = img.getBoundingClientRect();
|
||||||
return rect.left >= 0 && rect.top >= MIN_FOCUS_ELEMENT_TOP && rect.right <= window.innerWidth && rect.top <= getWindowHeight();
|
return rect.left >= 0 && rect.top >= MIN_FOCUS_ELEMENT_TOP && rect.right <= window.innerWidth && rect.top <= getWindowHeight();
|
||||||
@@ -2720,6 +2747,7 @@ module.exports = class PocketBird extends Plugin {
|
|||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
console.log("Pocket Bird loaded!");
|
||||||
}
|
}
|
||||||
|
|
||||||
onunload() {
|
onunload() {
|
||||||
|
|||||||
2
dist/obsidian/manifest.json
vendored
2
dist/obsidian/manifest.json
vendored
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"id": "pocket-bird",
|
"id": "pocket-bird",
|
||||||
"name": "Pocket Bird",
|
"name": "Pocket Bird",
|
||||||
"version": "2025.11.13.16",
|
"version": "2025.11.13.27",
|
||||||
"minAppVersion": "0.15.0",
|
"minAppVersion": "0.15.0",
|
||||||
"description": "It's a pet bird in your Obsidian, what more could you want?",
|
"description": "It's a pet bird in your Obsidian, what more could you want?",
|
||||||
"author": "Idrees Hassan",
|
"author": "Idrees Hassan",
|
||||||
|
|||||||
34
dist/userscript/birb.user.js
vendored
34
dist/userscript/birb.user.js
vendored
@@ -1,7 +1,7 @@
|
|||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name Pocket Bird
|
// @name Pocket Bird
|
||||||
// @namespace https://idreesinc.com
|
// @namespace https://idreesinc.com
|
||||||
// @version 2025.11.13.16
|
// @version 2025.11.13.27
|
||||||
// @description It's a bird that hops around your web browser, the future is here
|
// @description It's a bird that hops around your web browser, the future is here
|
||||||
// @author Idrees
|
// @author Idrees
|
||||||
// @downloadURL https://github.com/IdreesInc/Pocket-Bird/raw/refs/heads/main/dist/userscript/birb.user.js
|
// @downloadURL https://github.com/IdreesInc/Pocket-Bird/raw/refs/heads/main/dist/userscript/birb.user.js
|
||||||
@@ -895,6 +895,17 @@
|
|||||||
throw new Error("Method not implemented");
|
throw new Error("Method not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {string[]} A list of CSS selectors for focusable elements
|
||||||
|
*/
|
||||||
|
getFocusableElements() {
|
||||||
|
return ["img", "video", ".birb-sticky-note"];
|
||||||
|
}
|
||||||
|
|
||||||
|
getFocusElementTopMargin() {
|
||||||
|
return 80;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns {string} The current path of the active page in this context
|
* @returns {string} The current path of the active page in this context
|
||||||
*/
|
*/
|
||||||
@@ -1098,6 +1109,21 @@
|
|||||||
this.putSaveData({});
|
this.putSaveData({});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @override */
|
||||||
|
getFocusElementTopMargin() {
|
||||||
|
return 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @override */
|
||||||
|
getFocusableElements() {
|
||||||
|
const elements = [
|
||||||
|
".workspace-leaf",
|
||||||
|
".cm-callout",
|
||||||
|
".HyperMD-codeblock-begin"
|
||||||
|
];
|
||||||
|
return super.getFocusableElements().concat(elements);
|
||||||
|
}
|
||||||
|
|
||||||
/** @override */
|
/** @override */
|
||||||
areStickyNotesEnabled() {
|
areStickyNotesEnabled() {
|
||||||
return false;
|
return false;
|
||||||
@@ -1809,7 +1835,6 @@
|
|||||||
|
|
||||||
// Focus element constraints
|
// Focus element constraints
|
||||||
const MIN_FOCUS_ELEMENT_WIDTH = 100;
|
const MIN_FOCUS_ELEMENT_WIDTH = 100;
|
||||||
const MIN_FOCUS_ELEMENT_TOP = 80;
|
|
||||||
|
|
||||||
/** @type {Partial<Settings>} */
|
/** @type {Partial<Settings>} */
|
||||||
let userSettings = {};
|
let userSettings = {};
|
||||||
@@ -1938,7 +1963,7 @@
|
|||||||
insertModal(`${birdBirb()} Mode`, message);
|
insertModal(`${birdBirb()} Mode`, message);
|
||||||
}),
|
}),
|
||||||
new Separator(),
|
new Separator(),
|
||||||
new MenuItem("2025.11.13.16", () => { alert("Thank you for using Pocket Bird! You are on version: 2025.11.13.16"); }, false),
|
new MenuItem("2025.11.13.27", () => { alert("Thank you for using Pocket Bird! You are on version: 2025.11.13.27"); }, false),
|
||||||
];
|
];
|
||||||
|
|
||||||
const styleElement = document.createElement("style");
|
const styleElement = document.createElement("style");
|
||||||
@@ -2565,7 +2590,8 @@
|
|||||||
if (frozen) {
|
if (frozen) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const elements = document.querySelectorAll("img, video, .birb-sticky-note");
|
const MIN_FOCUS_ELEMENT_TOP = getContext().getFocusElementTopMargin();
|
||||||
|
const elements = document.querySelectorAll(getContext().getFocusableElements().join(", "));
|
||||||
const inWindow = Array.from(elements).filter((img) => {
|
const inWindow = Array.from(elements).filter((img) => {
|
||||||
const rect = img.getBoundingClientRect();
|
const rect = img.getBoundingClientRect();
|
||||||
return rect.left >= 0 && rect.top >= MIN_FOCUS_ELEMENT_TOP && rect.right <= window.innerWidth && rect.top <= getWindowHeight();
|
return rect.left >= 0 && rect.top >= MIN_FOCUS_ELEMENT_TOP && rect.right <= window.innerWidth && rect.top <= getWindowHeight();
|
||||||
|
|||||||
@@ -104,7 +104,6 @@ const PET_FEATHER_BOOST = 2;
|
|||||||
|
|
||||||
// Focus element constraints
|
// Focus element constraints
|
||||||
const MIN_FOCUS_ELEMENT_WIDTH = 100;
|
const MIN_FOCUS_ELEMENT_WIDTH = 100;
|
||||||
const MIN_FOCUS_ELEMENT_TOP = 80;
|
|
||||||
|
|
||||||
/** @type {Partial<Settings>} */
|
/** @type {Partial<Settings>} */
|
||||||
let userSettings = {};
|
let userSettings = {};
|
||||||
@@ -864,7 +863,8 @@ Promise.all([
|
|||||||
if (frozen) {
|
if (frozen) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const elements = document.querySelectorAll("img, video, .birb-sticky-note");
|
const MIN_FOCUS_ELEMENT_TOP = getContext().getFocusElementTopMargin();
|
||||||
|
const elements = document.querySelectorAll(getContext().getFocusableElements().join(", "));
|
||||||
const inWindow = Array.from(elements).filter((img) => {
|
const inWindow = Array.from(elements).filter((img) => {
|
||||||
const rect = img.getBoundingClientRect();
|
const rect = img.getBoundingClientRect();
|
||||||
return rect.left >= 0 && rect.top >= MIN_FOCUS_ELEMENT_TOP && rect.right <= window.innerWidth && rect.top <= getWindowHeight();
|
return rect.left >= 0 && rect.top >= MIN_FOCUS_ELEMENT_TOP && rect.right <= window.innerWidth && rect.top <= getWindowHeight();
|
||||||
|
|||||||
@@ -42,6 +42,17 @@ export class Context {
|
|||||||
throw new Error("Method not implemented");
|
throw new Error("Method not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {string[]} A list of CSS selectors for focusable elements
|
||||||
|
*/
|
||||||
|
getFocusableElements() {
|
||||||
|
return ["img", "video", ".birb-sticky-note"];
|
||||||
|
}
|
||||||
|
|
||||||
|
getFocusElementTopMargin() {
|
||||||
|
return 80;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns {string} The current path of the active page in this context
|
* @returns {string} The current path of the active page in this context
|
||||||
*/
|
*/
|
||||||
@@ -245,6 +256,21 @@ class ObsidianContext extends Context {
|
|||||||
this.putSaveData({});
|
this.putSaveData({});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @override */
|
||||||
|
getFocusElementTopMargin() {
|
||||||
|
return 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @override */
|
||||||
|
getFocusableElements() {
|
||||||
|
const elements = [
|
||||||
|
".workspace-leaf",
|
||||||
|
".cm-callout",
|
||||||
|
".HyperMD-codeblock-begin"
|
||||||
|
];
|
||||||
|
return super.getFocusableElements().concat(elements);
|
||||||
|
}
|
||||||
|
|
||||||
/** @override */
|
/** @override */
|
||||||
areStickyNotesEnabled() {
|
areStickyNotesEnabled() {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user