feat: Experimental browser support

This commit is contained in:
Vendicated 2022-10-04 00:52:42 +02:00
parent a9eae106c7
commit cc25753314
No known key found for this signature in database
GPG key ID: EC781ADFB93EFFA3
14 changed files with 212 additions and 41 deletions

3
browser/Vencord.ts Normal file
View file

@ -0,0 +1,3 @@
import "./VencordNativeStub";
export * from "../src/Vencord";

View file

@ -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))
},
};

1
browser/background.js Normal file
View file

@ -0,0 +1 @@
// could use this in the future

10
browser/content.js Normal file
View file

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

30
browser/manifest.json Normal file
View file

@ -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"
]
}