mirror of
https://github.com/TheNetsky/Microsoft-Rewards-Script.git
synced 2026-01-11 10:56:17 +00:00
1.4.4
- Fixed login getting stuck - Updated packages - Fixed some errors not throwing
This commit is contained in:
@@ -12,6 +12,7 @@ RUN apt-get update && apt-get install -y jq
|
|||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Check if "headless" is set to "true" in the config.json file
|
# Check if "headless" is set to "true" in the config.json file
|
||||||
|
# DELETE BELOW IF YOU WANT TO RUN THE DOCKER SCRIPT HEADFULL!
|
||||||
RUN HEADLESS=$(cat src/config.json | jq -r .headless) \
|
RUN HEADLESS=$(cat src/config.json | jq -r .headless) \
|
||||||
&& if [ "$HEADLESS" != "true" ]; then \
|
&& if [ "$HEADLESS" != "true" ]; then \
|
||||||
echo "Error: 'headless' in src/config.json is not true."; \
|
echo "Error: 'headless' in src/config.json is not true."; \
|
||||||
|
|||||||
14
package.json
14
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "microsoft-rewards-script",
|
"name": "microsoft-rewards-script",
|
||||||
"version": "1.4.3",
|
"version": "1.4.4",
|
||||||
"description": "Automatically do tasks for Microsoft Rewards but in TS!",
|
"description": "Automatically do tasks for Microsoft Rewards but in TS!",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"engines": {
|
"engines": {
|
||||||
@@ -26,17 +26,17 @@
|
|||||||
"author": "Netsky",
|
"author": "Netsky",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@typescript-eslint/eslint-plugin": "^6.7.0",
|
"@typescript-eslint/eslint-plugin": "^6.20.0",
|
||||||
"eslint": "^8.54.0",
|
"eslint": "^8.56.0",
|
||||||
"eslint-plugin-modules-newline": "^0.0.6",
|
"eslint-plugin-modules-newline": "^0.0.6",
|
||||||
"typescript": "^5.3.3"
|
"typescript": "^5.3.3"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^1.6.5",
|
"axios": "^1.6.7",
|
||||||
"cheerio": "^1.0.0-rc.12",
|
"cheerio": "^1.0.0-rc.12",
|
||||||
"fingerprint-generator": "^2.1.46",
|
"fingerprint-generator": "^2.1.48",
|
||||||
"fingerprint-injector": "^2.1.46",
|
"fingerprint-injector": "^2.1.48",
|
||||||
"playwright": "^1.41.1",
|
"playwright": "^1.41.2",
|
||||||
"ts-node": "^10.9.2"
|
"ts-node": "^10.9.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,13 +95,13 @@ export default class BrowserFunc {
|
|||||||
const scripts = Array.from(document.querySelectorAll('script'))
|
const scripts = Array.from(document.querySelectorAll('script'))
|
||||||
const targetScript = scripts.find(script => script.innerText.includes('var dashboard'))
|
const targetScript = scripts.find(script => script.innerText.includes('var dashboard'))
|
||||||
|
|
||||||
if (targetScript) {
|
return targetScript?.innerText ? targetScript.innerText : null
|
||||||
return targetScript.innerText
|
|
||||||
} else {
|
|
||||||
throw this.bot.log('GET-DASHBOARD-DATA', 'Script containing dashboard data not found', 'error')
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (!scriptContent) {
|
||||||
|
throw this.bot.log('GET-DASHBOARD-DATA', 'Dashboard data not found within script', 'error')
|
||||||
|
}
|
||||||
|
|
||||||
// Extract the dashboard object from the script content
|
// Extract the dashboard object from the script content
|
||||||
const dashboardData = await this.bot.homePage.evaluate(scriptContent => {
|
const dashboardData = await this.bot.homePage.evaluate(scriptContent => {
|
||||||
// Extract the dashboard object using regex
|
// Extract the dashboard object using regex
|
||||||
@@ -110,11 +110,13 @@ export default class BrowserFunc {
|
|||||||
|
|
||||||
if (match && match[1]) {
|
if (match && match[1]) {
|
||||||
return JSON.parse(match[1])
|
return JSON.parse(match[1])
|
||||||
} else {
|
|
||||||
throw this.bot.log('GET-DASHBOARD-DATA', 'Dashboard data not found within script', 'error')
|
|
||||||
}
|
}
|
||||||
}, scriptContent)
|
}, scriptContent)
|
||||||
|
|
||||||
|
if (!dashboardData) {
|
||||||
|
throw this.bot.log('GET-DASHBOARD-DATA', 'Unable to parse dashboard script', 'error')
|
||||||
|
}
|
||||||
|
|
||||||
return dashboardData
|
return dashboardData
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ export default class BrowserUtil {
|
|||||||
|
|
||||||
async tryDismissAllMessages(page: Page): Promise<boolean> {
|
async tryDismissAllMessages(page: Page): Promise<boolean> {
|
||||||
const buttons = [
|
const buttons = [
|
||||||
|
{ selector: '#acceptButton', label: 'AcceptButton' },
|
||||||
{ selector: '#iLandingViewAction', label: 'iLandingViewAction' },
|
{ selector: '#iLandingViewAction', label: 'iLandingViewAction' },
|
||||||
{ selector: '#iShowSkip', label: 'iShowSkip' },
|
{ selector: '#iShowSkip', label: 'iShowSkip' },
|
||||||
{ selector: '#iNext', label: 'iNext' },
|
{ selector: '#iNext', label: 'iNext' },
|
||||||
|
|||||||
@@ -53,35 +53,41 @@ export class Login {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async execLogin(page: Page, email: string, password: string) {
|
private async execLogin(page: Page, email: string, password: string) {
|
||||||
await page.type('#i0116', email)
|
|
||||||
await page.click('#idSIButton9')
|
|
||||||
|
|
||||||
this.bot.log('LOGIN', 'Email entered successfully')
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await page.waitForSelector('#i0118', { state: 'visible', timeout: 2000 })
|
// Enter email
|
||||||
await this.bot.utils.wait(2000)
|
await page.fill('#i0116', email)
|
||||||
|
|
||||||
await page.type('#i0118', password)
|
|
||||||
await page.click('#idSIButton9')
|
await page.click('#idSIButton9')
|
||||||
|
|
||||||
// When erroring at this stage it means a 2FA code is required
|
this.bot.log('LOGIN', 'Email entered successfully')
|
||||||
} catch (error) {
|
|
||||||
this.bot.log('LOGIN', '2FA code required')
|
|
||||||
|
|
||||||
// Wait for user input
|
try {
|
||||||
const code = await new Promise<string>((resolve) => {
|
// Enter password
|
||||||
rl.question('Enter 2FA code:\n', (input) => {
|
await page.waitForSelector('#i0118', { state: 'visible', timeout: 2000 })
|
||||||
rl.close()
|
await this.bot.utils.wait(2000)
|
||||||
resolve(input)
|
|
||||||
|
await page.fill('#i0118', password)
|
||||||
|
await page.click('#idSIButton9')
|
||||||
|
|
||||||
|
// When erroring at this stage it means a 2FA code is required
|
||||||
|
} catch (error) {
|
||||||
|
this.bot.log('LOGIN', '2FA code required')
|
||||||
|
|
||||||
|
// Wait for user input
|
||||||
|
const code = await new Promise<string>((resolve) => {
|
||||||
|
rl.question('Enter 2FA code:\n', (input) => {
|
||||||
|
rl.close()
|
||||||
|
resolve(input)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
|
||||||
await page.type('input[name="otc"]', code)
|
await page.fill('input[name="otc"]', code)
|
||||||
await page.keyboard.press('Enter')
|
await page.keyboard.press('Enter')
|
||||||
|
}
|
||||||
|
|
||||||
} finally {
|
|
||||||
this.bot.log('LOGIN', 'Password entered successfully')
|
this.bot.log('LOGIN', 'Password entered successfully')
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
this.bot.log('LOGIN', 'An error occurred:' + error, 'error')
|
||||||
}
|
}
|
||||||
|
|
||||||
const currentURL = new URL(page.url())
|
const currentURL = new URL(page.url())
|
||||||
|
|||||||
Reference in New Issue
Block a user