diff options
Diffstat (limited to 'browser')
-rw-r--r-- | browser/Vencord.ts | 3 | ||||
-rw-r--r-- | browser/VencordNativeStub.ts | 39 | ||||
-rw-r--r-- | browser/background.js | 1 | ||||
-rw-r--r-- | browser/content.js | 10 | ||||
-rw-r--r-- | browser/manifest.json | 30 |
5 files changed, 83 insertions, 0 deletions
diff --git a/browser/Vencord.ts b/browser/Vencord.ts new file mode 100644 index 0000000..2d4315d --- /dev/null +++ b/browser/Vencord.ts @@ -0,0 +1,3 @@ +import "./VencordNativeStub"; + +export * from "../src/Vencord"; diff --git a/browser/VencordNativeStub.ts b/browser/VencordNativeStub.ts new file mode 100644 index 0000000..bdcae4e --- /dev/null +++ b/browser/VencordNativeStub.ts @@ -0,0 +1,39 @@ +import IpcEvents from "../src/utils/IpcEvents"; + +// Discord deletes this so need to store in variable +var localStorage = window.localStorage; + +const handlers = { + [IpcEvents.GET_REPO]: () => "", // TODO + [IpcEvents.GET_SETTINGS_DIR]: () => "LocalStorage", + + [IpcEvents.GET_QUICK_CSS]: () => localStorage.getItem("VencordQuickCss"), + [IpcEvents.GET_SETTINGS]: () => localStorage.getItem("VencordSettings") || "{}", + [IpcEvents.SET_SETTINGS]: (s: string) => localStorage.setItem("VencordSettings", s), + + [IpcEvents.GET_UPDATES]: () => ({ ok: true, value: [] }), + + [IpcEvents.OPEN_EXTERNAL]: (url: string) => open(url, "_blank"), + [IpcEvents.OPEN_QUICKCSS]: () => { } // TODO +}; + +function onEvent(event: string, ...args: any[]) { + const handler = handlers[event]; + if (!handler) throw new Error(`Event ${event} not implemented.`); + return handler(...args); +} + +window.VencordNative = { + getVersions: () => ({}), + ipc: { + send: (event: string, ...args: any[]) => void onEvent(event, ...args), + sendSync: onEvent, + on(event: string, listener: () => {}) { + // TODO quickCss + }, + off(event: string, listener: () => {}) { + // not used for now + }, + invoke: (event: string, ...args: any[]) => Promise.resolve(onEvent(event, ...args)) + }, +}; diff --git a/browser/background.js b/browser/background.js new file mode 100644 index 0000000..872134b --- /dev/null +++ b/browser/background.js @@ -0,0 +1 @@ +// could use this in the future diff --git a/browser/content.js b/browser/content.js new file mode 100644 index 0000000..5922e8f --- /dev/null +++ b/browser/content.js @@ -0,0 +1,10 @@ +// This is just the bootstrap script + +if (typeof browser === "undefined") { + var browser = chrome; +} + +var script = document.createElement("script"); +script.src = browser.runtime.getURL("dist/Vencord.js"); +// documentElement because we load before body/head are ready +document.documentElement.appendChild(script); diff --git a/browser/manifest.json b/browser/manifest.json new file mode 100644 index 0000000..c01bc44 --- /dev/null +++ b/browser/manifest.json @@ -0,0 +1,30 @@ +{ + "manifest_version": 2, + "name": "Vencord Web", + "description": "Yeee", + "version": "1.0.0", + "author": "Vendicated", + "homepage_url": "https://github.com/Vendicated/Vencord", + "background": { + "scripts": [ + "background.js" + ] + }, + "content_scripts": [ + { + "run_at": "document_start", + "matches": [ + "*://*.discord.com/*" + ], + "js": [ + "content.js" + ] + } + ], + "permissions": [ + "*://*.discord.com/*" + ], + "web_accessible_resources": [ + "dist/Vencord.js" + ] +} |