mirror of
https://github.com/TheNetsky/Microsoft-Rewards-Script.git
synced 2026-01-18 05:53:57 +00:00
1.0.6
This commit is contained in:
@@ -6,7 +6,7 @@ const rl = readline.createInterface({
|
||||
output: process.stdout
|
||||
})
|
||||
|
||||
import { tryDismissAllMessages, tryDismissBingCookieBanner } from '../BrowserUtil'
|
||||
import { tryDismissAllMessages, tryDismissBingCookieBanner } from '../browser/BrowserUtil'
|
||||
import { wait } from '../util/Utils'
|
||||
import { log } from '../util/Logger'
|
||||
|
||||
@@ -34,7 +34,7 @@ export async function login(page: Page, email: string, password: string) {
|
||||
log('LOGIN', 'Logged in successfully')
|
||||
|
||||
} catch (error) {
|
||||
log('LOGIN', 'An error occurred:' + JSON.stringify(error, null, 2), 'error')
|
||||
log('LOGIN', 'An error occurred:' + error, 'error')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ async function checkBingLogin(page: Page): Promise<void> {
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
log('LOGIN-BING', 'An error occurred:' + JSON.stringify(error, null, 2), 'error')
|
||||
log('LOGIN-BING', 'An error occurred:' + error, 'error')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,11 +8,16 @@ import { doThisOrThat } from './activities/ThisOrThat'
|
||||
import { wait } from '../util/Utils'
|
||||
import { log } from '../util/Logger'
|
||||
|
||||
import { DashboardData } from '../interface/DashboardData'
|
||||
import { DashboardData, MorePromotion } from '../interface/DashboardData'
|
||||
|
||||
export async function doMorePromotions(page: Page, data: DashboardData) {
|
||||
const morePromotions = data.morePromotions
|
||||
|
||||
// Check if there is a promotional item
|
||||
if (data.promotionalItem) { // Convert and add the promotional item to the array
|
||||
morePromotions.push(data.promotionalItem as unknown as MorePromotion)
|
||||
}
|
||||
|
||||
const activitiesUncompleted = morePromotions?.filter(x => !x.complete) ?? []
|
||||
|
||||
if (!activitiesUncompleted.length) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Page } from 'puppeteer'
|
||||
|
||||
import { getLatestTab } from '../../BrowserUtil'
|
||||
import { getLatestTab } from '../../browser/BrowserUtil'
|
||||
import { log } from '../../util/Logger'
|
||||
import { randomNumber, wait } from '../../util/Utils'
|
||||
|
||||
@@ -20,7 +20,9 @@ export async function doPoll(page: Page, data: PromotionalItem | MorePromotion)
|
||||
|
||||
const buttonId = `#btoption${Math.floor(randomNumber(0, 1))}`
|
||||
|
||||
await pollPage.waitForNetworkIdle({ timeout: 5000 })
|
||||
await pollPage.waitForSelector(buttonId, { visible: true, timeout: 5000 })
|
||||
|
||||
await pollPage.click(buttonId)
|
||||
|
||||
await wait(2000)
|
||||
@@ -28,6 +30,8 @@ export async function doPoll(page: Page, data: PromotionalItem | MorePromotion)
|
||||
|
||||
log('POLL', 'Completed the poll successfully')
|
||||
} catch (error) {
|
||||
log('POLL', 'An error occurred:' + JSON.stringify(error, null, 2), 'error')
|
||||
const pollPage = await getLatestTab(page)
|
||||
await pollPage.close()
|
||||
log('POLL', 'An error occurred:' + error, 'error')
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Page } from 'puppeteer'
|
||||
|
||||
import { getLatestTab } from '../../BrowserUtil'
|
||||
import { getQuizData, waitForQuizRefresh } from '../../BrowserFunc'
|
||||
import { getLatestTab } from '../../browser/BrowserUtil'
|
||||
import { getQuizData, waitForQuizRefresh } from '../../browser/BrowserFunc'
|
||||
import { wait } from '../../util/Utils'
|
||||
import { log } from '../../util/Logger'
|
||||
|
||||
@@ -18,6 +18,7 @@ export async function doQuiz(page: Page, data: PromotionalItem | MorePromotion)
|
||||
await page.click(selector)
|
||||
|
||||
const quizPage = await getLatestTab(page)
|
||||
await quizPage.waitForNetworkIdle({ timeout: 5000 })
|
||||
|
||||
// Check if the quiz has been started or not
|
||||
const quizNotStarted = await quizPage.waitForSelector('#rqStartQuiz', { visible: true, timeout: 3000 }).then(() => true).catch(() => false)
|
||||
@@ -29,7 +30,7 @@ export async function doQuiz(page: Page, data: PromotionalItem | MorePromotion)
|
||||
|
||||
await wait(2000)
|
||||
|
||||
const quizData = await getQuizData(quizPage)
|
||||
let quizData = await getQuizData(quizPage)
|
||||
const questionsRemaining = quizData.maxQuestions - quizData.CorrectlyAnsweredQuestionCount // Amount of questions remaining
|
||||
|
||||
// All questions
|
||||
@@ -41,7 +42,6 @@ export async function doQuiz(page: Page, data: PromotionalItem | MorePromotion)
|
||||
for (let i = 0; i < quizData.numberOfOptions; i++) {
|
||||
const answerSelector = await quizPage.waitForSelector(`#rqAnswerOption${i}`, { visible: true, timeout: 5000 })
|
||||
const answerAttribute = await answerSelector?.evaluate(el => el.getAttribute('iscorrectoption'))
|
||||
await wait(500)
|
||||
|
||||
if (answerAttribute && answerAttribute.toLowerCase() === 'true') {
|
||||
answers.push(`#rqAnswerOption${i}`)
|
||||
@@ -65,6 +65,7 @@ export async function doQuiz(page: Page, data: PromotionalItem | MorePromotion)
|
||||
|
||||
// Other type quiz
|
||||
} else if ([2, 3, 4].includes(quizData.numberOfOptions)) {
|
||||
quizData = await getQuizData(quizPage) // Refresh Quiz Data
|
||||
const correctOption = quizData.correctAnswer
|
||||
|
||||
for (let i = 0; i < quizData.numberOfOptions; i++) {
|
||||
@@ -75,7 +76,6 @@ export async function doQuiz(page: Page, data: PromotionalItem | MorePromotion)
|
||||
if (dataOption === correctOption) {
|
||||
// Click the answer on page
|
||||
await quizPage.click(`#rqAnswerOption${i}`)
|
||||
await wait(2000)
|
||||
|
||||
const refreshSuccess = await waitForQuizRefresh(quizPage)
|
||||
if (!refreshSuccess) {
|
||||
@@ -98,7 +98,7 @@ export async function doQuiz(page: Page, data: PromotionalItem | MorePromotion)
|
||||
} catch (error) {
|
||||
const quizPage = await getLatestTab(page)
|
||||
await quizPage.close()
|
||||
log('QUIZ', 'An error occurred:' + JSON.stringify(error, null, 2), 'error')
|
||||
log('QUIZ', 'An error occurred:' + error, 'error')
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Page } from 'puppeteer'
|
||||
import axios from 'axios'
|
||||
|
||||
import { getLatestTab } from '../../BrowserUtil'
|
||||
import { getSearchPoints } from '../../BrowserFunc'
|
||||
import { getLatestTab } from '../../browser/BrowserUtil'
|
||||
import { getSearchPoints } from '../../browser/BrowserFunc'
|
||||
import { log } from '../../util/Logger'
|
||||
import { randomNumber, shuffleArray, wait } from '../../util/Utils'
|
||||
|
||||
@@ -169,11 +169,11 @@ async function bingSearch(page: Page, searchPage: Page, query: string, mobile: b
|
||||
|
||||
} catch (error) {
|
||||
if (i === 5) {
|
||||
log('SEARCH-BING', 'Failed after 5 retries... An error occurred:' + JSON.stringify(error, null, 2), 'error')
|
||||
log('SEARCH-BING', 'Failed after 5 retries... An error occurred:' + error, 'error')
|
||||
break
|
||||
|
||||
}
|
||||
log('SEARCH-BING', 'Search failed, An error occurred:' + JSON.stringify(error, null, 2), 'error')
|
||||
log('SEARCH-BING', 'Search failed, An error occurred:' + error, 'error')
|
||||
log('SEARCH-BING', `Retrying search, attempt ${i}/5`, 'warn')
|
||||
|
||||
await wait(4000)
|
||||
@@ -215,7 +215,7 @@ async function getGoogleTrends(locale: string, queryCount: number): Promise<Goog
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
log('SEARCH-GOOGLE-TRENDS', 'An error occurred:' + JSON.stringify(error, null, 2), 'error')
|
||||
log('SEARCH-GOOGLE-TRENDS', 'An error occurred:' + error, 'error')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,7 +236,7 @@ async function getRelatedTerms(term: string): Promise<string[]> {
|
||||
|
||||
return response.data[1] as string[]
|
||||
} catch (error) {
|
||||
log('SEARCH-BING-RELTATED', 'An error occurred:' + JSON.stringify(error, null, 2), 'error')
|
||||
log('SEARCH-BING-RELTATED', 'An error occurred:' + error, 'error')
|
||||
}
|
||||
return []
|
||||
}
|
||||
@@ -256,7 +256,7 @@ async function randomScroll(page: Page) {
|
||||
await page.keyboard.press('ArrowDown')
|
||||
}
|
||||
} catch (error) {
|
||||
log('SEARCH-RANDOM-SCROLL', 'An error occurred:' + JSON.stringify(error, null, 2), 'error')
|
||||
log('SEARCH-RANDOM-SCROLL', 'An error occurred:' + error, 'error')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -302,6 +302,6 @@ async function clickRandomLink(page: Page, mobile: boolean) {
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
log('SEARCH-RANDOM-CLICK', 'An error occurred:' + JSON.stringify(error, null, 2), 'error')
|
||||
log('SEARCH-RANDOM-CLICK', 'An error occurred:' + error, 'error')
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Page } from 'puppeteer'
|
||||
|
||||
import { getLatestTab } from '../../BrowserUtil'
|
||||
import { getLatestTab } from '../../browser/BrowserUtil'
|
||||
import { wait } from '../../util/Utils'
|
||||
import { log } from '../../util/Logger'
|
||||
|
||||
@@ -18,6 +18,7 @@ export async function doThisOrThat(page: Page, data: PromotionalItem | MorePromo
|
||||
await page.click(selector)
|
||||
|
||||
const thisorthatPage = await getLatestTab(page)
|
||||
await thisorthatPage.waitForNetworkIdle({ timeout: 5000 })
|
||||
|
||||
// Check if the quiz has been started or not
|
||||
const quizNotStarted = await thisorthatPage.waitForSelector('#rqStartQuiz', { visible: true, timeout: 3000 }).then(() => true).catch(() => false)
|
||||
@@ -33,7 +34,9 @@ export async function doThisOrThat(page: Page, data: PromotionalItem | MorePromo
|
||||
|
||||
log('THIS-OR-THAT', 'Completed the ThisOrthat successfully')
|
||||
} catch (error) {
|
||||
log('THIS-OR-THAT', 'An error occurred:' + JSON.stringify(error, null, 2), 'error')
|
||||
const thisorthatPage = await getLatestTab(page)
|
||||
await thisorthatPage.close()
|
||||
log('THIS-OR-THAT', 'An error occurred:' + error, 'error')
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Page } from 'puppeteer'
|
||||
|
||||
import { getLatestTab } from '../../BrowserUtil'
|
||||
import { getLatestTab } from '../../browser/BrowserUtil'
|
||||
import { log } from '../../util/Logger'
|
||||
|
||||
import { PromotionalItem, MorePromotion } from '../../interface/DashboardData'
|
||||
@@ -17,11 +17,14 @@ export async function doUrlReward(page: Page, data: PromotionalItem | MorePromot
|
||||
|
||||
// After waiting, close the page
|
||||
const visitPage = await getLatestTab(page)
|
||||
await visitPage.waitForNetworkIdle({ timeout: 5000 })
|
||||
await visitPage.close()
|
||||
|
||||
log('URL-REWARD', 'Completed the UrlReward successfully')
|
||||
} catch (error) {
|
||||
log('URL-REWARD', 'An error occurred:' + JSON.stringify(error, null, 2), 'error')
|
||||
const visitPage = await getLatestTab(page)
|
||||
await visitPage.close()
|
||||
log('URL-REWARD', 'An error occurred:' + error, 'error')
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user