Skip to content

Commit

Permalink
Merge pull request #152 from vrc-plugin/support-jinnai-system
Browse files Browse the repository at this point in the history
feat: support jinnai system
  • Loading branch information
bootjp authored Feb 16, 2023
2 parents 23aebd3 + dcd9a57 commit a27fdce
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 3 deletions.
25 changes: 24 additions & 1 deletion src/background.ts
Original file line number Diff line number Diff line change
@@ -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<true> =
Expand All @@ -12,14 +15,23 @@ const ERROR_NOTIFICATION_OPTIONS: chrome.notifications.NotificationOptions<true>
} 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",
mode: "cors",
credentials: "omit",
cache: "no-cache",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ url: url }),
body: JSON.stringify(body),
});

if (!res.ok) {
Expand Down Expand Up @@ -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: {
Expand All @@ -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;
}
}
});

Expand Down
10 changes: 10 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export async function getUseJinnaiSystem(): Promise<boolean> {
const { useJinnaiSystem } = await chrome.storage.local.get("useJinnaiSystem");
return useJinnaiSystem ?? false;
}

export function setUseJinnaiSystem(value: boolean): Promise<void> {
return chrome.storage.local.set({
useJinnaiSystem: value,
});
}
14 changes: 14 additions & 0 deletions src/options.ts
Original file line number Diff line number Diff line change
@@ -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;
});
9 changes: 7 additions & 2 deletions static/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -18,7 +22,8 @@
"contextMenus",
"clipboardRead",
"notifications",
"scripting"
"scripting",
"storage"
],
"host_permissions": ["http://localhost:11400/*"]
}
17 changes: 17 additions & 0 deletions static/options.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>SendVRC Options</title>
</head>
<body>
<h1>SendVRC Options</h1>
<div>
<input id="useJinnaiSystem" type="checkbox" />
<label for="useJinnaiSystem">Use Jinnai system</label>
</div>
<script src="options.js"></script>
</body>
</html>
1 change: 1 addition & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down

0 comments on commit a27fdce

Please sign in to comment.