From 47bbd175c3af34236bb610ea9f51d24e458fbf9c Mon Sep 17 00:00:00 2001 From: kakkokari-gtyih Date: Mon, 25 Dec 2023 18:06:22 +0900 Subject: [PATCH] =?UTF-8?q?(add)=20=E3=82=A8=E3=83=A9=E3=83=BC=E5=A0=B1?= =?UTF-8?q?=E5=91=8A=E3=83=95=E3=82=A9=E3=83=BC=E3=83=A0=E3=81=AB=E5=8B=95?= =?UTF-8?q?=E4=BD=9C=E7=92=B0=E5=A2=83=E3=82=92=E8=87=AA=E5=8B=95=E8=BF=BD?= =?UTF-8?q?=E8=A8=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/js/misc/get-issue-url.ts | 66 +++++++++++++++++++++++++++++++++ error.vue | 13 ++++++- package.json | 2 + pnpm-lock.yaml | 14 +++++++ 4 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 assets/js/misc/get-issue-url.ts diff --git a/assets/js/misc/get-issue-url.ts b/assets/js/misc/get-issue-url.ts new file mode 100644 index 00000000..625d5b26 --- /dev/null +++ b/assets/js/misc/get-issue-url.ts @@ -0,0 +1,66 @@ +import { withQuery } from 'ufo'; + +export async function getGhIssueUrl(options: { + lang: string; + repoUrl: string; +}) { + // Issue Templateのプレフィル + let environment = `* Model and OS of the device(s): +* Browser:`; + let template = '02_visitor-bug-report-en.yml'; + + if (options.lang === 'ja') { + template = '01_visitor-bug-report-ja.yml'; + } + + if (process.client) { + //@ts-ignore + if ('userAgentData' in navigator && 'getHighEntropyValues' in navigator.userAgentData) { + //@ts-ignore + const uaData = await navigator.userAgentData.getHighEntropyValues([ + "fullVersionList", + "platformVersion", + ]); + let osVersion = 'v' + uaData.platformVersion; + if (uaData.platform === 'Windows') { + // https://learn.microsoft.com/ja-jp/microsoft-edge/web-platform/how-to-detect-win11 + const majorPlatformVersion = parseInt(uaData.platformVersion.split('.')[0]); + if (majorPlatformVersion >= 13) { + osVersion = '11 or later'; + } + else if (majorPlatformVersion > 0) { + osVersion = '10'; + } + else { + osVersion = '8.1 or before'; + } + } + const browserData = uaData.fullVersionList.find((item: any) => item.brand.toLowerCase() !== 'not_a brand'); + const env = [ + `* Model and OS of the device(s): ${uaData.platform} ${osVersion}`, + `* Browser: ${browserData.brand} ${browserData.version}`, + `* Viewport Size: ${window.innerWidth}x${window.innerHeight}`, + `* (UA Detected Using getHighEntropyValues)`, + ]; + environment = env.join('\n'); + } else { + const UAParser = (await import('ua-parser-js')).default; + const ua = new UAParser(); + const uaRes = ua.getResult(); + const env = [ + `* Model and OS of the device(s): ${uaRes.os.name} v${uaRes.os.version}`, + `* Browser: ${uaRes.browser.name} (${uaRes.engine.name}) v${uaRes.browser.version}`, + `* Viewport Size: ${window.innerWidth}x${window.innerHeight}`, + `* Raw User Agent: ${uaRes.ua}`, + ]; + environment = env.join('\n'); + } + } + + return withQuery(`${options.repoUrl}/issues/new`, { + template, + environment, + labels: 'maybe non-developer,bug?', + }); + +} \ No newline at end of file diff --git a/error.vue b/error.vue index a114946b..525df846 100644 --- a/error.vue +++ b/error.vue @@ -15,7 +15,7 @@

{{ error?.statusCode === 404 ? $t('_error.notFoundDesc') : $t('_error.generalErrorDesc') }}

- {{ $t('_error.reportProblem') }} + {{ $t('_error.reportProblem') }}
@@ -27,7 +27,9 @@