Skip to content

Commit

Permalink
fix(script): 修复无法移动面板至边缘导致自动登录失效的BUG
Browse files Browse the repository at this point in the history
  • Loading branch information
enncy committed May 4, 2024
1 parent 64cc9c0 commit a05d0a1
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 9 deletions.
6 changes: 3 additions & 3 deletions packages/scripts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ocsjs/scripts",
"version": "4.0.0",
"version": "4.0.1",
"description": "core package of ocs",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
Expand Down Expand Up @@ -38,10 +38,10 @@
"vite-plugin-banner": "^0.6.1"
},
"dependencies": {
"@ocsjs/core": "workspace:4.0.0-beta.0",
"@ocsjs/core": "4.0.1",
"@rollup/plugin-commonjs": "^24.0.0",
"browser-env": "^3.3.0",
"easy-us": "^0.0.15",
"easy-us": "^0.0.18",
"lodash": "^4.17.21",
"markdown-it": "^13.0.1",
"marked": "^4.2.12",
Expand Down
3 changes: 2 additions & 1 deletion packages/scripts/src/projects/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { CommonProject } from './common';
import { definedProjects } from '..';
import { RenderScript } from '../render';
import { SearchInfosElement } from '../elements/search.infos';
import { $render } from '../utils/render';

const state = {
console: {
Expand Down Expand Up @@ -468,7 +469,7 @@ export const BackgroundProject = Project.create({
oncomplete() {
// 将面板移动至左侧顶部,防止挡住软件登录
if ($.isInTopWindow()) {
CommonProject.scripts.render.methods.moveToEdge();
$render.moveToEdge();
}
}
}),
Expand Down
6 changes: 5 additions & 1 deletion packages/scripts/src/projects/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,11 @@ export const CommonProject = Project.create({
]),
...createAnswererWrapperList(awsResult)
]),
onConfirm: () => top?.document.location.reload(),
onConfirm: () => {
if ($gm.isInGMContext()) {
top?.document.location.reload();
}
},
...($gm.isInGMContext()
? {
confirmButtonText: '立即刷新',
Expand Down
5 changes: 3 additions & 2 deletions packages/scripts/src/projects/icourse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { $console } from './background';
import { $playwright } from '../utils/app';
import { waitForElement, waitForMedia } from '../utils/study';
import { playbackRate, volume, workNotes } from '../utils/configs';
import { $render } from '../utils/render';

const state = {
currentMedia: undefined as HTMLMediaElement | undefined,
Expand Down Expand Up @@ -138,7 +139,7 @@ export const ICourseProject = Project.create({
}

// 移动窗口到边缘
CommonProject.scripts.render.methods.moveToEdge();
$render.moveToEdge();

const study = async () => {
const lessonName = document.querySelector('.j-lesson .j-up')?.textContent;
Expand Down Expand Up @@ -318,7 +319,7 @@ export const ICourseProject = Project.create({
CommonProject.scripts.render.methods.pin(this);

// 移动窗口到边缘
CommonProject.scripts.render.methods.moveToEdge();
$render.moveToEdge();

// 检查是否为软件环境
const remotePage = await RemotePlaywright.getCurrentPage();
Expand Down
5 changes: 3 additions & 2 deletions packages/scripts/src/projects/zhs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { CommonWorkOptions, playMedia } from '../utils';
import { $console } from './background';
import { waitForMedia } from '../utils/study';
import { $playwright } from '../utils/app';
import { $render } from '../utils/render';

const state = {
study: {
Expand Down Expand Up @@ -297,7 +298,7 @@ export const ZHSProject = Project.create({
if (options.length !== 0) {
await waitForCaptcha();
// 最小化脚本窗口
CommonProject.scripts.render.methods.moveToEdge();
$render.moveToEdge();
// 随机选
const random = Math.floor(Math.random() * options.length);
await $.sleep(1000);
Expand Down Expand Up @@ -382,7 +383,7 @@ export const ZHSProject = Project.create({
if (item) {
await $.sleep(3000);
// 最小化脚本窗口
CommonProject.scripts.render.methods.moveToEdge();
$render.moveToEdge();
// 点击侧边栏任务
await remotePage.click(item);

Expand Down
11 changes: 11 additions & 0 deletions packages/scripts/src/utils/render.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { CommonProject } from '../projects/common';

export const $render = {
/**
* 移动到边缘
*/
moveToEdge() {
CommonProject.scripts.render.methods.minimize();
CommonProject.scripts.render.methods.setPosition(80, 100);
}
};

0 comments on commit a05d0a1

Please sign in to comment.