-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
176 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { PanelType } from "../shared"; | ||
import { ToolPanel } from "../common/ToolPanel"; | ||
import * as vscode from "vscode"; | ||
import i18n from "../i18n"; | ||
|
||
export class UserAgent extends ToolPanel<UserAgent> { | ||
constructor(panel: vscode.WebviewPanel, extensionUri: vscode.Uri) { | ||
super(panel, extensionUri, PanelType.userAgent, "react"); | ||
} | ||
|
||
public static createOrShow(extensionUri: vscode.Uri) { | ||
super.createOrShow( | ||
extensionUri, | ||
PanelType.userAgent, | ||
i18n.t("view.devtoys.others.userAgent.panel.title"), | ||
UserAgent | ||
); | ||
} | ||
|
||
public dispose(): void { | ||
super.dispose(); | ||
UserAgent.currentPanel = undefined; | ||
} | ||
} | ||
|
||
ToolPanel.allPanel.add(UserAgent); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import i18n from "i18next"; | ||
import { initReactI18next } from "react-i18next"; | ||
import en from "./locales/en.json"; | ||
import zh_CN from "./locales/zh-CN.json"; | ||
|
||
i18n.use(initReactI18next).init({ | ||
resources: { | ||
en: { | ||
translation: en, | ||
}, | ||
"zh-cn": { | ||
translation: zh_CN, | ||
}, | ||
}, | ||
lng: window.displayLanguage, | ||
lowerCaseLng: true, | ||
fallbackLng: "en", | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { useTranslation } from "react-i18next"; | ||
import { | ||
VSCodeTextField, | ||
VSCodeTextArea, | ||
} from "@vscode/webview-ui-toolkit/react"; | ||
import UAParser from "ua-parser-js"; | ||
import { useEffect, useState } from "react"; | ||
const uaParser = new UAParser(); | ||
export default () => { | ||
const { t } = useTranslation(); | ||
const [ua, setUa] = useState(window.navigator.userAgent); | ||
const [uaResult, setUaResult] = useState<UAParser.IResult>(); | ||
const formatUA = (result: UAParser.IResult | undefined) => { | ||
if (!result) { | ||
return ""; | ||
} | ||
let text = result.ua + "\n"; | ||
if (result.browser.name) { | ||
text += `\n- ${t("tool.userAgent.result.browser")}: ${ | ||
result.browser.name | ||
} ${result.browser.version}`; | ||
} | ||
if (result.device.type) { | ||
text += `\n- ${t("tool.userAgent.result.device")}: ${ | ||
result.device.type | ||
} / ${result.device.vendor} / ${result.device.model}`; | ||
} | ||
if (result.os.name) { | ||
text += `\n- ${t("tool.userAgent.result.os")}: ${result.os.name} / ${ | ||
result.os.version | ||
}`; | ||
} | ||
if (result.engine.name) { | ||
text += `\n- ${t("tool.userAgent.result.engine")}: ${ | ||
result.engine.name | ||
} / ${result.engine.version}`; | ||
} | ||
if (result.cpu.architecture) { | ||
text += `\n- ${t("tool.userAgent.result.cpu")}: ${ | ||
result.cpu.architecture | ||
}`; | ||
} | ||
return text; | ||
}; | ||
useEffect(() => { | ||
uaParser.setUA(ua); | ||
setUaResult(uaParser.getResult()); | ||
}, [ua]); | ||
// const [uaParser, setUaParser] = useState<UAParser>(); | ||
return ( | ||
<div> | ||
<h1>{t("tool.userAgent.title")}</h1> | ||
<VSCodeTextField | ||
value={ua} | ||
onInput={({ target }) => { | ||
setUa((target as HTMLInputElement).value); | ||
}} | ||
style={{ width: "100%" }} | ||
> | ||
{t("tool.userAgent.uaTextField.label")} | ||
</VSCodeTextField> | ||
<VSCodeTextArea | ||
style={{ width: "100%" }} | ||
value={formatUA(uaResult)} | ||
cols={20} | ||
rows={8} | ||
readOnly | ||
> | ||
{t("tool.userAgent.resultTextArea.label")} | ||
</VSCodeTextArea> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"tool.userAgent.result.browser": "Browser", | ||
"tool.userAgent.result.cpu": "CPU", | ||
"tool.userAgent.result.device": "Device", | ||
"tool.userAgent.result.engine": "Engine", | ||
"tool.userAgent.result.os": "OS", | ||
"tool.userAgent.resultTextArea.label": "Result", | ||
"tool.userAgent.title": "UserAgent Parser", | ||
"tool.userAgent.uaTextField.label": "UA" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"tool.userAgent.result.browser": "浏览器", | ||
"tool.userAgent.result.cpu": "架构", | ||
"tool.userAgent.result.device": "设备", | ||
"tool.userAgent.result.engine": "内核", | ||
"tool.userAgent.result.os": "操作系统", | ||
"tool.userAgent.resultTextArea.label": "解析结果", | ||
"tool.userAgent.title": "UserAgent 解析", | ||
"tool.userAgent.uaTextField.label": "UA" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React, { Component } from "react"; | ||
import ReactDOM from "react-dom"; | ||
import "../components/react/UserAgent/i18n"; | ||
import App from "../components/react/UserAgent/index"; | ||
|
||
ReactDOM.render( | ||
<React.StrictMode> | ||
<App></App> | ||
</React.StrictMode>, | ||
document.getElementById("root") | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters