mirror of
https://github.com/TheNetsky/Microsoft-Rewards-Script.git
synced 2026-01-11 19:06:18 +00:00
1.0.4
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "microsoft-rewards-script",
|
"name": "microsoft-rewards-script",
|
||||||
"version": "1.0.3",
|
"version": "1.0.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",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Page } from 'puppeteer'
|
import { Page } from 'puppeteer'
|
||||||
import { DashboardData } from '../interface/DashboardData'
|
import { DashboardData } from '../interface/DashboardData'
|
||||||
import { doPoll } from './activities/Poll'
|
import { doPoll } from './activities/Poll'
|
||||||
import { getFormattedDate } from '../util/Utils'
|
import { getFormattedDate, wait } from '../util/Utils'
|
||||||
import { doQuiz } from './activities/Quiz'
|
import { doQuiz } from './activities/Quiz'
|
||||||
import { log } from '../util/Logger'
|
import { log } from '../util/Logger'
|
||||||
import { doUrlReward } from './activities/UrlReward'
|
import { doUrlReward } from './activities/UrlReward'
|
||||||
@@ -47,7 +47,7 @@ export async function doDailySet(page: Page, data: DashboardData) {
|
|||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
await wait(1500)
|
||||||
}
|
}
|
||||||
|
|
||||||
log('DAILY-SET', 'Daily set items have been completed')
|
log('DAILY-SET', 'Daily set items have been completed')
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { doPoll } from './activities/Poll'
|
|||||||
import { doQuiz } from './activities/Quiz'
|
import { doQuiz } from './activities/Quiz'
|
||||||
import { log } from '../util/Logger'
|
import { log } from '../util/Logger'
|
||||||
import { doUrlReward } from './activities/UrlReward'
|
import { doUrlReward } from './activities/UrlReward'
|
||||||
|
import { wait } from '../util/Utils'
|
||||||
|
|
||||||
|
|
||||||
export async function doMorePromotions(page: Page, data: DashboardData) {
|
export async function doMorePromotions(page: Page, data: DashboardData) {
|
||||||
@@ -46,6 +47,6 @@ export async function doMorePromotions(page: Page, data: DashboardData) {
|
|||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
await wait(1500)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,7 @@ import { Page } from 'puppeteer'
|
|||||||
import { MorePromotion, PromotionalItem } from '../../interface/DashboardData'
|
import { MorePromotion, PromotionalItem } from '../../interface/DashboardData'
|
||||||
import { getLatestTab } from '../../BrowserUtil'
|
import { getLatestTab } from '../../BrowserUtil'
|
||||||
import { log } from '../../util/Logger'
|
import { log } from '../../util/Logger'
|
||||||
import { wait } from '../../util/Utils'
|
import { randomNumber, wait } from '../../util/Utils'
|
||||||
|
|
||||||
export async function doPoll(page: Page, data: PromotionalItem | MorePromotion) {
|
export async function doPoll(page: Page, data: PromotionalItem | MorePromotion) {
|
||||||
log('POLL', 'Trying to complete poll')
|
log('POLL', 'Trying to complete poll')
|
||||||
@@ -16,7 +16,7 @@ export async function doPoll(page: Page, data: PromotionalItem | MorePromotion)
|
|||||||
|
|
||||||
const pollPage = await getLatestTab(page)
|
const pollPage = await getLatestTab(page)
|
||||||
|
|
||||||
const buttonId = `#btoption${Math.floor(Math.random() * 2)}`
|
const buttonId = `#btoption${Math.floor(randomNumber(0, 1))}`
|
||||||
|
|
||||||
await pollPage.waitForSelector(buttonId)
|
await pollPage.waitForSelector(buttonId)
|
||||||
await pollPage.click(buttonId)
|
await pollPage.click(buttonId)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { Page } from 'puppeteer'
|
|||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
|
|
||||||
import { log } from '../../util/Logger'
|
import { log } from '../../util/Logger'
|
||||||
import { shuffleArray, wait } from '../../util/Utils'
|
import { randomNumber, shuffleArray, wait } from '../../util/Utils'
|
||||||
import { getSearchPoints } from '../../BrowserFunc'
|
import { getSearchPoints } from '../../BrowserFunc'
|
||||||
|
|
||||||
import { searches } from '../../config.json'
|
import { searches } from '../../config.json'
|
||||||
@@ -10,6 +10,7 @@ import { searches } from '../../config.json'
|
|||||||
import { DashboardData, DashboardImpression } from '../../interface/DashboardData'
|
import { DashboardData, DashboardImpression } from '../../interface/DashboardData'
|
||||||
import { GoogleTrends } from '../../interface/GoogleDailyTrends'
|
import { GoogleTrends } from '../../interface/GoogleDailyTrends'
|
||||||
import { GoogleSearch } from '../../interface/Search'
|
import { GoogleSearch } from '../../interface/Search'
|
||||||
|
import { getLatestTab } from '../../BrowserUtil'
|
||||||
|
|
||||||
export async function doSearch(page: Page, data: DashboardData, mobile: boolean) {
|
export async function doSearch(page: Page, data: DashboardData, mobile: boolean) {
|
||||||
const locale = await page.evaluate(() => {
|
const locale = await page.evaluate(() => {
|
||||||
@@ -56,7 +57,7 @@ export async function doSearch(page: Page, data: DashboardData, mobile: boolean)
|
|||||||
|
|
||||||
log('SEARCH-BING', `${missingPoints} Points Remaining | Query: ${query} | Mobile: ${mobile}`)
|
log('SEARCH-BING', `${missingPoints} Points Remaining | Query: ${query} | Mobile: ${mobile}`)
|
||||||
|
|
||||||
const newData = await bingSearch(page, searchPage, query)
|
const newData = await bingSearch(page, searchPage, query, mobile)
|
||||||
|
|
||||||
const newMobileData = newData.mobileSearch[0] as DashboardImpression // Mobile searches
|
const newMobileData = newData.mobileSearch[0] as DashboardImpression // Mobile searches
|
||||||
const newEdgeData = newData.pcSearch[1] as DashboardImpression // Edge searches
|
const newEdgeData = newData.pcSearch[1] as DashboardImpression // Edge searches
|
||||||
@@ -100,7 +101,7 @@ export async function doSearch(page: Page, data: DashboardData, mobile: boolean)
|
|||||||
// Search for the first 2 related terms
|
// Search for the first 2 related terms
|
||||||
for (const term of relatedTerms.slice(1, 3)) {
|
for (const term of relatedTerms.slice(1, 3)) {
|
||||||
log('SEARCH-BING-EXTRA', `${missingPoints} Points Remaining | Query: ${term} | Mobile: ${mobile}`)
|
log('SEARCH-BING-EXTRA', `${missingPoints} Points Remaining | Query: ${term} | Mobile: ${mobile}`)
|
||||||
const newData = await bingSearch(page, searchPage, query.topic)
|
const newData = await bingSearch(page, searchPage, query.topic, mobile)
|
||||||
|
|
||||||
const newMobileData = newData.mobileSearch[0] as DashboardImpression // Mobile searches
|
const newMobileData = newData.mobileSearch[0] as DashboardImpression // Mobile searches
|
||||||
const newEdgeData = newData.pcSearch[1] as DashboardImpression // Edge searches
|
const newEdgeData = newData.pcSearch[1] as DashboardImpression // Edge searches
|
||||||
@@ -137,7 +138,7 @@ export async function doSearch(page: Page, data: DashboardData, mobile: boolean)
|
|||||||
log('SEARCH-BING', 'Completed searches')
|
log('SEARCH-BING', 'Completed searches')
|
||||||
}
|
}
|
||||||
|
|
||||||
async function bingSearch(page: Page, searchPage: Page, query: string) {
|
async function bingSearch(page: Page, searchPage: Page, query: string, mobile: boolean) {
|
||||||
// Try a max of 5 times
|
// Try a max of 5 times
|
||||||
for (let i = 0; i < 5; i++) {
|
for (let i = 0; i < 5; i++) {
|
||||||
try {
|
try {
|
||||||
@@ -159,10 +160,10 @@ async function bingSearch(page: Page, searchPage: Page, query: string) {
|
|||||||
|
|
||||||
if (searches.clickRandomResults) {
|
if (searches.clickRandomResults) {
|
||||||
await wait(2000)
|
await wait(2000)
|
||||||
await clickRandomLink(searchPage)
|
await clickRandomLink(searchPage, mobile)
|
||||||
}
|
}
|
||||||
|
|
||||||
await wait(Math.floor(Math.random() * (20_000 - 10_000) + 1) + 10_000)
|
await wait(Math.floor(randomNumber(10_000, 20_000)))
|
||||||
|
|
||||||
return await getSearchPoints(page)
|
return await getSearchPoints(page)
|
||||||
|
|
||||||
@@ -171,8 +172,9 @@ async function bingSearch(page: Page, searchPage: Page, query: string) {
|
|||||||
log('SEARCH-BING', 'Failed after 5 retries... An error occurred:' + error, 'error')
|
log('SEARCH-BING', 'Failed after 5 retries... An error occurred:' + error, 'error')
|
||||||
return await getSearchPoints(page)
|
return await getSearchPoints(page)
|
||||||
}
|
}
|
||||||
|
log('SEARCH-BING', 'Search failed, An error occurred:' + error, 'error')
|
||||||
|
log('SEARCH-BING', `Retrying search, attempt ${i}/5`, 'warn')
|
||||||
|
|
||||||
log('SEARCH-BING', 'Search failed, retrying...', 'warn')
|
|
||||||
await wait(4000)
|
await wait(4000)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -247,17 +249,58 @@ function formatDate(date: Date): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function randomScroll(page: Page) {
|
async function randomScroll(page: Page) {
|
||||||
const randomNumber = Math.random() * (50 - 5 + 1) + 5
|
try {
|
||||||
|
|
||||||
// Press the arrow down key to scroll
|
// Press the arrow down key to scroll
|
||||||
for (let i = 0; i < randomNumber; i++) {
|
for (let i = 0; i < randomNumber(5, 50); i++) {
|
||||||
await page.keyboard.press('ArrowDown')
|
await page.keyboard.press('ArrowDown')
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
log('SEARCH-RANDOM-SCROLL', 'An error occurred:' + error, 'error')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function clickRandomLink(page: Page) {
|
async function clickRandomLink(page: Page, mobile: boolean) {
|
||||||
await page.click('#b_results h2')
|
try {
|
||||||
|
const searchListingURL = new URL(page.url()) // Get page info before clicking
|
||||||
|
|
||||||
|
await page.click('#b_results .b_algo h2').catch(() => { }) // Since we don't really care if it did it or not
|
||||||
await wait(3000)
|
await wait(3000)
|
||||||
|
|
||||||
|
const newTab = await getLatestTab(page) // Will get current tab if no new one is created
|
||||||
|
|
||||||
|
// Check if the tab is closed or not
|
||||||
|
if (!newTab.isClosed()) {
|
||||||
|
const newTabURL = new URL(newTab.url()) // Get new tab info
|
||||||
|
|
||||||
|
// Check if the URL is different from the original one
|
||||||
|
if (newTabURL.href !== searchListingURL.href) {
|
||||||
|
// Mobile is always same tab
|
||||||
|
if (mobile) {
|
||||||
await page.goBack()
|
await page.goBack()
|
||||||
|
|
||||||
|
const currentURL = new URL(page.url())
|
||||||
|
// If "goBack" didn't return to search listing (due to redirects)
|
||||||
|
if (currentURL.hostname !== searchListingURL.hostname) {
|
||||||
|
await page.goto(searchListingURL.href)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Still on bing, go back (news/images pages on bing search)
|
||||||
|
} else if (newTabURL.hostname == searchListingURL.hostname) {
|
||||||
|
await page.goBack()
|
||||||
|
|
||||||
|
const currentURL = new URL(page.url())
|
||||||
|
// If "goBack" didn't return to search listing (due to redirects)
|
||||||
|
if (currentURL.hostname !== searchListingURL.hostname) {
|
||||||
|
await page.goto(searchListingURL.href)
|
||||||
|
}
|
||||||
|
|
||||||
|
// No longer on bing, likely opened a new tab, close this tab
|
||||||
|
} else {
|
||||||
|
await newTab.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
log('SEARCH-RANDOM-CLICK', 'An error occurred:' + error, 'error')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -21,3 +21,7 @@ export function shuffleArray(array: any[]): any[] {
|
|||||||
|
|
||||||
return shuffledArray
|
return shuffledArray
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function randomNumber(min: number, max: number) {
|
||||||
|
return Math.floor(Math.random() * (max - min + 1)) + min
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user