Skip to content

Commit

Permalink
fix(core): 修复跨域问题
Browse files Browse the repository at this point in the history
  • Loading branch information
enncy committed Jun 4, 2022
1 parent 79e209b commit 8ad21bf
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
3 changes: 1 addition & 2 deletions packages/core/src/core/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,11 @@ export async function getRemoteSetting(port: number) {
let count = 3;
while (count > 0) {
try {
const res = await request(`http://localhost:${port}/setting`, {
return await request(`http://localhost:${port}/setting`, {
type: 'GM_xmlhttpRequest',
method: 'get',
contentType: 'json'
});
return res;
} catch { }
count--;
}
Expand Down
16 changes: 10 additions & 6 deletions packages/core/src/script/common/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createNote } from '../../components';
import { defineScript } from '../../core/define.script';
import { getRemoteSetting, onComplete, onInteractive, useUnsafeWindow } from '../../core/utils';
import { logger } from '../../logger';
import { useSettings } from '../../store';

const supports = ['*'];
Expand Down Expand Up @@ -63,12 +64,15 @@ export const CommonScript = defineScript({
name: '获取软件题库配置脚本',
url: supports,
async onload() {
const { common } = useSettings();
if (common.answererWrappers.length) {
const setting = await getRemoteSetting(15319);
if (setting?.answererWrappers) {
const { common } = useSettings();
common.answererWrappers = setting.answererWrappers;
if (top === self) {
const { common } = useSettings();
if (common.answererWrappers.length === 0) {
const setting = await getRemoteSetting(15319);
if (setting?.answererWrappers) {
logger('debug', '成功读取本地题库配置');
const { common } = useSettings();
common.answererWrappers = setting.answererWrappers;
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/script/cx/recognize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function mapRecognize() {
logger('debug', '正在加载字典库...');
// 预加载字体库
const res = await request('https://cdn.ocsjs.com/resources/font/table.json', {
type: 'fetch',
type: 'GM_xmlhttpRequest',
method: 'get',
contentType: 'json'
});
Expand Down
2 changes: 2 additions & 0 deletions userjs.template
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
// @icon https://cdn.ocsjs.com/logo.ico
// @connect enncy.cn
// @connect icodef.com
// @connect ocsjs.com
// @connect localhost
// @match *://*.chaoxing.com/*
// @match *://*.edu.cn/*
// @match *://*.org.cn/*
Expand Down

0 comments on commit 8ad21bf

Please sign in to comment.