Skip to content

Commit

Permalink
一些优化
Browse files Browse the repository at this point in the history
  • Loading branch information
HCLonely committed Feb 6, 2022
1 parent 92af867 commit ba2dbeb
Show file tree
Hide file tree
Showing 44 changed files with 517 additions and 400 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/Release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ jobs:
uses: softprops/action-gh-release@v1
with:
prerelease: false
tag_name: v4.2.1
name: 4.2.1
tag_name: v4.2.2
name: 4.2.2
body: |-
- 修复已知BUG
- 一些优化
- Keylol相关功能优化
- 控制台输出优化
- 调试功能优化
- 其他功能优化
files: |-
dist/auto-task-v4-for-giveawaysu.user.js
dist/auto-task-v4.compatibility.user.js
Expand Down
10 changes: 5 additions & 5 deletions dist/auto-task-v4-for-giveawaysu.user.js

Large diffs are not rendered by default.

36 changes: 18 additions & 18 deletions dist/auto-task-v4.compatibility.user.js

Large diffs are not rendered by default.

208 changes: 125 additions & 83 deletions dist/auto-task-v4.user.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions doc/docs/.vuepress/public/report.html

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions doc/docs/logs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ lang: zh-CN

## V4.2

### V4.2.2

[Release](https://github.com/HCLonely/auto-task-v4/releases/tag/v4.2.2)

- Keylol相关功能优化
- 控制台输出优化
- 调试功能优化
- 其他功能优化

### V4.2.1

[Release](https://github.com/HCLonely/auto-task-v4/releases/tag/v4.2.1)
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"name": "auto-task-v4",
"version": "4.2.1",
"version": "4.2.2",
"change": [
"修复已知BUG",
"一些优化"
"Keylol相关功能优化",
"控制台输出优化",
"调试功能优化",
"其他功能优化"
],
"description": "赠Key站自动任务脚本",
"main": "package.json",
Expand Down
10 changes: 5 additions & 5 deletions page/dist/auto-task-v4-for-giveawaysu.user.js

Large diffs are not rendered by default.

36 changes: 18 additions & 18 deletions page/dist/auto-task-v4.compatibility.user.js

Large diffs are not rendered by default.

208 changes: 125 additions & 83 deletions page/dist/auto-task-v4.user.js

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions page/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"name": "auto-task-v4",
"version": "4.2.1",
"version": "4.2.2",
"change": [
"修复已知BUG",
"一些优化"
"Keylol相关功能优化",
"控制台输出优化",
"调试功能优化",
"其他功能优化"
],
"description": "赠Key站自动任务脚本",
"main": "package.json",
Expand Down
4 changes: 3 additions & 1 deletion src/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* @Author : HCLonely
* @Date : 2021-10-13 13:18:21
* @LastEditTime : 2022-01-30 11:32:55
* @LastEditTime : 2022-02-06 11:27:21
* @LastEditors : HCLonely
* @FilePath : /auto-task-new/src/global.d.ts
*/
Expand Down Expand Up @@ -208,6 +208,8 @@ declare global {

interface Window {
STYLE: HTMLElement
DEBUG: boolean
TRACE: boolean
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,4 @@
// @noframes
// ==/UserScript==

console.log('%c%s', 'color:blue', 'Auto Task脚本开始加载');
console.log('%c%s', 'color:blue', 'Auto-Task[Load]: 脚本开始加载');
58 changes: 31 additions & 27 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* @Author : HCLonely
* @Date : 2021-10-26 15:44:54
* @LastEditTime : 2022-01-29 16:49:35
* @LastEditTime : 2022-02-06 11:37:38
* @LastEditors : HCLonely
* @FilePath : /auto-task-new/src/index.ts
* @Description : 入口文件
Expand All @@ -21,36 +21,15 @@ import updateChecker from './scripts/updateChecker';
import echoLog from './scripts/echoLog';

window.STYLE = GM_addStyle(style + GM_getResourceText('style'));
window.DEBUG = !!globalOptions.other?.debug;
window.TRACE = !!globalOptions.other?.debug && typeof console.trace === 'function';

declare const commonOptions: {
headers?: {
'Client-ID': string
}
};

if (window.location.hostname === 'discord.com') {
const LocalStorage = window.localStorage;
if (window.location.hash === '#auth') {
window.localStorage.removeItem = () => true;
const discordAuth = LocalStorage?.getItem('token')?.replace(/^"|"$/g, '');
if (discordAuth && discordAuth.length > 0) {
GM_setValue('discordAuth', { auth: discordAuth });
window.close();
Swal.fire('', __('closePageNotice'));
} else {
Swal.fire({
text: __('getDiscordAuthFailed'),
icon: 'error'
});
}
} else {
const discordAuth = LocalStorage?.getItem('token')?.replace(/^"|"$/g, '');
if (discordAuth && discordAuth.length > 0) {
GM_setValue('discordAuth', { auth: discordAuth });
}
}
}

const loadScript = async () => {
if (window.location.hostname === 'www.twitch.tv' && window.location.hash === '#auth') {
const authToken = Cookies.get('auth-token');
Expand All @@ -62,6 +41,7 @@ const loadScript = async () => {
} else {
Swal.fire('', __('needLogin'));
}
return;
}
if (window.location.hostname === 'twitter.com' && window.location.hash === '#auth') {
const ct0 = Cookies.get('ct0');
Expand All @@ -73,6 +53,7 @@ const loadScript = async () => {
} else {
Swal.fire('', __('needLogin'));
}
return;
}
if (window.location.hostname === 'www.youtube.com' && window.location.hash === '#auth') {
const PAPISID = Cookies.get('__Secure-3PAPISID');
Expand All @@ -83,6 +64,7 @@ const loadScript = async () => {
} else {
Swal.fire('', __('needLogin'));
}
return;
}
if (window.location.hostname === 'www.reddit.com' &&
(window.location.hash === '#auth' || GM_getValue('redditAuth') === '#auth')) {
Expand All @@ -94,6 +76,7 @@ const loadScript = async () => {
GM_setValue('redditAuth', null);
window.close();
Swal.fire('', __('closePageNotice'));
return;
}

let website: WebsiteType;
Expand All @@ -106,7 +89,7 @@ const loadScript = async () => {

// @ts-ignore
if (!website) {
console.log('%c%s', 'color:#ff0000', 'Auto Task脚本停止加载:当前网站不支持!');
console.log('%c%s', 'color:#ff0000', 'Auto-Task[Warning]: 脚本停止加载,当前网站不支持!');
return;
}

Expand Down Expand Up @@ -198,7 +181,7 @@ const loadScript = async () => {
});
}

console.log('%c%s', 'color:#1bbe1a', 'Auto Task脚本初始化完成!');
console.log('%c%s', 'color:#1bbe1a', 'Auto-Task[Load]: 脚本加载完成');

if (!GM_getValue<number>('notice')) {
Swal.fire({
Expand All @@ -216,7 +199,28 @@ const loadScript = async () => {
updateChecker();
};

if (window.location.hostname === 'opquests.com') {
if (window.location.hostname === 'discord.com') {
const LocalStorage = window.localStorage;
if (window.location.hash === '#auth') {
window.localStorage.removeItem = () => true;
const discordAuth = LocalStorage?.getItem('token')?.replace(/^"|"$/g, '');
if (discordAuth && discordAuth.length > 0) {
GM_setValue('discordAuth', { auth: discordAuth });
window.close();
Swal.fire('', __('closePageNotice'));
} else {
Swal.fire({
text: __('getDiscordAuthFailed'),
icon: 'error'
});
}
} else {
const discordAuth = LocalStorage?.getItem('token')?.replace(/^"|"$/g, '');
if (discordAuth && discordAuth.length > 0) {
GM_setValue('discordAuth', { auth: discordAuth });
}
}
} else if (window.location.hostname === 'opquests.com') {
loadScript();
} else {
$(loadScript);
Expand Down
3 changes: 2 additions & 1 deletion src/locales/en-US.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* @Author : HCLonely
* @Date : 2021-12-30 17:08:27
* @LastEditTime : 2022-01-30 11:39:07
* @LastEditTime : 2022-02-06 11:10:13
* @LastEditors : HCLonely
* @FilePath : /auto-task-new/src/locales/en-US.js
* @Description : i18n英文
Expand Down Expand Up @@ -101,6 +101,7 @@ const data = {
hideLog: 'HideLog',
defaultShowButton: 'Default display button',
defaultShowLog: 'Display log by default',
debug: 'Output debug log, do not enable this option!',
position: 'Component position',
buttonSideX: 'Horizontal positioning of the button area (real-time preview function is only available on the setting page).' +
'</br>left: left | right: right',
Expand Down
3 changes: 2 additions & 1 deletion src/locales/zh-CN.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* @Author : HCLonely
* @Date : 2021-11-20 19:38:41
* @LastEditTime : 2022-01-30 11:38:23
* @LastEditTime : 2022-02-06 11:08:02
* @LastEditors : HCLonely
* @FilePath : /auto-task-new/src/locales/zh-CN.js
* @Description : i18n中文
Expand Down Expand Up @@ -96,6 +96,7 @@ const data = {
hideLog: '隐藏日志',
defaultShowButton: '默认显示按钮',
defaultShowLog: '默认显示日志',
debug: '输出调试日志,不要开启此选项!',
position: '组件位置',
buttonSideX: '按钮区域水平方向定位(实时预览功能仅在设置页面可用)</br>left: 靠左 | right: 靠右',
buttonSideY: '按钮区域垂直方向定位(实时预览功能仅在设置页面可用)</br>top: 靠上 | bottom: 靠下',
Expand Down
3 changes: 2 additions & 1 deletion src/scripts/globalOptions.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* @Author : HCLonely
* @Date : 2021-12-24 17:21:16
* @LastEditTime : 2022-01-30 11:30:13
* @LastEditTime : 2022-02-06 11:05:10
* @LastEditors : HCLonely
* @FilePath : /auto-task-new/src/scripts/globalOptions.d.ts
*/
Expand Down Expand Up @@ -104,5 +104,6 @@ interface globalOptions {
checkLeftKey: boolean
defaultShowButton: boolean
defaultShowLog: boolean
debug: boolean
}
}
5 changes: 3 additions & 2 deletions src/scripts/globalOptions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* @Author : HCLonely
* @Date : 2021-12-24 16:41:12
* @LastEditTime : 2022-01-30 11:30:24
* @LastEditTime : 2022-02-06 11:05:01
* @LastEditors : HCLonely
* @FilePath : /auto-task-new/src/scripts/globalOptions.ts
* @Description : 全局设置选项
Expand Down Expand Up @@ -112,7 +112,8 @@ const defaultGlobalOptions: globalOptions = {
checkLogin: true,
checkLeftKey: true,
defaultShowButton: true,
defaultShowLog: true
defaultShowLog: true,
debug: false
}
};

Expand Down
20 changes: 10 additions & 10 deletions src/scripts/social/Discord.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* @Author : HCLonely
* @Date : 2021-09-28 15:03:10
* @LastEditTime : 2022-01-30 11:58:03
* @LastEditTime : 2022-02-06 11:48:22
* @LastEditors : HCLonely
* @FilePath : /auto-task-new/src/scripts/social/Discord.ts
* @Description : Discord 加入&移除服务器
Expand Down Expand Up @@ -29,7 +29,7 @@ class Discord extends Social {
/**
* @description: 验证及获取Auth
* @return true: 初始化完成 | false: 初始化失败,toggle方法不可用
*/
*/
try {
if (this.#initialized) {
return true;
Expand Down Expand Up @@ -66,7 +66,7 @@ class Discord extends Social {
* @internal
* @description 检测Discord Token是否失效
* @return true: Token有效 | false: Token失效
*/
*/
try {
const logStatus = echoLog({ text: __('verifyingAuth', 'Discord') });
const { result, statusText, status, data } = await httpRequest({
Expand Down Expand Up @@ -95,7 +95,7 @@ class Discord extends Social {
* @internal
* @description 通过打开Discord网站更新Token.
* @return true: 更新Token成功 | false: 更新Token失败
*/
*/
try {
const logStatus = echoLog({ text: __('updatingAuth', 'Discord') });
return await new Promise((resolve) => {
Expand Down Expand Up @@ -125,7 +125,7 @@ class Discord extends Social {
* @description 加入Discord服务器
* @param inviteId: 邀请id
* @return true: 加入成功 | false: 加入失败
*/
*/
try {
const logStatus = echoLog({ type: 'joiningDiscordServer', text: inviteId });
const { result, statusText, status, data } = await httpRequest({
Expand Down Expand Up @@ -157,7 +157,7 @@ class Discord extends Social {
* @description 退出Discord服务器
* @param inviteId: 邀请id
* @return true: 退出成功 | false: 退出失败
*/
*/
try {
if (this.whiteList.servers.includes(inviteId)) {
echoLog({ type: 'whiteList', text: 'Discord.leaveServer', id: inviteId });
Expand Down Expand Up @@ -191,7 +191,7 @@ class Discord extends Social {
* @description 通过{inviteId}获取{guild}, {guild}用于退出服务器
* @param inviteId: 邀请id
* @return {string}: 获取成功,返回{guild} | false: 获取失败
*/
*/
try {
const logStatus = echoLog({ type: 'gettingDiscordGuild', text: inviteId });
const guild = this.#cache[inviteId];
Expand Down Expand Up @@ -233,7 +233,7 @@ class Discord extends Social {
* @description 公有方法,统一处理Discord相关任务
* @param {boolean} doTask true: 做任务 | false: 取消任务
* @param {?Array} serverLinks Discord服务器邀请链接数组。注意: 不接受邀请id数组
*/
*/
try {
if (!this.#initialized) {
echoLog({ text: __('needInit') });
Expand Down Expand Up @@ -271,7 +271,7 @@ class Discord extends Social {
* @internal
* @description 缓存{inviteId}与{guild}的对应关系
* @return {void}
*/
*/
try {
this.#cache[inviteId] = guild;
GM_setValue('discordCache', this.#cache);
Expand All @@ -280,5 +280,5 @@ class Discord extends Social {
}
}
}
unsafeWindow.Discord = Discord;

export default Discord;
Loading

1 comment on commit ba2dbeb

@vercel
Copy link

@vercel vercel bot commented on ba2dbeb Feb 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.