From dcd9a5720d4b899429433d3fd5266669489c6bee Mon Sep 17 00:00:00 2001 From: koyashiro <6698252+koyashiro@users.noreply.github.com> Date: Thu, 16 Feb 2023 02:26:43 +0900 Subject: [PATCH] feat: support jinnai system Signed-off-by: koyashiro <6698252+koyashiro@users.noreply.github.com> --- src/background.ts | 25 ++++++++++++++++++++++++- src/config.ts | 10 ++++++++++ src/options.ts | 14 ++++++++++++++ static/manifest.json | 9 +++++++-- static/options.html | 17 +++++++++++++++++ webpack.config.js | 1 + 6 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 src/config.ts create mode 100644 src/options.ts create mode 100644 static/options.html diff --git a/src/background.ts b/src/background.ts index 9439ccd..4a47b13 100644 --- a/src/background.ts +++ b/src/background.ts @@ -1,6 +1,9 @@ +import { getUseJinnaiSystem } from "./config"; + const CONTEXT_MENUS = { SEND_THIS_PAGE: "send_this_page", SEND_WITH_CLIPBOARD: "send_with_clipboard", + OPEN_OPTIONS: "open_options", }; const ERROR_NOTIFICATION_OPTIONS: chrome.notifications.NotificationOptions = @@ -12,6 +15,15 @@ const ERROR_NOTIFICATION_OPTIONS: chrome.notifications.NotificationOptions } as const; const sendUrlToVRC = async (url: string) => { + let body: { url: string }; + if (await getUseJinnaiSystem()) { + const jinnaiSystemUrl = new URL("https://nextnex.com/"); + jinnaiSystemUrl.searchParams.set("url", url); + body = { url: jinnaiSystemUrl.toString() }; + } else { + body = { url }; + } + try { const res = await fetch("http://localhost:11400/url", { method: "POST", @@ -19,7 +31,7 @@ const sendUrlToVRC = async (url: string) => { credentials: "omit", cache: "no-cache", headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ url: url }), + body: JSON.stringify(body), }); if (!res.ok) { @@ -72,6 +84,13 @@ chrome.contextMenus.create({ contexts: ["action"], }); +chrome.contextMenus.create({ + id: CONTEXT_MENUS.OPEN_OPTIONS, + title: "Options", + type: "normal", + contexts: ["action"], +}); + chrome.contextMenus.onClicked.addListener(async (info, tab) => { switch (info.menuItemId) { case CONTEXT_MENUS.SEND_THIS_PAGE: { @@ -92,6 +111,10 @@ chrome.contextMenus.onClicked.addListener(async (info, tab) => { sendUrlToVRC(clipboardText); break; } + case CONTEXT_MENUS.OPEN_OPTIONS: { + chrome.tabs.create({ url: "options.html" }); + break; + } } }); diff --git a/src/config.ts b/src/config.ts new file mode 100644 index 0000000..407dc14 --- /dev/null +++ b/src/config.ts @@ -0,0 +1,10 @@ +export async function getUseJinnaiSystem(): Promise { + const { useJinnaiSystem } = await chrome.storage.local.get("useJinnaiSystem"); + return useJinnaiSystem ?? false; +} + +export function setUseJinnaiSystem(value: boolean): Promise { + return chrome.storage.local.set({ + useJinnaiSystem: value, + }); +} diff --git a/src/options.ts b/src/options.ts new file mode 100644 index 0000000..38a3f48 --- /dev/null +++ b/src/options.ts @@ -0,0 +1,14 @@ +import { getUseJinnaiSystem, setUseJinnaiSystem } from "./config"; + +const useJinnaiSystemInput = document.getElementById( + "useJinnaiSystem" +) as HTMLInputElement; + +useJinnaiSystemInput.addEventListener("change", () => { + setUseJinnaiSystem(useJinnaiSystemInput.checked); +}); + +window.addEventListener("load", async () => { + const useJinnaiSystem = await getUseJinnaiSystem(); + useJinnaiSystemInput.checked = useJinnaiSystem; +}); diff --git a/static/manifest.json b/static/manifest.json index 154e870..2a64fe9 100644 --- a/static/manifest.json +++ b/static/manifest.json @@ -4,7 +4,11 @@ "version": "1.1.1", "description": "Sends the URL to VRChat. send_vrc_desktop is required for one-click operation.", "action": { - "default_icon": "icon.png", + "default_icon": { + "16": "icon.png", + "24": "icon.png", + "32": "icon.png" + }, "default_title": "this page send to VRChat" }, "icons": { @@ -18,7 +22,8 @@ "contextMenus", "clipboardRead", "notifications", - "scripting" + "scripting", + "storage" ], "host_permissions": ["http://localhost:11400/*"] } diff --git a/static/options.html b/static/options.html new file mode 100644 index 0000000..54b47cb --- /dev/null +++ b/static/options.html @@ -0,0 +1,17 @@ + + + + + + + SendVRC Options + + +

SendVRC Options

+
+ + +
+ + + diff --git a/webpack.config.js b/webpack.config.js index 81a5a4c..7ba773d 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -7,6 +7,7 @@ module.exports = { mode: process.env.NODE_ENV || "development", entry: { background: path.join(__dirname, "src/background.ts"), + options: path.join(__dirname, "src/options.ts"), }, output: { path: path.join(__dirname, "dist"),