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
1 parent 584da46 commit b783152
Show file tree
Hide file tree
Showing 18 changed files with 338 additions and 118 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/Release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ jobs:
uses: softprops/action-gh-release@v1
with:
prerelease: false
tag_name: v4.3.3
name: 4.3.3
body: '- 移除:Opquests验证任务功能(#17)'
tag_name: v4.4.2
name: 4.4.2
body: '- 修复:Tampermonkey更新导致Steam凭证刷新失败(#16)'
files: |-
dist/auto-task-v4-for-giveawaysu.user.js
dist/auto-task-v4.compatibility.user.js
Expand Down
4 changes: 2 additions & 2 deletions dist/auto-task-v4-for-giveawaysu.all.user.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

80 changes: 61 additions & 19 deletions dist/auto-task-v4.all.user.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ==UserScript==
// @name auto-task-v4
// @namespace auto-task-v4
// @version 4.3.3
// @version 4.4.2
// @description 自动完成 Freeanywhere,Giveawaysu,GiveeClub,Givekey,Gleam,Indiedb,keyhub,OpiumPulses,Opquests,SweepWidget 等网站的任务。
// @description:en Automatically complete the tasks of FreeAnyWhere, GiveawaySu, GiveeClub, Givekey, Gleam, Indiedb, keyhub, OpiumPulses, Opquests, SweepWidget websites.
// @author HCLonely
Expand Down Expand Up @@ -4589,13 +4589,17 @@ console.log('%c%s', 'color:blue', 'Auto-Task[Load]: 脚本开始加载');
return false;
}
}
async #refreshStoreToken() {
async #refreshToken(type = 'steamStore') {
try {
const host = {
steamStore: 'store.steampowered.com',
steamCommunity: 'steamcommunity.com'
};
const logStatus = scripts_echoLog({
text: i18n('refreshingToken', i18n('steamStore'))
text: i18n('refreshingToken', i18n(type))
});
const formData = new FormData();
formData.append('redir', 'https://store.steampowered.com/');
formData.append('redir', `https://${host[type]}/`);
const {
result,
statusText,
Expand All @@ -4607,14 +4611,14 @@ console.log('%c%s', 'color:blue', 'Auto-Task[Load]: 脚本开始加载');
responseType: 'json',
headers: {
Host: 'login.steampowered.com',
Origin: 'https://store.steampowered.com',
Referer: 'https://store.steampowered.com/'
Origin: `https://${host[type]}`,
Referer: `https://${host[type]}/`
},
data: formData
});
if (result === 'Success') {
if (data?.response?.success) {
if (await this.#setStoreToken(data.response)) {
if (await this.#setStoreToken(data.response, type)) {
logStatus.success();
return true;
}
Expand All @@ -4627,14 +4631,18 @@ console.log('%c%s', 'color:blue', 'Auto-Task[Load]: 脚本开始加载');
logStatus.error(`${result}:${statusText}(${status})`);
return false;
} catch (error) {
throwError(error, 'Steam.refreshStoreToken');
throwError(error, 'Steam.refreshToken');
return false;
}
}
async #setStoreToken(param) {
async #setStoreToken(param, type) {
try {
const host = {
steamStore: 'store.steampowered.com',
steamCommunity: 'steamcommunity.com'
};
const logStatus = scripts_echoLog({
text: i18n('settingToken', i18n('steamStore'))
text: i18n('settingToken', i18n(type))
});
const formData = new FormData();
formData.append('steamID', param.steamID);
Expand All @@ -4647,13 +4655,12 @@ console.log('%c%s', 'color:blue', 'Auto-Task[Load]: 脚本开始加载');
status,
data
} = await tools_httpRequest({
url: 'https://store.steampowered.com/login/settoken',
url: `https://${host[type]}/login/settoken`,
method: 'POST',
headers: {
Accept: 'application/json, text/plain, */*',
Host: 'store.steampowered.com',
Origin: 'https://store.steampowered.com',
Referer: 'https://store.steampowered.com/login'
Host: host[type],
Origin: `https://${host[type]}`
},
data: formData
});
Expand All @@ -4672,7 +4679,7 @@ console.log('%c%s', 'color:blue', 'Auto-Task[Load]: 脚本开始加载');
return false;
}
}
async #updateStoreAuth() {
async #updateStoreAuth(retry = false) {
try {
const logStatus = scripts_echoLog({
text: i18n('updatingAuth', i18n('steamStore'))
Expand All @@ -4691,12 +4698,21 @@ console.log('%c%s', 'color:blue', 'Auto-Task[Load]: 脚本开始加载');
'Sec-Fetch-Dest': 'document',
'Sec-Fetch-Mode': 'navigate',
'Upgrade-Insecure-Requests': '1'
}
},
fetch: false,
redirect: 'manual'
});
if (result === 'Success') {
if (data?.status === 200) {
if (!data.responseText.includes('data-miniprofile=')) {
await this.#refreshStoreToken();
if (await this.#refreshToken('steamStore')) {
logStatus.warning(i18n('retry'));
if (retry) {
logStatus.error(`Error:${i18n('needLoginSteamStore')}`, true);
return false;
}
return this.#updateStoreAuth(true);
}
logStatus.error(`Error:${i18n('needLoginSteamStore')}`, true);
return false;
}
Expand All @@ -4712,14 +4728,26 @@ console.log('%c%s', 'color:blue', 'Auto-Task[Load]: 脚本开始加载');
logStatus.error(`Error:${data?.statusText}(${data?.status})`);
return false;
}
if (data?.status === 302) {
if (await this.#refreshToken('steamStore')) {
logStatus.warning(i18n('retry'));
if (retry) {
logStatus.error(`Error:${i18n('needLoginSteamStore')}`, true);
return false;
}
return this.#updateStoreAuth(true);
}
logStatus.error(`Error:${i18n('needLoginSteamStore')}`, true);
return false;
}
logStatus.error(`${result}:${statusText}(${status})`);
return false;
} catch (error) {
throwError(error, 'Steam.updateStoreAuth');
return false;
}
}
async #updateCommunityAuth() {
async #updateCommunityAuth(retry = false) {
try {
const logStatus = scripts_echoLog({
text: i18n('updatingAuth', i18n('steamCommunity'))
Expand All @@ -4738,7 +4766,9 @@ console.log('%c%s', 'color:blue', 'Auto-Task[Load]: 脚本开始加载');
'Sec-Fetch-Dest': 'document',
'Sec-Fetch-Mode': 'navigate',
'Upgrade-Insecure-Requests': '1'
}
},
fetch: false,
redirect: 'manual'
});
if (result === 'Success') {
if (data?.status === 200) {
Expand Down Expand Up @@ -4766,6 +4796,18 @@ console.log('%c%s', 'color:blue', 'Auto-Task[Load]: 脚本开始加载');
logStatus.error(`Error:${data?.statusText}(${data?.status})`);
return false;
}
if (data?.status === 302) {
if (await this.#refreshToken('steamCommunity')) {
logStatus.warning(i18n('retry'));
if (retry) {
logStatus.error(`Error:${i18n('needLoginSteamCommunity')}`, true);
return false;
}
return this.#updateCommunityAuth(true);
}
logStatus.error(`Error:${i18n('needLoginSteamCommunity')}`, true);
return false;
}
logStatus.error(`${result}:${statusText}(${status})`);
return false;
} catch (error) {
Expand Down
4 changes: 2 additions & 2 deletions dist/auto-task-v4.compatibility.all.user.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/auto-task-v4.compatibility.user.js

Large diffs are not rendered by default.

80 changes: 61 additions & 19 deletions dist/auto-task-v4.user.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ==UserScript==
// @name auto-task-v4
// @namespace auto-task-v4
// @version 4.3.3
// @version 4.4.2
// @description 自动完成 Freeanywhere,Giveawaysu,GiveeClub,Givekey,Gleam,Indiedb,keyhub,OpiumPulses,Opquests,SweepWidget 等网站的任务。
// @description:en Automatically complete the tasks of FreeAnyWhere, GiveawaySu, GiveeClub, Givekey, Gleam, Indiedb, keyhub, OpiumPulses, Opquests, SweepWidget websites.
// @author HCLonely
Expand Down Expand Up @@ -4570,13 +4570,17 @@ console.log('%c%s', 'color:blue', 'Auto-Task[Load]: 脚本开始加载');
return false;
}
}
async #refreshStoreToken() {
async #refreshToken(type = 'steamStore') {
try {
const host = {
steamStore: 'store.steampowered.com',
steamCommunity: 'steamcommunity.com'
};
const logStatus = scripts_echoLog({
text: i18n('refreshingToken', i18n('steamStore'))
text: i18n('refreshingToken', i18n(type))
});
const formData = new FormData();
formData.append('redir', 'https://store.steampowered.com/');
formData.append('redir', `https://${host[type]}/`);
const {
result,
statusText,
Expand All @@ -4588,14 +4592,14 @@ console.log('%c%s', 'color:blue', 'Auto-Task[Load]: 脚本开始加载');
responseType: 'json',
headers: {
Host: 'login.steampowered.com',
Origin: 'https://store.steampowered.com',
Referer: 'https://store.steampowered.com/'
Origin: `https://${host[type]}`,
Referer: `https://${host[type]}/`
},
data: formData
});
if (result === 'Success') {
if (data?.response?.success) {
if (await this.#setStoreToken(data.response)) {
if (await this.#setStoreToken(data.response, type)) {
logStatus.success();
return true;
}
Expand All @@ -4608,14 +4612,18 @@ console.log('%c%s', 'color:blue', 'Auto-Task[Load]: 脚本开始加载');
logStatus.error(`${result}:${statusText}(${status})`);
return false;
} catch (error) {
throwError(error, 'Steam.refreshStoreToken');
throwError(error, 'Steam.refreshToken');
return false;
}
}
async #setStoreToken(param) {
async #setStoreToken(param, type) {
try {
const host = {
steamStore: 'store.steampowered.com',
steamCommunity: 'steamcommunity.com'
};
const logStatus = scripts_echoLog({
text: i18n('settingToken', i18n('steamStore'))
text: i18n('settingToken', i18n(type))
});
const formData = new FormData();
formData.append('steamID', param.steamID);
Expand All @@ -4628,13 +4636,12 @@ console.log('%c%s', 'color:blue', 'Auto-Task[Load]: 脚本开始加载');
status,
data
} = await tools_httpRequest({
url: 'https://store.steampowered.com/login/settoken',
url: `https://${host[type]}/login/settoken`,
method: 'POST',
headers: {
Accept: 'application/json, text/plain, */*',
Host: 'store.steampowered.com',
Origin: 'https://store.steampowered.com',
Referer: 'https://store.steampowered.com/login'
Host: host[type],
Origin: `https://${host[type]}`
},
data: formData
});
Expand All @@ -4653,7 +4660,7 @@ console.log('%c%s', 'color:blue', 'Auto-Task[Load]: 脚本开始加载');
return false;
}
}
async #updateStoreAuth() {
async #updateStoreAuth(retry = false) {
try {
const logStatus = scripts_echoLog({
text: i18n('updatingAuth', i18n('steamStore'))
Expand All @@ -4672,12 +4679,21 @@ console.log('%c%s', 'color:blue', 'Auto-Task[Load]: 脚本开始加载');
'Sec-Fetch-Dest': 'document',
'Sec-Fetch-Mode': 'navigate',
'Upgrade-Insecure-Requests': '1'
}
},
fetch: false,
redirect: 'manual'
});
if (result === 'Success') {
if (data?.status === 200) {
if (!data.responseText.includes('data-miniprofile=')) {
await this.#refreshStoreToken();
if (await this.#refreshToken('steamStore')) {
logStatus.warning(i18n('retry'));
if (retry) {
logStatus.error(`Error:${i18n('needLoginSteamStore')}`, true);
return false;
}
return this.#updateStoreAuth(true);
}
logStatus.error(`Error:${i18n('needLoginSteamStore')}`, true);
return false;
}
Expand All @@ -4693,14 +4709,26 @@ console.log('%c%s', 'color:blue', 'Auto-Task[Load]: 脚本开始加载');
logStatus.error(`Error:${data?.statusText}(${data?.status})`);
return false;
}
if (data?.status === 302) {
if (await this.#refreshToken('steamStore')) {
logStatus.warning(i18n('retry'));
if (retry) {
logStatus.error(`Error:${i18n('needLoginSteamStore')}`, true);
return false;
}
return this.#updateStoreAuth(true);
}
logStatus.error(`Error:${i18n('needLoginSteamStore')}`, true);
return false;
}
logStatus.error(`${result}:${statusText}(${status})`);
return false;
} catch (error) {
throwError(error, 'Steam.updateStoreAuth');
return false;
}
}
async #updateCommunityAuth() {
async #updateCommunityAuth(retry = false) {
try {
const logStatus = scripts_echoLog({
text: i18n('updatingAuth', i18n('steamCommunity'))
Expand All @@ -4719,7 +4747,9 @@ console.log('%c%s', 'color:blue', 'Auto-Task[Load]: 脚本开始加载');
'Sec-Fetch-Dest': 'document',
'Sec-Fetch-Mode': 'navigate',
'Upgrade-Insecure-Requests': '1'
}
},
fetch: false,
redirect: 'manual'
});
if (result === 'Success') {
if (data?.status === 200) {
Expand Down Expand Up @@ -4747,6 +4777,18 @@ console.log('%c%s', 'color:blue', 'Auto-Task[Load]: 脚本开始加载');
logStatus.error(`Error:${data?.statusText}(${data?.status})`);
return false;
}
if (data?.status === 302) {
if (await this.#refreshToken('steamCommunity')) {
logStatus.warning(i18n('retry'));
if (retry) {
logStatus.error(`Error:${i18n('needLoginSteamCommunity')}`, true);
return false;
}
return this.#updateCommunityAuth(true);
}
logStatus.error(`Error:${i18n('needLoginSteamCommunity')}`, true);
return false;
}
logStatus.error(`${result}:${statusText}(${status})`);
return false;
} catch (error) {
Expand Down
8 changes: 8 additions & 0 deletions doc/docs/logs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ title: 更新日志
lang: zh-CN
---

## V4.4

### V4.4.2

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

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

## V4.3

### V4.3.3
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "auto-task-v4",
"version": "4.3.3",
"version": "4.4.2",
"change": [
"移除:Opquests验证任务功能(#17)"
"修复:Tampermonkey更新导致Steam凭证刷新失败(#16)"
],
"description": "赠Key站自动任务脚本",
"main": "package.json",
Expand Down
Loading

0 comments on commit b783152

Please sign in to comment.