mirror of
https://github.com/NohamR/Pocket-Bird.git
synced 2026-05-25 12:17:22 +00:00
Fix type hints
This commit is contained in:
19
birb.js
19
birb.js
@@ -48,6 +48,7 @@ const DEFAULT_SETTINGS = {
|
|||||||
* @typedef {typeof DEFAULT_SETTINGS} Settings
|
* @typedef {typeof DEFAULT_SETTINGS} Settings
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/** @type {Partial<Settings>} */
|
||||||
let userSettings = {};
|
let userSettings = {};
|
||||||
|
|
||||||
const STYLESHEET = `___STYLESHEET___`;
|
const STYLESHEET = `___STYLESHEET___`;
|
||||||
@@ -65,6 +66,7 @@ class Layer {
|
|||||||
|
|
||||||
class Frame {
|
class Frame {
|
||||||
|
|
||||||
|
/** @type {{ [tag: string]: string[][] }} */
|
||||||
#pixelsByTag = {};
|
#pixelsByTag = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -191,6 +193,7 @@ const HEART_BORDER = "heart-border";
|
|||||||
const HEART_SHINE = "heart-shine";
|
const HEART_SHINE = "heart-shine";
|
||||||
const FEATHER_SPINE = "feather-spine";
|
const FEATHER_SPINE = "feather-spine";
|
||||||
|
|
||||||
|
/** @type {Record<string, string>} */
|
||||||
const SPRITE_SHEET_COLOR_MAP = {
|
const SPRITE_SHEET_COLOR_MAP = {
|
||||||
"transparent": TRANSPARENT,
|
"transparent": TRANSPARENT,
|
||||||
"#ffffff": BORDER,
|
"#ffffff": BORDER,
|
||||||
@@ -234,11 +237,13 @@ class BirdType {
|
|||||||
[HOOD]: colors.face,
|
[HOOD]: colors.face,
|
||||||
[NOSE]: colors.face,
|
[NOSE]: colors.face,
|
||||||
};
|
};
|
||||||
|
/** @type {Record<string, string>} */
|
||||||
this.colors = { ...defaultColors, ...colors, [THEME_HIGHLIGHT]: colors[THEME_HIGHLIGHT] ?? colors.hood ?? colors.face };
|
this.colors = { ...defaultColors, ...colors, [THEME_HIGHLIGHT]: colors[THEME_HIGHLIGHT] ?? colors.hood ?? colors.face };
|
||||||
this.tags = tags;
|
this.tags = tags;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @type {Record<string, BirdType>} */
|
||||||
const species = {
|
const species = {
|
||||||
bluebird: new BirdType("Eastern Bluebird",
|
bluebird: new BirdType("Eastern Bluebird",
|
||||||
"Native to North American and very social, though can be timid around people.", {
|
"Native to North American and very social, though can be timid around people.", {
|
||||||
@@ -681,6 +686,7 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI
|
|||||||
/** @type {HTMLElement|null} */
|
/** @type {HTMLElement|null} */
|
||||||
let focusedElement = null;
|
let focusedElement = null;
|
||||||
let lastActionTimestamp = Date.now();
|
let lastActionTimestamp = Date.now();
|
||||||
|
/** @type {number[]} */
|
||||||
let petStack = [];
|
let petStack = [];
|
||||||
let currentSpecies = DEFAULT_BIRD;
|
let currentSpecies = DEFAULT_BIRD;
|
||||||
let unlockedSpecies = [DEFAULT_BIRD];
|
let unlockedSpecies = [DEFAULT_BIRD];
|
||||||
@@ -702,6 +708,7 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI
|
|||||||
}
|
}
|
||||||
|
|
||||||
function load() {
|
function load() {
|
||||||
|
/** @type {Record<string, any>} */
|
||||||
let saveData = {};
|
let saveData = {};
|
||||||
if (isUserScript()) {
|
if (isUserScript()) {
|
||||||
log("Loading save data from UserScript storage");
|
log("Loading save data from UserScript storage");
|
||||||
@@ -733,6 +740,7 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI
|
|||||||
}
|
}
|
||||||
|
|
||||||
function save() {
|
function save() {
|
||||||
|
/** @type {Record<string, any>} */
|
||||||
let saveData = {
|
let saveData = {
|
||||||
unlockedSpecies: unlockedSpecies,
|
unlockedSpecies: unlockedSpecies,
|
||||||
currentSpecies: currentSpecies,
|
currentSpecies: currentSpecies,
|
||||||
@@ -840,11 +848,14 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI
|
|||||||
|
|
||||||
const textarea = noteElement.querySelector(".birb-sticky-note-input");
|
const textarea = noteElement.querySelector(".birb-sticky-note-input");
|
||||||
if (textarea && textarea instanceof HTMLTextAreaElement) {
|
if (textarea && textarea instanceof HTMLTextAreaElement) {
|
||||||
|
/** @type {NodeJS.Timeout | undefined} */
|
||||||
let saveTimeout;
|
let saveTimeout;
|
||||||
// Save after debounce
|
// Save after debounce
|
||||||
textarea.addEventListener("input", () => {
|
textarea.addEventListener("input", () => {
|
||||||
stickyNote.content = textarea.value;
|
stickyNote.content = textarea.value;
|
||||||
clearTimeout(saveTimeout);
|
if (saveTimeout) {
|
||||||
|
clearTimeout(saveTimeout);
|
||||||
|
}
|
||||||
saveTimeout = setTimeout(() => {
|
saveTimeout = setTimeout(() => {
|
||||||
save();
|
save();
|
||||||
}, 250);
|
}, 250);
|
||||||
@@ -888,15 +899,13 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI
|
|||||||
/** @type {Record<string, string>} */
|
/** @type {Record<string, string>} */
|
||||||
const stickyNoteParams = stickyNoteUrl.split("?")[1]?.split("&").reduce((params, param) => {
|
const stickyNoteParams = stickyNoteUrl.split("?")[1]?.split("&").reduce((params, param) => {
|
||||||
const [key, value] = param.split("=");
|
const [key, value] = param.split("=");
|
||||||
params[key] = value;
|
return {...params, [key]: value};
|
||||||
return params;
|
|
||||||
}, {});
|
}, {});
|
||||||
|
|
||||||
/** @type {Record<string, string>} */
|
/** @type {Record<string, string>} */
|
||||||
const currentParams = currentUrl.split("?")[1]?.split("&").reduce((params, param) => {
|
const currentParams = currentUrl.split("?")[1]?.split("&").reduce((params, param) => {
|
||||||
const [key, value] = param.split("=");
|
const [key, value] = param.split("=");
|
||||||
params[key] = value;
|
return {...params, [key]: value};
|
||||||
return params;
|
|
||||||
}, {});
|
}, {});
|
||||||
|
|
||||||
debug("Comparing params: ", stickyNoteParams, currentParams);
|
debug("Comparing params: ", stickyNoteParams, currentParams);
|
||||||
|
|||||||
19
dist/birb.js
vendored
19
dist/birb.js
vendored
@@ -48,6 +48,7 @@ const DEFAULT_SETTINGS = {
|
|||||||
* @typedef {typeof DEFAULT_SETTINGS} Settings
|
* @typedef {typeof DEFAULT_SETTINGS} Settings
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/** @type {Partial<Settings>} */
|
||||||
let userSettings = {};
|
let userSettings = {};
|
||||||
|
|
||||||
const STYLESHEET = `:root {
|
const STYLESHEET = `:root {
|
||||||
@@ -397,6 +398,7 @@ class Layer {
|
|||||||
|
|
||||||
class Frame {
|
class Frame {
|
||||||
|
|
||||||
|
/** @type {{ [tag: string]: string[][] }} */
|
||||||
#pixelsByTag = {};
|
#pixelsByTag = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -523,6 +525,7 @@ const HEART_BORDER = "heart-border";
|
|||||||
const HEART_SHINE = "heart-shine";
|
const HEART_SHINE = "heart-shine";
|
||||||
const FEATHER_SPINE = "feather-spine";
|
const FEATHER_SPINE = "feather-spine";
|
||||||
|
|
||||||
|
/** @type {Record<string, string>} */
|
||||||
const SPRITE_SHEET_COLOR_MAP = {
|
const SPRITE_SHEET_COLOR_MAP = {
|
||||||
"transparent": TRANSPARENT,
|
"transparent": TRANSPARENT,
|
||||||
"#ffffff": BORDER,
|
"#ffffff": BORDER,
|
||||||
@@ -566,11 +569,13 @@ class BirdType {
|
|||||||
[HOOD]: colors.face,
|
[HOOD]: colors.face,
|
||||||
[NOSE]: colors.face,
|
[NOSE]: colors.face,
|
||||||
};
|
};
|
||||||
|
/** @type {Record<string, string>} */
|
||||||
this.colors = { ...defaultColors, ...colors, [THEME_HIGHLIGHT]: colors[THEME_HIGHLIGHT] ?? colors.hood ?? colors.face };
|
this.colors = { ...defaultColors, ...colors, [THEME_HIGHLIGHT]: colors[THEME_HIGHLIGHT] ?? colors.hood ?? colors.face };
|
||||||
this.tags = tags;
|
this.tags = tags;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @type {Record<string, BirdType>} */
|
||||||
const species = {
|
const species = {
|
||||||
bluebird: new BirdType("Eastern Bluebird",
|
bluebird: new BirdType("Eastern Bluebird",
|
||||||
"Native to North American and very social, though can be timid around people.", {
|
"Native to North American and very social, though can be timid around people.", {
|
||||||
@@ -1013,6 +1018,7 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI
|
|||||||
/** @type {HTMLElement|null} */
|
/** @type {HTMLElement|null} */
|
||||||
let focusedElement = null;
|
let focusedElement = null;
|
||||||
let lastActionTimestamp = Date.now();
|
let lastActionTimestamp = Date.now();
|
||||||
|
/** @type {number[]} */
|
||||||
let petStack = [];
|
let petStack = [];
|
||||||
let currentSpecies = DEFAULT_BIRD;
|
let currentSpecies = DEFAULT_BIRD;
|
||||||
let unlockedSpecies = [DEFAULT_BIRD];
|
let unlockedSpecies = [DEFAULT_BIRD];
|
||||||
@@ -1034,6 +1040,7 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI
|
|||||||
}
|
}
|
||||||
|
|
||||||
function load() {
|
function load() {
|
||||||
|
/** @type {Record<string, any>} */
|
||||||
let saveData = {};
|
let saveData = {};
|
||||||
if (isUserScript()) {
|
if (isUserScript()) {
|
||||||
log("Loading save data from UserScript storage");
|
log("Loading save data from UserScript storage");
|
||||||
@@ -1065,6 +1072,7 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI
|
|||||||
}
|
}
|
||||||
|
|
||||||
function save() {
|
function save() {
|
||||||
|
/** @type {Record<string, any>} */
|
||||||
let saveData = {
|
let saveData = {
|
||||||
unlockedSpecies: unlockedSpecies,
|
unlockedSpecies: unlockedSpecies,
|
||||||
currentSpecies: currentSpecies,
|
currentSpecies: currentSpecies,
|
||||||
@@ -1172,11 +1180,14 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI
|
|||||||
|
|
||||||
const textarea = noteElement.querySelector(".birb-sticky-note-input");
|
const textarea = noteElement.querySelector(".birb-sticky-note-input");
|
||||||
if (textarea && textarea instanceof HTMLTextAreaElement) {
|
if (textarea && textarea instanceof HTMLTextAreaElement) {
|
||||||
|
/** @type {NodeJS.Timeout | undefined} */
|
||||||
let saveTimeout;
|
let saveTimeout;
|
||||||
// Save after debounce
|
// Save after debounce
|
||||||
textarea.addEventListener("input", () => {
|
textarea.addEventListener("input", () => {
|
||||||
stickyNote.content = textarea.value;
|
stickyNote.content = textarea.value;
|
||||||
clearTimeout(saveTimeout);
|
if (saveTimeout) {
|
||||||
|
clearTimeout(saveTimeout);
|
||||||
|
}
|
||||||
saveTimeout = setTimeout(() => {
|
saveTimeout = setTimeout(() => {
|
||||||
save();
|
save();
|
||||||
}, 250);
|
}, 250);
|
||||||
@@ -1220,15 +1231,13 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI
|
|||||||
/** @type {Record<string, string>} */
|
/** @type {Record<string, string>} */
|
||||||
const stickyNoteParams = stickyNoteUrl.split("?")[1]?.split("&").reduce((params, param) => {
|
const stickyNoteParams = stickyNoteUrl.split("?")[1]?.split("&").reduce((params, param) => {
|
||||||
const [key, value] = param.split("=");
|
const [key, value] = param.split("=");
|
||||||
params[key] = value;
|
return {...params, [key]: value};
|
||||||
return params;
|
|
||||||
}, {});
|
}, {});
|
||||||
|
|
||||||
/** @type {Record<string, string>} */
|
/** @type {Record<string, string>} */
|
||||||
const currentParams = currentUrl.split("?")[1]?.split("&").reduce((params, param) => {
|
const currentParams = currentUrl.split("?")[1]?.split("&").reduce((params, param) => {
|
||||||
const [key, value] = param.split("=");
|
const [key, value] = param.split("=");
|
||||||
params[key] = value;
|
return {...params, [key]: value};
|
||||||
return params;
|
|
||||||
}, {});
|
}, {});
|
||||||
|
|
||||||
debug("Comparing params: ", stickyNoteParams, currentParams);
|
debug("Comparing params: ", stickyNoteParams, currentParams);
|
||||||
|
|||||||
19
dist/birb.user.js
vendored
19
dist/birb.user.js
vendored
@@ -62,6 +62,7 @@ const DEFAULT_SETTINGS = {
|
|||||||
* @typedef {typeof DEFAULT_SETTINGS} Settings
|
* @typedef {typeof DEFAULT_SETTINGS} Settings
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/** @type {Partial<Settings>} */
|
||||||
let userSettings = {};
|
let userSettings = {};
|
||||||
|
|
||||||
const STYLESHEET = `:root {
|
const STYLESHEET = `:root {
|
||||||
@@ -411,6 +412,7 @@ class Layer {
|
|||||||
|
|
||||||
class Frame {
|
class Frame {
|
||||||
|
|
||||||
|
/** @type {{ [tag: string]: string[][] }} */
|
||||||
#pixelsByTag = {};
|
#pixelsByTag = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -537,6 +539,7 @@ const HEART_BORDER = "heart-border";
|
|||||||
const HEART_SHINE = "heart-shine";
|
const HEART_SHINE = "heart-shine";
|
||||||
const FEATHER_SPINE = "feather-spine";
|
const FEATHER_SPINE = "feather-spine";
|
||||||
|
|
||||||
|
/** @type {Record<string, string>} */
|
||||||
const SPRITE_SHEET_COLOR_MAP = {
|
const SPRITE_SHEET_COLOR_MAP = {
|
||||||
"transparent": TRANSPARENT,
|
"transparent": TRANSPARENT,
|
||||||
"#ffffff": BORDER,
|
"#ffffff": BORDER,
|
||||||
@@ -580,11 +583,13 @@ class BirdType {
|
|||||||
[HOOD]: colors.face,
|
[HOOD]: colors.face,
|
||||||
[NOSE]: colors.face,
|
[NOSE]: colors.face,
|
||||||
};
|
};
|
||||||
|
/** @type {Record<string, string>} */
|
||||||
this.colors = { ...defaultColors, ...colors, [THEME_HIGHLIGHT]: colors[THEME_HIGHLIGHT] ?? colors.hood ?? colors.face };
|
this.colors = { ...defaultColors, ...colors, [THEME_HIGHLIGHT]: colors[THEME_HIGHLIGHT] ?? colors.hood ?? colors.face };
|
||||||
this.tags = tags;
|
this.tags = tags;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @type {Record<string, BirdType>} */
|
||||||
const species = {
|
const species = {
|
||||||
bluebird: new BirdType("Eastern Bluebird",
|
bluebird: new BirdType("Eastern Bluebird",
|
||||||
"Native to North American and very social, though can be timid around people.", {
|
"Native to North American and very social, though can be timid around people.", {
|
||||||
@@ -1027,6 +1032,7 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI
|
|||||||
/** @type {HTMLElement|null} */
|
/** @type {HTMLElement|null} */
|
||||||
let focusedElement = null;
|
let focusedElement = null;
|
||||||
let lastActionTimestamp = Date.now();
|
let lastActionTimestamp = Date.now();
|
||||||
|
/** @type {number[]} */
|
||||||
let petStack = [];
|
let petStack = [];
|
||||||
let currentSpecies = DEFAULT_BIRD;
|
let currentSpecies = DEFAULT_BIRD;
|
||||||
let unlockedSpecies = [DEFAULT_BIRD];
|
let unlockedSpecies = [DEFAULT_BIRD];
|
||||||
@@ -1048,6 +1054,7 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI
|
|||||||
}
|
}
|
||||||
|
|
||||||
function load() {
|
function load() {
|
||||||
|
/** @type {Record<string, any>} */
|
||||||
let saveData = {};
|
let saveData = {};
|
||||||
if (isUserScript()) {
|
if (isUserScript()) {
|
||||||
log("Loading save data from UserScript storage");
|
log("Loading save data from UserScript storage");
|
||||||
@@ -1079,6 +1086,7 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI
|
|||||||
}
|
}
|
||||||
|
|
||||||
function save() {
|
function save() {
|
||||||
|
/** @type {Record<string, any>} */
|
||||||
let saveData = {
|
let saveData = {
|
||||||
unlockedSpecies: unlockedSpecies,
|
unlockedSpecies: unlockedSpecies,
|
||||||
currentSpecies: currentSpecies,
|
currentSpecies: currentSpecies,
|
||||||
@@ -1186,11 +1194,14 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI
|
|||||||
|
|
||||||
const textarea = noteElement.querySelector(".birb-sticky-note-input");
|
const textarea = noteElement.querySelector(".birb-sticky-note-input");
|
||||||
if (textarea && textarea instanceof HTMLTextAreaElement) {
|
if (textarea && textarea instanceof HTMLTextAreaElement) {
|
||||||
|
/** @type {NodeJS.Timeout | undefined} */
|
||||||
let saveTimeout;
|
let saveTimeout;
|
||||||
// Save after debounce
|
// Save after debounce
|
||||||
textarea.addEventListener("input", () => {
|
textarea.addEventListener("input", () => {
|
||||||
stickyNote.content = textarea.value;
|
stickyNote.content = textarea.value;
|
||||||
clearTimeout(saveTimeout);
|
if (saveTimeout) {
|
||||||
|
clearTimeout(saveTimeout);
|
||||||
|
}
|
||||||
saveTimeout = setTimeout(() => {
|
saveTimeout = setTimeout(() => {
|
||||||
save();
|
save();
|
||||||
}, 250);
|
}, 250);
|
||||||
@@ -1234,15 +1245,13 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI
|
|||||||
/** @type {Record<string, string>} */
|
/** @type {Record<string, string>} */
|
||||||
const stickyNoteParams = stickyNoteUrl.split("?")[1]?.split("&").reduce((params, param) => {
|
const stickyNoteParams = stickyNoteUrl.split("?")[1]?.split("&").reduce((params, param) => {
|
||||||
const [key, value] = param.split("=");
|
const [key, value] = param.split("=");
|
||||||
params[key] = value;
|
return {...params, [key]: value};
|
||||||
return params;
|
|
||||||
}, {});
|
}, {});
|
||||||
|
|
||||||
/** @type {Record<string, string>} */
|
/** @type {Record<string, string>} */
|
||||||
const currentParams = currentUrl.split("?")[1]?.split("&").reduce((params, param) => {
|
const currentParams = currentUrl.split("?")[1]?.split("&").reduce((params, param) => {
|
||||||
const [key, value] = param.split("=");
|
const [key, value] = param.split("=");
|
||||||
params[key] = value;
|
return {...params, [key]: value};
|
||||||
return params;
|
|
||||||
}, {});
|
}, {});
|
||||||
|
|
||||||
debug("Comparing params: ", stickyNoteParams, currentParams);
|
debug("Comparing params: ", stickyNoteParams, currentParams);
|
||||||
|
|||||||
Reference in New Issue
Block a user