mirror of
https://github.com/NohamR/Pocket-Bird.git
synced 2026-05-24 19:59:36 +00:00
Allow for set contexts
This commit is contained in:
18
build.js
18
build.js
@@ -16,10 +16,12 @@ const BROWSER_MANIFEST = "./platform-specific/extension/manifest.json";
|
|||||||
const OBSIDIAN_MANIFEST = "./platform-specific/obsidian/manifest.json";
|
const OBSIDIAN_MANIFEST = "./platform-specific/obsidian/manifest.json";
|
||||||
const USERSCRIPT_HEADER = "./platform-specific/userscript/header.txt";
|
const USERSCRIPT_HEADER = "./platform-specific/userscript/header.txt";
|
||||||
const OBSIDIAN_WRAPPER = "./platform-specific/obsidian/wrapper.js";
|
const OBSIDIAN_WRAPPER = "./platform-specific/obsidian/wrapper.js";
|
||||||
|
const VENCORD_WRAPPER = "./platform-specific/vencord/wrapper.js";
|
||||||
|
|
||||||
const USERSCRIPT_DIR = DIST_DIR + "/userscript";
|
const USERSCRIPT_DIR = DIST_DIR + "/userscript";
|
||||||
const EXTENSION_DIR = DIST_DIR + "/extension";
|
const EXTENSION_DIR = DIST_DIR + "/extension";
|
||||||
const OBSIDIAN_DIR = DIST_DIR + "/obsidian";
|
const OBSIDIAN_DIR = DIST_DIR + "/obsidian";
|
||||||
|
const VENCORD_DIR = DIST_DIR + "/vencord";
|
||||||
|
|
||||||
const STYLESHEET_PATH = SRC_DIR + "/stylesheet.css";
|
const STYLESHEET_PATH = SRC_DIR + "/stylesheet.css";
|
||||||
const APPLICATION_ENTRY = SRC_DIR + "/application.js";
|
const APPLICATION_ENTRY = SRC_DIR + "/application.js";
|
||||||
@@ -32,6 +34,7 @@ const VERSION_KEY = "__VERSION__";
|
|||||||
const STYLESHEET_KEY = "___STYLESHEET___";
|
const STYLESHEET_KEY = "___STYLESHEET___";
|
||||||
const MONOCRAFT_SRC_KEY = "__MONOCRAFT_SRC__";
|
const MONOCRAFT_SRC_KEY = "__MONOCRAFT_SRC__";
|
||||||
const CODE_KEY = "__CODE__";
|
const CODE_KEY = "__CODE__";
|
||||||
|
const CONTEXT_KEY = "__CONTEXT__";
|
||||||
|
|
||||||
const spriteSheets = [
|
const spriteSheets = [
|
||||||
{
|
{
|
||||||
@@ -183,4 +186,19 @@ let obsidianManifest = readFileSync(OBSIDIAN_MANIFEST, 'utf8');
|
|||||||
obsidianManifest = obsidianManifest.replace(/"version":\s*".*"/, `"version": "${version}"`);
|
obsidianManifest = obsidianManifest.replace(/"version":\s*".*"/, `"version": "${version}"`);
|
||||||
writeFileSync(OBSIDIAN_DIR + '/manifest.json', obsidianManifest);
|
writeFileSync(OBSIDIAN_DIR + '/manifest.json', obsidianManifest);
|
||||||
|
|
||||||
|
// =============================================
|
||||||
|
// Build Vencord plugin
|
||||||
|
// =============================================
|
||||||
|
|
||||||
|
mkdirSync(VENCORD_DIR, { recursive: true });
|
||||||
|
|
||||||
|
// Wrap birb.js with plugin boilerplate
|
||||||
|
let vencordPlugin = readFileSync(VENCORD_WRAPPER, 'utf8').replace(CODE_KEY, birbJs);
|
||||||
|
|
||||||
|
// Set context to "local"
|
||||||
|
vencordPlugin = vencordPlugin.replace(CONTEXT_KEY, "local");
|
||||||
|
|
||||||
|
// Create exported birb function
|
||||||
|
writeFileSync(VENCORD_DIR + '/birb.export.js', vencordPlugin);
|
||||||
|
|
||||||
console.log(`Build complete: ${version}`);
|
console.log(`Build complete: ${version}`);
|
||||||
22
dist/birb.js
vendored
22
dist/birb.js
vendored
@@ -847,6 +847,7 @@
|
|||||||
|
|
||||||
const SAVE_KEY = "birbSaveData";
|
const SAVE_KEY = "birbSaveData";
|
||||||
const ROOT_PATH = "";
|
const ROOT_PATH = "";
|
||||||
|
const SET_CONTEXT = "__CONTEXT__";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {import('./application.js').BirbSaveData} BirbSaveData
|
* @typedef {import('./application.js').BirbSaveData} BirbSaveData
|
||||||
@@ -1033,7 +1034,7 @@
|
|||||||
*/
|
*/
|
||||||
isContextActive() {
|
isContextActive() {
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
return typeof chrome !== "undefined";
|
return typeof chrome !== "undefined" && typeof chrome.storage !== "undefined" && typeof chrome.storage.sync !== "undefined";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1077,6 +1078,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
class ObsidianContext extends Context {
|
class ObsidianContext extends Context {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @override
|
* @override
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
@@ -1164,15 +1166,29 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const CONTEXTS = [
|
const contextProcessingOrder = [
|
||||||
new UserScriptContext(),
|
new UserScriptContext(),
|
||||||
new ObsidianContext(),
|
new ObsidianContext(),
|
||||||
new BrowserExtensionContext(),
|
new BrowserExtensionContext(),
|
||||||
new LocalContext()
|
new LocalContext()
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const CONTEXTS_BY_KEY = {
|
||||||
|
"local": LocalContext,
|
||||||
|
"userscript": UserScriptContext,
|
||||||
|
"browser-extension": BrowserExtensionContext,
|
||||||
|
"obsidian": ObsidianContext
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines and returns the current context
|
||||||
|
* @returns {Context}
|
||||||
|
*/
|
||||||
function getContext() {
|
function getContext() {
|
||||||
for (const context of CONTEXTS) {
|
if (CONTEXTS_BY_KEY[SET_CONTEXT]) {
|
||||||
|
return new CONTEXTS_BY_KEY[SET_CONTEXT]();
|
||||||
|
}
|
||||||
|
for (const context of contextProcessingOrder) {
|
||||||
if (context.isContextActive()) {
|
if (context.isContextActive()) {
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
dist/extension.zip
vendored
BIN
dist/extension.zip
vendored
Binary file not shown.
22
dist/extension/birb.js
vendored
22
dist/extension/birb.js
vendored
@@ -847,6 +847,7 @@
|
|||||||
|
|
||||||
const SAVE_KEY = "birbSaveData";
|
const SAVE_KEY = "birbSaveData";
|
||||||
const ROOT_PATH = "";
|
const ROOT_PATH = "";
|
||||||
|
const SET_CONTEXT = "__CONTEXT__";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {import('./application.js').BirbSaveData} BirbSaveData
|
* @typedef {import('./application.js').BirbSaveData} BirbSaveData
|
||||||
@@ -1033,7 +1034,7 @@
|
|||||||
*/
|
*/
|
||||||
isContextActive() {
|
isContextActive() {
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
return typeof chrome !== "undefined";
|
return typeof chrome !== "undefined" && typeof chrome.storage !== "undefined" && typeof chrome.storage.sync !== "undefined";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1077,6 +1078,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
class ObsidianContext extends Context {
|
class ObsidianContext extends Context {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @override
|
* @override
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
@@ -1164,15 +1166,29 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const CONTEXTS = [
|
const contextProcessingOrder = [
|
||||||
new UserScriptContext(),
|
new UserScriptContext(),
|
||||||
new ObsidianContext(),
|
new ObsidianContext(),
|
||||||
new BrowserExtensionContext(),
|
new BrowserExtensionContext(),
|
||||||
new LocalContext()
|
new LocalContext()
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const CONTEXTS_BY_KEY = {
|
||||||
|
"local": LocalContext,
|
||||||
|
"userscript": UserScriptContext,
|
||||||
|
"browser-extension": BrowserExtensionContext,
|
||||||
|
"obsidian": ObsidianContext
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines and returns the current context
|
||||||
|
* @returns {Context}
|
||||||
|
*/
|
||||||
function getContext() {
|
function getContext() {
|
||||||
for (const context of CONTEXTS) {
|
if (CONTEXTS_BY_KEY[SET_CONTEXT]) {
|
||||||
|
return new CONTEXTS_BY_KEY[SET_CONTEXT]();
|
||||||
|
}
|
||||||
|
for (const context of contextProcessingOrder) {
|
||||||
if (context.isContextActive()) {
|
if (context.isContextActive()) {
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|||||||
22
dist/obsidian/main.js
vendored
22
dist/obsidian/main.js
vendored
@@ -852,6 +852,7 @@ module.exports = class PocketBird extends Plugin {
|
|||||||
|
|
||||||
const SAVE_KEY = "birbSaveData";
|
const SAVE_KEY = "birbSaveData";
|
||||||
const ROOT_PATH = "";
|
const ROOT_PATH = "";
|
||||||
|
const SET_CONTEXT = "__CONTEXT__";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {import('./application.js').BirbSaveData} BirbSaveData
|
* @typedef {import('./application.js').BirbSaveData} BirbSaveData
|
||||||
@@ -1038,7 +1039,7 @@ module.exports = class PocketBird extends Plugin {
|
|||||||
*/
|
*/
|
||||||
isContextActive() {
|
isContextActive() {
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
return typeof chrome !== "undefined";
|
return typeof chrome !== "undefined" && typeof chrome.storage !== "undefined" && typeof chrome.storage.sync !== "undefined";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1082,6 +1083,7 @@ module.exports = class PocketBird extends Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class ObsidianContext extends Context {
|
class ObsidianContext extends Context {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @override
|
* @override
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
@@ -1169,15 +1171,29 @@ module.exports = class PocketBird extends Plugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const CONTEXTS = [
|
const contextProcessingOrder = [
|
||||||
new UserScriptContext(),
|
new UserScriptContext(),
|
||||||
new ObsidianContext(),
|
new ObsidianContext(),
|
||||||
new BrowserExtensionContext(),
|
new BrowserExtensionContext(),
|
||||||
new LocalContext()
|
new LocalContext()
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const CONTEXTS_BY_KEY = {
|
||||||
|
"local": LocalContext,
|
||||||
|
"userscript": UserScriptContext,
|
||||||
|
"browser-extension": BrowserExtensionContext,
|
||||||
|
"obsidian": ObsidianContext
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines and returns the current context
|
||||||
|
* @returns {Context}
|
||||||
|
*/
|
||||||
function getContext() {
|
function getContext() {
|
||||||
for (const context of CONTEXTS) {
|
if (CONTEXTS_BY_KEY[SET_CONTEXT]) {
|
||||||
|
return new CONTEXTS_BY_KEY[SET_CONTEXT]();
|
||||||
|
}
|
||||||
|
for (const context of contextProcessingOrder) {
|
||||||
if (context.isContextActive()) {
|
if (context.isContextActive()) {
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|||||||
22
dist/userscript/birb.user.js
vendored
22
dist/userscript/birb.user.js
vendored
@@ -861,6 +861,7 @@
|
|||||||
|
|
||||||
const SAVE_KEY = "birbSaveData";
|
const SAVE_KEY = "birbSaveData";
|
||||||
const ROOT_PATH = "";
|
const ROOT_PATH = "";
|
||||||
|
const SET_CONTEXT = "__CONTEXT__";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {import('./application.js').BirbSaveData} BirbSaveData
|
* @typedef {import('./application.js').BirbSaveData} BirbSaveData
|
||||||
@@ -1047,7 +1048,7 @@
|
|||||||
*/
|
*/
|
||||||
isContextActive() {
|
isContextActive() {
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
return typeof chrome !== "undefined";
|
return typeof chrome !== "undefined" && typeof chrome.storage !== "undefined" && typeof chrome.storage.sync !== "undefined";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1091,6 +1092,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
class ObsidianContext extends Context {
|
class ObsidianContext extends Context {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @override
|
* @override
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
@@ -1178,15 +1180,29 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const CONTEXTS = [
|
const contextProcessingOrder = [
|
||||||
new UserScriptContext(),
|
new UserScriptContext(),
|
||||||
new ObsidianContext(),
|
new ObsidianContext(),
|
||||||
new BrowserExtensionContext(),
|
new BrowserExtensionContext(),
|
||||||
new LocalContext()
|
new LocalContext()
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const CONTEXTS_BY_KEY = {
|
||||||
|
"local": LocalContext,
|
||||||
|
"userscript": UserScriptContext,
|
||||||
|
"browser-extension": BrowserExtensionContext,
|
||||||
|
"obsidian": ObsidianContext
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines and returns the current context
|
||||||
|
* @returns {Context}
|
||||||
|
*/
|
||||||
function getContext() {
|
function getContext() {
|
||||||
for (const context of CONTEXTS) {
|
if (CONTEXTS_BY_KEY[SET_CONTEXT]) {
|
||||||
|
return new CONTEXTS_BY_KEY[SET_CONTEXT]();
|
||||||
|
}
|
||||||
|
for (const context of contextProcessingOrder) {
|
||||||
if (context.isContextActive()) {
|
if (context.isContextActive()) {
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|||||||
2837
dist/vencord/birb.export.js
vendored
Normal file
2837
dist/vencord/birb.export.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
3
platform-specific/vencord/wrapper.js
Normal file
3
platform-specific/vencord/wrapper.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
export const Birb = () => {
|
||||||
|
__CODE__
|
||||||
|
};
|
||||||
@@ -2,6 +2,7 @@ import { debug, log, error } from "./shared.js";
|
|||||||
|
|
||||||
const SAVE_KEY = "birbSaveData";
|
const SAVE_KEY = "birbSaveData";
|
||||||
const ROOT_PATH = "";
|
const ROOT_PATH = "";
|
||||||
|
const SET_CONTEXT = "__CONTEXT__"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {import('./application.js').BirbSaveData} BirbSaveData
|
* @typedef {import('./application.js').BirbSaveData} BirbSaveData
|
||||||
@@ -188,7 +189,7 @@ class BrowserExtensionContext extends Context {
|
|||||||
*/
|
*/
|
||||||
isContextActive() {
|
isContextActive() {
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
return typeof chrome !== "undefined";
|
return typeof chrome !== "undefined" && typeof chrome.storage !== "undefined" && typeof chrome.storage.sync !== "undefined";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -232,6 +233,7 @@ class BrowserExtensionContext extends Context {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class ObsidianContext extends Context {
|
export class ObsidianContext extends Context {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @override
|
* @override
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
@@ -319,15 +321,29 @@ export class ObsidianContext extends Context {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const CONTEXTS = [
|
const contextProcessingOrder = [
|
||||||
new UserScriptContext(),
|
new UserScriptContext(),
|
||||||
new ObsidianContext(),
|
new ObsidianContext(),
|
||||||
new BrowserExtensionContext(),
|
new BrowserExtensionContext(),
|
||||||
new LocalContext()
|
new LocalContext()
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const CONTEXTS_BY_KEY = {
|
||||||
|
"local": LocalContext,
|
||||||
|
"userscript": UserScriptContext,
|
||||||
|
"browser-extension": BrowserExtensionContext,
|
||||||
|
"obsidian": ObsidianContext
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines and returns the current context
|
||||||
|
* @returns {Context}
|
||||||
|
*/
|
||||||
export function getContext() {
|
export function getContext() {
|
||||||
for (const context of CONTEXTS) {
|
if (CONTEXTS_BY_KEY[SET_CONTEXT]) {
|
||||||
|
return new CONTEXTS_BY_KEY[SET_CONTEXT]();
|
||||||
|
}
|
||||||
|
for (const context of contextProcessingOrder) {
|
||||||
if (context.isContextActive()) {
|
if (context.isContextActive()) {
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user