Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into develop/mv3
Browse files Browse the repository at this point in the history
# Conflicts:
#	package.json
  • Loading branch information
CodFrm committed Dec 27, 2023
2 parents 2fa52f2 + 061e285 commit dec26ce
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 65 deletions.
9 changes: 7 additions & 2 deletions pkg/filesystem/onedrive/onedrive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) => {
Expand Down
10 changes: 5 additions & 5 deletions pkg/filesystem/onedrive/rw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
}),
}
Expand Down
12 changes: 4 additions & 8 deletions src/locales/locales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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) => {
// 遍历数组寻找匹配语言
Expand All @@ -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()}`]
Expand Down
7 changes: 1 addition & 6 deletions src/pages/options/routes/Setting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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")!);
}}
Expand Down
6 changes: 5 additions & 1 deletion src/pkg/utils/match.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ 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",
"ok2",
"ok3",
]);
expect(url.match("http://test.list.ggnb.top:81/search")).toEqual([
"ok1",
"ok2",
"ok3",
]);
Expand All @@ -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("特殊情况", () => {
Expand Down
11 changes: 9 additions & 2 deletions src/pkg/utils/match.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ export default class Match<T> {
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 "";
}
Expand All @@ -75,7 +77,12 @@ export default class Match<T> {
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 === "/") {
Expand Down
9 changes: 8 additions & 1 deletion src/runtime/background/permission_verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/runtime/content/gm_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions src/runtime/content/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
});
86 changes: 46 additions & 40 deletions src/runtime/content/utils.ts
Original file line number Diff line number Diff line change
@@ -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";

// 构建脚本运行代码
Expand Down Expand Up @@ -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;
},
Expand All @@ -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;
Expand Down

0 comments on commit dec26ce

Please sign in to comment.