mirror of
https://github.com/TheNetsky/Microsoft-Rewards-Script.git
synced 2026-01-17 21:43:59 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1d6167aeca | ||
|
|
3b15fe19a7 |
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "microsoft-rewards-script",
|
"name": "microsoft-rewards-script",
|
||||||
"version": "1.2.4",
|
"version": "1.2.5",
|
||||||
"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": {
|
||||||
|
|||||||
@@ -30,6 +30,9 @@ class Browser {
|
|||||||
'--no-sandbox',
|
'--no-sandbox',
|
||||||
'--mute-audio',
|
'--mute-audio',
|
||||||
'--disable-setuid-sandbox',
|
'--disable-setuid-sandbox',
|
||||||
|
'--ignore-certificate-errors',
|
||||||
|
'--ignore-certificate-errors-spki-list',
|
||||||
|
'--ignore-ssl-errors',
|
||||||
proxy.url ? `--proxy-server=${proxy.url}:${proxy.port}` : ''
|
proxy.url ? `--proxy-server=${proxy.url}:${proxy.port}` : ''
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ export default class BrowserFunc {
|
|||||||
await this.bot.browser.utils.tryDismissCookieBanner(page)
|
await this.bot.browser.utils.tryDismissCookieBanner(page)
|
||||||
|
|
||||||
// Check if account is suspended
|
// Check if account is suspended
|
||||||
const isSuspended = await page.waitForSelector('#suspendedAccountHeader', { visible: true, timeout: 3000 }).then(() => true).catch(() => false)
|
const isSuspended = await page.waitForSelector('#suspendedAccountHeader', { visible: true, timeout: 2000 }).then(() => true).catch(() => false)
|
||||||
if (isSuspended) {
|
if (isSuspended) {
|
||||||
this.bot.log('GO-HOME', 'This account is suspended!', 'error')
|
this.bot.log('GO-HOME', 'This account is suspended!', 'error')
|
||||||
throw new Error('Account has been suspended!')
|
throw new Error('Account has been suspended!')
|
||||||
|
|||||||
@@ -52,6 +52,9 @@ export class Workers {
|
|||||||
// Got to punch card index page in a new tab
|
// Got to punch card index page in a new tab
|
||||||
await page.goto(punchCard.parentPromotion.destinationUrl, { referer: this.bot.config.baseURL })
|
await page.goto(punchCard.parentPromotion.destinationUrl, { referer: this.bot.config.baseURL })
|
||||||
|
|
||||||
|
// Wait for new page to load, max 10 seconds, however try regardless in case of error
|
||||||
|
await page.waitForNetworkIdle({ timeout: 10_000 }).catch(() => { })
|
||||||
|
|
||||||
await this.solveActivities(page, activitiesUncompleted, punchCard)
|
await this.solveActivities(page, activitiesUncompleted, punchCard)
|
||||||
|
|
||||||
// Close the punch card index page
|
// Close the punch card index page
|
||||||
@@ -101,7 +104,8 @@ export class Workers {
|
|||||||
|
|
||||||
// Promotion
|
// Promotion
|
||||||
if (activity.priority === 1) {
|
if (activity.priority === 1) {
|
||||||
selector = '#promo-item'
|
selector = await page.waitForSelector('#promo-item', { visible: true, timeout: 2000 }).then(() => true).catch(() => false) ?
|
||||||
|
'#promo-item' : activity.name
|
||||||
} else {
|
} else {
|
||||||
selector = `[data-bi-id="${activity.name}"]`
|
selector = `[data-bi-id="${activity.name}"]`
|
||||||
}
|
}
|
||||||
@@ -113,14 +117,18 @@ export class Workers {
|
|||||||
// Click element, it will be opened in a new tab
|
// Click element, it will be opened in a new tab
|
||||||
await page.click(selector)
|
await page.click(selector)
|
||||||
|
|
||||||
// Cooldown
|
|
||||||
await this.bot.utils.wait(4000)
|
|
||||||
|
|
||||||
// Select the new activity page
|
// Select the new activity page
|
||||||
const activityPage = await this.bot.browser.utils.getLatestTab(page)
|
const activityPage = await this.bot.browser.utils.getLatestTab(page)
|
||||||
|
|
||||||
// Wait for body to load
|
// Wait for the new tab to fully load, ignore error.
|
||||||
await activityPage.waitForSelector('body', { timeout: 10_000 })
|
/*
|
||||||
|
Due to common false timeout on this function, we're ignoring the error regardless, if it worked then it's faster,
|
||||||
|
if it didn't then it gave enough time for the page to load.
|
||||||
|
*/
|
||||||
|
await activityPage.waitForNetworkIdle({ timeout: 10_000 }).catch(() => { })
|
||||||
|
|
||||||
|
// Cooldown
|
||||||
|
await this.bot.utils.wait(4000)
|
||||||
|
|
||||||
switch (activity.promotionType) {
|
switch (activity.promotionType) {
|
||||||
// Quiz (Poll, Quiz or ABC)
|
// Quiz (Poll, Quiz or ABC)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ export class Quiz extends Workers {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Check if the quiz has been started or not
|
// Check if the quiz has been started or not
|
||||||
const quizNotStarted = await page.waitForSelector('#rqStartQuiz', { visible: true, timeout: 3000 }).then(() => true).catch(() => false)
|
const quizNotStarted = await page.waitForSelector('#rqStartQuiz', { visible: true, timeout: 2000 }).then(() => true).catch(() => false)
|
||||||
if (quizNotStarted) {
|
if (quizNotStarted) {
|
||||||
await page.click('#rqStartQuiz')
|
await page.click('#rqStartQuiz')
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -267,14 +267,11 @@ export class Search extends Workers {
|
|||||||
|
|
||||||
await page.click('#b_results .b_algo h2').catch(() => { }) // Since we don't really care if it did it or not
|
await page.click('#b_results .b_algo h2').catch(() => { }) // Since we don't really care if it did it or not
|
||||||
|
|
||||||
// Wait for website to load
|
|
||||||
await this.bot.utils.wait(3000)
|
|
||||||
|
|
||||||
// Will get current tab if no new one is created
|
// Will get current tab if no new one is created
|
||||||
let lastTab = await this.bot.browser.utils.getLatestTab(page)
|
let lastTab = await this.bot.browser.utils.getLatestTab(page)
|
||||||
|
|
||||||
// Wait for the body of the new page to be loaded
|
// Let website load, if it doesn't load within 5 sec. exit regardless
|
||||||
await lastTab.waitForSelector('body', { timeout: 10_000 }).catch(() => { })
|
await lastTab.waitForNetworkIdle({ timeout: 5000 }).catch(() => { })
|
||||||
|
|
||||||
// Check if the tab is closed or not
|
// Check if the tab is closed or not
|
||||||
if (!lastTab.isClosed()) {
|
if (!lastTab.isClosed()) {
|
||||||
@@ -324,7 +321,6 @@ export class Search extends Workers {
|
|||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.bot.log('SEARCH-RANDOM-CLICK', 'An error occurred:' + error, 'error')
|
this.bot.log('SEARCH-RANDOM-CLICK', 'An error occurred:' + error, 'error')
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ export class ThisOrThat extends Workers {
|
|||||||
return
|
return
|
||||||
try {
|
try {
|
||||||
// Check if the quiz has been started or not
|
// Check if the quiz has been started or not
|
||||||
const quizNotStarted = await page.waitForSelector('#rqStartQuiz', { visible: true, timeout: 3000 }).then(() => true).catch(() => false)
|
const quizNotStarted = await page.waitForSelector('#rqStartQuiz', { visible: true, timeout: 2000 }).then(() => true).catch(() => false)
|
||||||
if (quizNotStarted) {
|
if (quizNotStarted) {
|
||||||
await page.click('#rqStartQuiz')
|
await page.click('#rqStartQuiz')
|
||||||
} else {
|
} else {
|
||||||
@@ -24,7 +24,7 @@ export class ThisOrThat extends Workers {
|
|||||||
const quizData = await this.bot.browser.func.getQuizData(page)
|
const quizData = await this.bot.browser.func.getQuizData(page)
|
||||||
quizData // correctAnswer property is always null?
|
quizData // correctAnswer property is always null?
|
||||||
|
|
||||||
this.bot.log('THIS-OR-THAT', 'Completed the ThisOrthat successfully')
|
this.bot.log('THIS-OR-THAT', 'Completed the ThisOrThat successfully')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
await page.close()
|
await page.close()
|
||||||
this.bot.log('THIS-OR-THAT', 'An error occurred:' + error, 'error')
|
this.bot.log('THIS-OR-THAT', 'An error occurred:' + error, 'error')
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Webhook } from './Webhook'
|
import { Webhook } from './Webhook'
|
||||||
|
|
||||||
export function log(title: string, message: string, type?: 'log' | 'warn' | 'error') {
|
export function log(title: string, message: string, type?: 'log' | 'warn' | 'error') {
|
||||||
const currentTime = new Date().toISOString()
|
const currentTime = new Date().toLocaleString()
|
||||||
|
|
||||||
let str = ''
|
let str = ''
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user