diff --git a/pkg/filesystem/onedrive/onedrive.ts b/pkg/filesystem/onedrive/onedrive.ts index d40a6f2d..aa7ecfda 100644 --- a/pkg/filesystem/onedrive/onedrive.ts +++ b/pkg/filesystem/onedrive/onedrive.ts @@ -62,8 +62,11 @@ export default class OneDriveFileSystem implements FileSystem { } const myHeaders = new Headers(); myHeaders.append("Content-Type", "application/json"); + if (parent !== "") { + parent = `:${parent}:`; + } return this.request( - `https://graph.microsoft.com/v1.0/me/drive/special/approot:${parent}:/children`, + `https://graph.microsoft.com/v1.0/me/drive/special/approot${parent}/children`, { method: "POST", headers: myHeaders, @@ -136,9 +139,11 @@ export default class OneDriveFileSystem implements FileSystem { let { path } = this; if (path === "/") { path = ""; + } else { + path = `:${path}:`; } return this.request( - `https://graph.microsoft.com/v1.0/me/drive/special/approot:${path}:/children` + `https://graph.microsoft.com/v1.0/me/drive/special/approot${path}/children` ).then((data) => { const list: File[] = []; data.value.forEach((val: any) => { diff --git a/pkg/filesystem/onedrive/rw.ts b/pkg/filesystem/onedrive/rw.ts index 934b9e24..4f2029fa 100644 --- a/pkg/filesystem/onedrive/rw.ts +++ b/pkg/filesystem/onedrive/rw.ts @@ -76,11 +76,11 @@ export class OneDriveFileWriter implements FileWriter { body: JSON.stringify({ item: { "@microsoft.graph.conflictBehavior": "replace", - description: "description", - fileSystemInfo: { - "@odata.type": "microsoft.graph.fileSystemInfo", - }, - name: this.path.substring(this.path.lastIndexOf("/") + 1), + // description: "description", + // fileSystemInfo: { + // "@odata.type": "microsoft.graph.fileSystemInfo", + // }, + // name: this.path.substring(this.path.lastIndexOf("/") + 1), }, }), } diff --git a/src/locales/locales.ts b/src/locales/locales.ts index e37a19e8..9f0da14c 100644 --- a/src/locales/locales.ts +++ b/src/locales/locales.ts @@ -8,6 +8,7 @@ import zhCN from "./zh-CN/translation.json"; import zhTW from "./zh-TW/translation.json"; import achUG from "./ach-UG/translation.json"; import "dayjs/locale/zh-cn"; +import "dayjs/locale/zh-tw"; i18n.use(initReactI18next).init({ fallbackLng: "zh-CN", @@ -23,14 +24,6 @@ i18n.use(initReactI18next).init({ }, }); -dayjs.locale( - ( - (localStorage.language || chrome.i18n.getUILanguage()) as string - ).toLocaleLowerCase() -); - -dayjs.extend(relativeTime); - if (!localStorage.language) { chrome.i18n.getAcceptLanguages((lngs) => { // 遍历数组寻找匹配语言 @@ -44,7 +37,10 @@ if (!localStorage.language) { } } }); +} else { + dayjs.locale((localStorage.language as string).toLocaleLowerCase()); } +dayjs.extend(relativeTime); export function i18nName(script: { name: string; metadata: Metadata }) { return script.metadata[`name:${i18n.language.toLowerCase()}`] diff --git a/src/pages/options/routes/Setting.tsx b/src/pages/options/routes/Setting.tsx index c3282adc..f3a90d07 100644 --- a/src/pages/options/routes/Setting.tsx +++ b/src/pages/options/routes/Setting.tsx @@ -83,12 +83,7 @@ function Setting() { } setLanguage(value); i18n.changeLanguage(value); - dayjs.locale( - ( - (localStorage.language || - chrome.i18n.getUILanguage()) as string - ).toLocaleLowerCase() - ); + dayjs.locale(value.toLocaleLowerCase()); localStorage.language = value; Message.success(t("language_change_tip")!); }} diff --git a/src/pkg/utils/match.test.ts b/src/pkg/utils/match.test.ts index 89b4944e..0313c246 100644 --- a/src/pkg/utils/match.test.ts +++ b/src/pkg/utils/match.test.ts @@ -116,6 +116,7 @@ describe("UrlMatch-port2", () => { url.add("http://test.list.ggnb.top:80/search", "ok1"); url.add("http://test.list.ggnb.top*/search", "ok2"); url.add("http://test.list.ggnb.top:*/search", "ok3"); + url.add("http://localhost:3000/", "ok4"); it("match1", () => { expect(url.match("http://test.list.ggnb.top:80/search")).toEqual([ "ok1", @@ -123,7 +124,6 @@ describe("UrlMatch-port2", () => { "ok3", ]); expect(url.match("http://test.list.ggnb.top:81/search")).toEqual([ - "ok1", "ok2", "ok3", ]); @@ -133,6 +133,10 @@ describe("UrlMatch-port2", () => { "ok3", ]); }); + it("case2", () => { + expect(url.match("http://localhost:3000/")).toEqual(["ok4"]); + expect(url.match("http://localhost:8000/")).toEqual([]); + }); }); describe("特殊情况", () => { diff --git a/src/pkg/utils/match.ts b/src/pkg/utils/match.ts index d74bab67..fe774b7a 100644 --- a/src/pkg/utils/match.ts +++ b/src/pkg/utils/match.ts @@ -53,7 +53,9 @@ export default class Match { pos = -1; } else if (u.host.endsWith("*")) { // 处理*结尾 - u.host = u.host.substring(0, u.host.length - 1); + if (!u.host.endsWith(":*")) { + u.host = u.host.substring(0, u.host.length - 1); + } } else if (pos !== -1 && pos !== 0) { return ""; } @@ -75,7 +77,12 @@ export default class Match { if (pos2 === -1) { u.host = `${u.host}(:\\d+)?`; } else { - u.host = `${u.host.substring(0, pos2)}(:\\d+)?`; + const port = u.host.substring(pos2 + 1); + if (port === "*") { + u.host = `${u.host.substring(0, pos2)}(:\\d+)?`; + } else { + u.host = `${u.host.substring(0, pos2)}(:${port})?`; + } } let re = `^${u.scheme}://${u.host}`; if (u.path === "/") { diff --git a/src/runtime/background/permission_verify.ts b/src/runtime/background/permission_verify.ts index 09442f49..531217e1 100644 --- a/src/runtime/background/permission_verify.ts +++ b/src/runtime/background/permission_verify.ts @@ -232,7 +232,14 @@ export default class PermissionVerify { } for (let i = 0; i < grant.length; i += 1) { - if (grant[i] === request.api || grant[i] === api.param.link) { + if ( + // 名称相等 + grant[i] === request.api || + // 别名相等 + (api.param.alias && api.param.alias.includes(grant[i])) || + // 有关联的 + grant[i] === api.param.link + ) { // 需要用户确认 if (api.param.confirm) { return this.pushConfirmQueue(request, api); diff --git a/src/runtime/content/gm_api.ts b/src/runtime/content/gm_api.ts index f3d64584..4a79b8e1 100644 --- a/src/runtime/content/gm_api.ts +++ b/src/runtime/content/gm_api.ts @@ -139,6 +139,7 @@ export default class GMApi { icon64: (script.metadata.icon64 && script.metadata.icon64[0]) || null, header: metadataStr, grant: script.metadata.grant || [], + connects: script.metadata.connect || [], }; return { diff --git a/src/runtime/content/utils.test.ts b/src/runtime/content/utils.test.ts index 7c52f941..e43b1fa8 100644 --- a/src/runtime/content/utils.test.ts +++ b/src/runtime/content/utils.test.ts @@ -54,3 +54,13 @@ describe("兼容问题", () => { expect(() => _this.Object.freeze({})).not.toThrow(); }); }); + +// 允许往global写入Symbol属性,影响内容: https://bbs.tampermonkey.net.cn/thread-5509-1-1.html +describe("Symbol", () => { + const _this = proxyContext({}, {}); + it("Symbol", () => { + const s = Symbol("test"); + _this[s] = "ok"; + expect(_this[s]).toEqual("ok"); + }); +}); diff --git a/src/runtime/content/utils.ts b/src/runtime/content/utils.ts index eade0a00..e66f86ba 100644 --- a/src/runtime/content/utils.ts +++ b/src/runtime/content/utils.ts @@ -1,7 +1,7 @@ import { MessageManager } from "@App/app/message/message"; import { ScriptRunResouce } from "@App/app/repo/scripts"; import { v4 as uuidv4 } from "uuid"; -import { has } from "lodash"; +import has from "lodash/has"; import GMApi, { ApiValue, GMContext } from "./gm_api"; // 构建脚本运行代码 @@ -197,37 +197,39 @@ export function proxyContext( default: break; } - if (typeof name === "string" && name !== "undefined") { + if (name !== "undefined") { if (has(thisContext, name)) { // @ts-ignore return thisContext[name]; } - if (context[name]) { - if (contextKeyword[name]) { - return undefined; + if (typeof name === "string") { + if (context[name]) { + if (contextKeyword[name]) { + return undefined; + } + return context[name]; } - return context[name]; - } - if (special[name] !== undefined) { - if ( - typeof special[name] === "function" && - !(<{ prototype: any }>special[name]).prototype - ) { - return (<{ bind: any }>special[name]).bind(global); + if (special[name] !== undefined) { + if ( + typeof special[name] === "function" && + !(<{ prototype: any }>special[name]).prototype + ) { + return (<{ bind: any }>special[name]).bind(global); + } + return special[name]; } - return special[name]; - } - if (global[name] !== undefined) { - if ( - typeof global[name] === "function" && - !(<{ prototype: any }>global[name]).prototype - ) { - return (<{ bind: any }>global[name]).bind(global); + if (global[name] !== undefined) { + if ( + typeof global[name] === "function" && + !(<{ prototype: any }>global[name]).prototype + ) { + return (<{ bind: any }>global[name]).bind(global); + } + return global[name]; } - return global[name]; + } else if (name === Symbol.unscopables) { + return unscopables; } - } else if (name === Symbol.unscopables) { - return unscopables; } return undefined; }, @@ -246,24 +248,28 @@ export function proxyContext( default: break; } - if (typeof name === "string" && name !== "undefined") { - if (unscopables[name]) { - return false; - } - if (has(thisContext, name)) { - return true; - } - if (context[name]) { - if (contextKeyword[name]) { + if (name !== "undefined") { + if (typeof name === "string") { + if (unscopables[name]) { return false; } - return true; - } - if (special[name] !== undefined) { - return true; - } - if (global[name] !== undefined) { - return true; + if (has(thisContext, name)) { + return true; + } + if (context[name]) { + if (contextKeyword[name]) { + return false; + } + return true; + } + if (special[name] !== undefined) { + return true; + } + if (global[name] !== undefined) { + return true; + } + } else if (typeof name === "symbol") { + return has(thisContext, name); } } return false;