Skip to content

Commit

Permalink
修复:Tampermonkey更新导致Steam凭证刷新失败(#16);
Browse files Browse the repository at this point in the history
修复:推特转推功能失效
  • Loading branch information
HCLonely committed Jun 15, 2024
2 parents b783152 + 346de4a commit 9de604b
Show file tree
Hide file tree
Showing 38 changed files with 1,723 additions and 493 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/Release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ jobs:
prerelease: false
tag_name: v4.4.2
name: 4.4.2
body: '- 修复:Tampermonkey更新导致Steam凭证刷新失败(#16)'
body: |-
- 修复:Tampermonkey更新导致Steam凭证刷新失败(#16)
- 修复:推特转推功能失效
files: |-
dist/auto-task-v4-for-giveawaysu.user.js
dist/auto-task-v4.compatibility.user.js
Expand Down
6 changes: 3 additions & 3 deletions dist/auto-task-v4-for-giveawaysu.all.user.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/auto-task-v4-for-giveawaysu.user.js

Large diffs are not rendered by default.

467 changes: 369 additions & 98 deletions dist/auto-task-v4.all.user.js

Large diffs are not rendered by default.

17 changes: 10 additions & 7 deletions dist/auto-task-v4.compatibility.all.user.js

Large diffs are not rendered by default.

17 changes: 10 additions & 7 deletions dist/auto-task-v4.compatibility.user.js

Large diffs are not rendered by default.

467 changes: 369 additions & 98 deletions dist/auto-task-v4.user.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion doc/docs/en/guide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The content of this page is translated through Google translation. If the descri

## READ ME FIRST

1. This script supports [Tampermonkey](https://www.tampermonkey.net/) and [Violentmonkey](https://violentmonkey.github.io/) extensions, not other extensions specifically;
1. This script supports [Tampermonkey](https://www.tampermonkey.net/) >= 5.2.0 ~~and [Violentmonkey](https://violentmonkey.github.io/)~~ extensions, not other extensions specifically;
2. Reddit related functions need to use the beta version of reddit website to use, if the script fails to switch automatically, please switch by yourself;
3. When verifying Twitter and Youtube token, it will automatically follow the official account. If you don’t want to follow the official account, you can go to [Settings Page](https://auto-task-v4.hclonely.com/setting.html)->`Global Settings`->`Others` to change;
4. The functions of `Like community announcement` and `Like workshop item` do not support cancellation, and the `Opquests` website does not support cancellation tasks;
Expand Down
2 changes: 1 addition & 1 deletion doc/docs/guide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ lang: zh-CN

## 用前必读

1. 此脚本支持[Tampermonkey](https://www.tampermonkey.net/)[Violentmonkey](https://violentmonkey.github.io/)扩展,不会专门去兼容其他扩展;
1. 此脚本支持[Tampermonkey](https://www.tampermonkey.net/) >= 5.2.0 ~~[Violentmonkey](https://violentmonkey.github.io/)~~ 扩展,不会专门去兼容其他扩展;
2. reddit功能需要使用reddit的beta版网站才能使用,如果脚本自动切换失败,请自行切换;
3. 验证 Twitter 和 Youtube 凭证时会自动关注官方账号,如果不想关注官方账号,可在[设置页面](https://auto-task-v4.hclonely.com/setting.html)->`全局设置`->`其他`中更换;
4. `点赞社区公告``点赞创意工坊物品`功能不支持撤销,`Opquests`网站不支持撤销任务;
Expand Down
14 changes: 14 additions & 0 deletions doc/docs/logs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ lang: zh-CN

- 修复:Steam凭证刷新失败([#16](https://github.com/HCLonely/auto-task-v4/issues/16))

### V4.4.1

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

- 重要:4.4.0以后版本*需TamperMonkey >= 5.2.0或TamperMonkey >= 5.2.6196)
- 重要:暂时取消对Violentmonkey的支持

### V4.4.0

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

- 修复:Twitter/X域名更改导致部分功能不可用([#18](https://github.com/HCLonely/auto-task-v4/issues/18))
- 优化:Twitter/X凭证获取方式(需TamperMonkey >= 5.2.0或TamperMonkey >= 5.2.6196)

## V4.3

### V4.3.3
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"name": "auto-task-v4",
"version": "4.4.2",
"change": [
"修复:Tampermonkey更新导致Steam凭证刷新失败(#16)"
"修复:Tampermonkey更新导致Steam凭证刷新失败(#16)",
"修复:推特转推功能失效"
],
"description": "赠Key站自动任务脚本",
"main": "package.json",
Expand Down
6 changes: 3 additions & 3 deletions page/dist/auto-task-v4-for-giveawaysu.all.user.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions page/dist/auto-task-v4-for-giveawaysu.user.js

Large diffs are not rendered by default.

467 changes: 369 additions & 98 deletions page/dist/auto-task-v4.all.user.js

Large diffs are not rendered by default.

17 changes: 10 additions & 7 deletions page/dist/auto-task-v4.compatibility.all.user.js

Large diffs are not rendered by default.

17 changes: 10 additions & 7 deletions page/dist/auto-task-v4.compatibility.user.js

Large diffs are not rendered by default.

467 changes: 369 additions & 98 deletions page/dist/auto-task-v4.user.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion page/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"name": "auto-task-v4",
"version": "4.4.2",
"change": [
"修复:Tampermonkey更新导致Steam凭证刷新失败(#16)"
"修复:Tampermonkey更新导致Steam凭证刷新失败(#16)",
"修复:推特转推功能失效"
],
"description": "赠Key站自动任务脚本",
"main": "package.json",
Expand Down
2 changes: 1 addition & 1 deletion src/for_giveawaysu/Giveawaysu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ class GiveawaySu {
const hasDiscord = Object.values(tasks.discord).reduce((total, arr) => [...total, ...arr]).length > 0;
if (hasDiscord && !this.socialInitialized.discord) {
this.social.discord = new Discord();
pro.push(this.#bind('discord', this.social.discord.init()));
pro.push(this.#bind('discord', this.social.discord.init('do')));
}
}
if (tasks.instagram) {
Expand Down
2 changes: 1 addition & 1 deletion src/for_giveawaysu/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const loadScript = async () => {
Swal.fire('', __('needLogin'));
}
}
if (window.location.hostname === 'twitter.com' && window.location.hash === '#auth') {
if (window.location.hostname === 'x.com' && window.location.hash === '#auth') {
const ct0 = Cookies.get('ct0');
const isLogin = !!Cookies.get('twid');
if (isLogin && ct0) {
Expand Down
26 changes: 26 additions & 0 deletions src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,32 @@ declare global {
onclose: () => void
closed: boolean
}
const GM_cookie: {
list(details: {
url?: string
domain?: string
name?: string
path?: string
partitionKey?: {
topLevelSite?: string
}
}, callback?: (cookies: Array<{
domain: string
firstPartyDomain?: string
partitionKey?: {
topLevelSite?: string
}
hostOnly: boolean
httpOnly: boolean
name: string
path: string
sameSite: string
secure: boolean
session: boolean
value: string
}>, error: string | null) => void): void
};

/* eslint-enable camelcase */
function sha1(value: string): string

Expand Down
3 changes: 3 additions & 0 deletions src/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
// @include *://www.youtube.com/*
// @include *://*.reddit.com/*
// @include *://twitter.com/settings/account?k*
// @include *://x.com/settings/account*
// @include https://auto-task-v4.hclonely.com/setting.html
// @include https://auto-task-v4.hclonely.com/history.html

Expand All @@ -45,6 +46,7 @@
// @grant GM_openInTab
// @grant GM_setClipboard
// @grant GM_getResourceText
// @grant GM_cookie
// @grant unsafeWindow
// @grant window.close
// @grant window.localStorage
Expand All @@ -54,6 +56,7 @@
// @connect steamcommunity.com
// @connect login.steampowered.com
// @connect twitter.com
// @connect x.com
// @connect api.twitter.com
// @connect youtube.com
// @connect www.youtube.com
Expand Down
9 changes: 8 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ const loadScript = async () => {
}
return;
}
if (window.location.hostname === 'twitter.com' && window.location.hash === '#auth') {
/*
if (window.location.hostname === 'x.com' && window.location.hash === '#auth') {
const ct0 = Cookies.get('ct0');
const isLogin = !!Cookies.get('twid');
if (isLogin && ct0) {
Expand All @@ -75,6 +76,7 @@ const loadScript = async () => {
}
return;
}
*/
if (window.location.hostname === 'www.reddit.com' &&
(window.location.hash === '#auth' || GM_getValue('redditAuth') === '#auth')) {
const betaButton = $('#redesign-beta-optin-btn');
Expand Down Expand Up @@ -192,6 +194,11 @@ const loadScript = async () => {

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

// INFO: 版本检测
const [v1, v2] = GM_info.version.split('.');
if (!(parseInt(v1, 10) >= 5 && parseInt(v2, 10) >= 2)) {
echoLog({}).error(__('versionNotMatched'));
}
if (!GM_getValue<number>('notice')) {
Swal.fire({
title: __('swalNotice'),
Expand Down
3 changes: 3 additions & 0 deletions src/locales/en-US.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ const data = {
requestingPlayTestAccess: 'Requesting play test access',
tryChangeAreaNotice: 'This function cannot detect whether the game is limited, so it will try to change the area before entering the library' +
'. Failure to change the area will not affect the subsequent storage.',
versionNotMatched: 'The script manager version is too low, requiring TamperMonkey >= 5.2.0 or TamperMonkey Beta >= 5.2.6196',
gettingUserLink: 'Getting steam user community link...',
retry: 'Retry',

// Steam ASF
initingASF: 'Initing ASF...',
Expand Down
3 changes: 3 additions & 0 deletions src/locales/zh-CN.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ const data = {
AsfEnabled: '使用ASF做Steam相关任务(需<a href="https://github.com/chr233/ASFEnhance" target="_blank">ASFEnhance</a>插件)',
AsfIpcUrl: 'ASF IPC 地址',
AsfIpcPassword: 'ASF IPC 密码',
versionNotMatched: '脚本管理器版本过低,需TamperMonkey >= 5.2.0或TamperMonkey Beta >= 5.2.6196',

// Steam
groups: '组',
Expand Down Expand Up @@ -214,6 +215,8 @@ const data = {
gettingLicenses: '正在获取Licenses...',
requestingPlayTestAccess: '正在请求访问权限',
tryChangeAreaNotice: '此功能无法检测游戏是否限区,因此会尝试换区后再入库,换区失败也不影响后续入库',
gettingUserLink: '正在获取Steam用户社区链接...',
retry: '重试',

// Steam ASF
initingASF: '正在初始化ASF...',
Expand Down
7 changes: 4 additions & 3 deletions src/scripts/dataSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ const syncOptions = (): void => {
GIST_ID,
FILE_NAME,
SYNC_HISTORY
} = GM_getValue('gistOptions') || { TOKEN: '', GIST_ID: '', FILE_NAME: '', SYNC_HISTORY: true };
} = GM_getValue<{ TOKEN: string; GIST_ID: string; FILE_NAME: string; SYNC_HISTORY: boolean; }>('gistOptions') ||
{ TOKEN: '', GIST_ID: '', FILE_NAME: '', SYNC_HISTORY: true };

Swal.fire({
title: __('gistOptions'),
Expand Down Expand Up @@ -147,7 +148,7 @@ const syncOptions = (): void => {
}
});
$('#upload-data').on('click', async () => {
const { TOKEN, GIST_ID, FILE_NAME } = GM_getValue('gistOptions') || {};
const { TOKEN, GIST_ID, FILE_NAME } = GM_getValue<{ TOKEN: string, GIST_ID: string, FILE_NAME: string }>('gistOptions') || {};
if (!(TOKEN && GIST_ID && FILE_NAME)) {
return Swal.fire({
icon: 'error',
Expand Down Expand Up @@ -183,7 +184,7 @@ const syncOptions = (): void => {
}
});
$('#download-data').on('click', async () => {
const { TOKEN, GIST_ID, FILE_NAME } = GM_getValue('gistOptions') || {};
const { TOKEN, GIST_ID, FILE_NAME } = GM_getValue<{ TOKEN: string, GIST_ID: string, FILE_NAME: string }>('gistOptions') || {};
if (!(TOKEN && GIST_ID && FILE_NAME)) {
return Swal.fire({
icon: 'error',
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/echoLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const echoLog = ({ type, text, html, id }: { type?: string, text?: string, html?
case 'gettingTwitterUserId':
case 'followingTwitterUser':
case 'unfollowingTwitterUser':
ele = $(`<li>${__(type)}[<a href="https://twitter.com/${text}" target="_blank">${text}</a>]...<font></font></li>`);
ele = $(`<li>${__(type)}[<a href="https://x.com/${text}" target="_blank">${text}</a>]...<font></font></li>`);
break;
case 'retweetting':
case 'unretweetting':
Expand Down
6 changes: 4 additions & 2 deletions src/scripts/social/Discord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Discord extends Social {
this.tasks = defaultTasksTemplate;
this.whiteList = { ...defaultTasksTemplate, ...(GM_getValue<whiteList>('whiteList')?.discord || {}) };
}
async init(): Promise<boolean | 'skip'> {
async init(action: string): Promise<boolean | 'skip'> {
/**
* @description: 验证及获取Auth
* @return true: 初始化完成 | false: 初始化失败,toggle方法不可用
Expand Down Expand Up @@ -61,7 +61,9 @@ class Discord extends Social {
return 'skip';
}
}
if (!globalOptions.doTask.discord.servers && !globalOptions.undoTask.discord.servers) {
if (GM_getValue('dontRemindDiscordAgain') ||
(action === 'do' && !globalOptions.doTask.discord.servers) ||
(action === 'undo' && !globalOptions.undoTask.discord.servers)) {
this.#initialized = false;
return 'skip';
}
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/social/Social.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface toggleParams {
abstract class Social {
tasks!: socialTasks;

abstract init(): Promise<boolean | 'skip'>
abstract init(options?: any): Promise<boolean | 'skip'>
abstract toggle(toggleParams: toggleParams): Promise<boolean>

protected getRealParams(
Expand Down
67 changes: 50 additions & 17 deletions src/scripts/social/Steam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class Steam extends Social {
if (this.#communityInitialized) {
return true;
}
this.#communityInitialized = await this.#updateCommunityAuth();
this.#communityInitialized = await this.#getUserLink();
if (!this.#communityInitialized) {
echoLog({}).error(__('initFailed', 'Steam'));
return false;
Expand All @@ -95,7 +95,7 @@ class Steam extends Social {
}

this.#storeInitialized = await this.#updateStoreAuth();
this.#communityInitialized = await this.#updateCommunityAuth();
this.#communityInitialized = await this.#getUserLink();
if (this.#storeInitialized && this.#communityInitialized) {
echoLog({}).success(__('initSuccess', 'Steam'));
return true;
Expand Down Expand Up @@ -242,7 +242,7 @@ class Steam extends Social {
logStatus.error(`Error:${data?.statusText}(${data?.status})`);
return false;
}
if (data?.status === 302) {
if ([301, 302].includes(data?.status as number)) {
if (await this.#refreshToken('steamStore')) {
logStatus.warning(__('retry'));
if (retry) {
Expand All @@ -262,14 +262,14 @@ class Steam extends Social {
}
}

async #updateCommunityAuth(retry = false): Promise<boolean> {
async #getUserLink(retry = false): Promise<boolean> {
/**
* @internal
* @description 更新Steam社区Token.
* @return true: 更新Token成功 | false: 更新Token失败
*/
try {
const logStatus = echoLog({ text: __('updatingAuth', __('steamCommunity')) });
const logStatus = echoLog({ text: __('gettingUserLink') });
const { result, statusText, status, data } = await httpRequest({
url: 'https://steamcommunity.com/my',
method: 'GET',
Expand All @@ -283,6 +283,51 @@ class Steam extends Social {
fetch: false,
redirect: 'manual'
});
if (data?.status === 302) {
if (await this.#refreshToken('steamCommunity')) {
if (retry) {
logStatus.error(`Error:${__('needLoginSteamCommunity')}`, true);
return false;
}
logStatus.warning(__('retry'));
return this.#getUserLink(true);
}
logStatus.error(`Error:${__('needLoginSteamCommunity')}`, true);
return false;
}
const location = data?.responseHeaders?.split('\n')
?.find((header: string) => (header.includes('location') ? header.replace('loctation:', '').trim() : null));
if (data?.status === 301 && location?.includes('steamcommunity.com/id')) {
logStatus.success();
return await this.#updateCommunityAuth(data.finalUrl);
}
logStatus.error(`${result}:${statusText}(${status})`);
return false;
} catch (error) {
throwError(error as Error, 'Steam.updateCommunityAuth');
return false;
}
}

async #updateCommunityAuth(url: string): Promise<boolean> {
/**
* @internal
* @description 更新Steam社区Token.
* @return true: 更新Token成功 | false: 更新Token失败
*/
try {
const logStatus = echoLog({ text: __('updatingAuth', __('steamCommunity')) });
const { result, statusText, status, data } = await httpRequest({
url,
method: 'GET',
headers: {
Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'Cache-Control': 'max-age=0',
'Sec-Fetch-Dest': 'document',
'Sec-Fetch-Mode': 'navigate',
'Upgrade-Insecure-Requests': '1'
}
});
if (result === 'Success') {
if (data?.status === 200) {
if (data.finalUrl.includes('https://steamcommunity.com/login/home')) {
Expand All @@ -305,18 +350,6 @@ class Steam extends Social {
logStatus.error(`Error:${data?.statusText}(${data?.status})`);
return false;
}
if (data?.status === 302) {
if (await this.#refreshToken('steamCommunity')) {
logStatus.warning(__('retry'));
if (retry) {
logStatus.error(`Error:${__('needLoginSteamCommunity')}`, true);
return false;
}
return this.#updateCommunityAuth(true);
}
logStatus.error(`Error:${__('needLoginSteamCommunity')}`, true);
return false;
}
logStatus.error(`${result}:${statusText}(${status})`);
return false;
} catch (error) {
Expand Down
Loading

0 comments on commit 9de604b

Please sign in to comment.