mirror of
https://github.com/TheNetsky/Microsoft-Rewards-Script.git
synced 2026-01-18 14:03:58 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5bc66c5fc9 |
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "microsoft-rewards-script",
|
"name": "microsoft-rewards-script",
|
||||||
"version": "1.4.9",
|
"version": "1.4.10",
|
||||||
"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": {
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ export class ReadToEarn extends Workers {
|
|||||||
this.bot.log('READ-TO-EARN', 'Starting Read to Earn')
|
this.bot.log('READ-TO-EARN', 'Starting Read to Earn')
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
let geoLocale = data.userProfile.attributes.country
|
let geoLocale = data.userProfile.attributes.country
|
||||||
geoLocale = (this.bot.config.searchSettings.useGeoLocaleQueries && geoLocale.length === 2) ? geoLocale.toLowerCase() : 'us'
|
geoLocale = (this.bot.config.searchSettings.useGeoLocaleQueries && geoLocale.length === 2) ? geoLocale.toLowerCase() : 'us'
|
||||||
|
|
||||||
@@ -26,7 +25,7 @@ export class ReadToEarn extends Workers {
|
|||||||
}
|
}
|
||||||
const userDataResponse = await axios(userDataRequest)
|
const userDataResponse = await axios(userDataRequest)
|
||||||
const userData = (await userDataResponse.data).response
|
const userData = (await userDataResponse.data).response
|
||||||
let balance: number = userData.balance
|
let userBalance = userData.balance
|
||||||
|
|
||||||
const jsonData = {
|
const jsonData = {
|
||||||
amount: 1,
|
amount: 1,
|
||||||
@@ -38,7 +37,8 @@ export class ReadToEarn extends Workers {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < 10; ++i) {
|
const articleCount = 10
|
||||||
|
for (let i = 0; i < articleCount; ++i) {
|
||||||
jsonData.id = randomBytes(64).toString('hex')
|
jsonData.id = randomBytes(64).toString('hex')
|
||||||
const claimRequest = {
|
const claimRequest = {
|
||||||
url: 'https://prod.rewardsplatform.microsoft.com/dapi/me/activities',
|
url: 'https://prod.rewardsplatform.microsoft.com/dapi/me/activities',
|
||||||
@@ -55,12 +55,12 @@ export class ReadToEarn extends Workers {
|
|||||||
const claimResponse = await axios(claimRequest)
|
const claimResponse = await axios(claimRequest)
|
||||||
const newBalance = (await claimResponse.data).response.balance
|
const newBalance = (await claimResponse.data).response.balance
|
||||||
|
|
||||||
if (newBalance == balance) {
|
if (newBalance == userBalance) {
|
||||||
this.bot.log('READ-TO-EARN', 'Read all available articles')
|
this.bot.log('READ-TO-EARN', 'Read all available articles')
|
||||||
break
|
break
|
||||||
} else {
|
} else {
|
||||||
balance = newBalance
|
this.bot.log('READ-TO-EARN', `Read article ${i + 1} of ${articleCount} max | Gained ${newBalance - userBalance} Points`)
|
||||||
this.bot.log('READ-TO-EARN', `Read article ${i + 1}`)
|
userBalance = newBalance
|
||||||
await this.bot.utils.wait(Math.floor(this.bot.utils.randomNumber(this.bot.config.searchSettings.searchDelay.min, this.bot.config.searchSettings.searchDelay.max)))
|
await this.bot.utils.wait(Math.floor(this.bot.utils.randomNumber(this.bot.config.searchSettings.searchDelay.min, this.bot.config.searchSettings.searchDelay.max)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,11 +10,11 @@ import { GoogleSearch } from '../../interface/Search'
|
|||||||
|
|
||||||
|
|
||||||
export class Search extends Workers {
|
export class Search extends Workers {
|
||||||
|
private bingHome = 'https://bing.com'
|
||||||
private searchPageURL = 'https://bing.com'
|
private searchPageURL = ''
|
||||||
|
|
||||||
public async doSearch(page: Page, data: DashboardData) {
|
public async doSearch(page: Page, data: DashboardData) {
|
||||||
this.bot.log('SEARCH-BING', 'Starting bing searches')
|
this.bot.log('SEARCH-BING', 'Starting Bing searches')
|
||||||
|
|
||||||
page = await this.bot.browser.utils.getLatestTab(page)
|
page = await this.bot.browser.utils.getLatestTab(page)
|
||||||
|
|
||||||
@@ -34,7 +34,7 @@ export class Search extends Workers {
|
|||||||
googleSearchQueries = [...new Set(googleSearchQueries)]
|
googleSearchQueries = [...new Set(googleSearchQueries)]
|
||||||
|
|
||||||
// Go to bing
|
// Go to bing
|
||||||
await page.goto(this.searchPageURL)
|
await page.goto(this.searchPageURL ? this.searchPageURL : this.bingHome)
|
||||||
|
|
||||||
let maxLoop = 0 // If the loop hits 10 this when not gaining any points, we're assuming it's stuck. If it ddoesn't continue after 5 more searches with alternative queries, abort search
|
let maxLoop = 0 // If the loop hits 10 this when not gaining any points, we're assuming it's stuck. If it ddoesn't continue after 5 more searches with alternative queries, abort search
|
||||||
|
|
||||||
@@ -133,11 +133,12 @@ export class Search extends Workers {
|
|||||||
private async bingSearch(searchPage: Page, query: string) {
|
private async bingSearch(searchPage: Page, query: string) {
|
||||||
const platformControlKey = platform() === 'darwin' ? 'Meta' : 'Control'
|
const platformControlKey = platform() === 'darwin' ? 'Meta' : 'Control'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 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 {
|
||||||
|
// This page had already been set to the Bing.com page or the previous search listing, we just need to select it
|
||||||
|
searchPage = await this.bot.browser.utils.getLatestTab(searchPage)
|
||||||
|
|
||||||
// Go to top of the page
|
// Go to top of the page
|
||||||
await searchPage.evaluate(() => {
|
await searchPage.evaluate(() => {
|
||||||
window.scrollTo(0, 0)
|
window.scrollTo(0, 0)
|
||||||
@@ -163,6 +164,7 @@ export class Search extends Workers {
|
|||||||
|
|
||||||
// Bing.com in Chrome opens a new tab when searching
|
// Bing.com in Chrome opens a new tab when searching
|
||||||
const resultPage = await this.bot.browser.utils.getLatestTab(searchPage)
|
const resultPage = await this.bot.browser.utils.getLatestTab(searchPage)
|
||||||
|
this.searchPageURL = new URL(resultPage.url()).href // Set the results page
|
||||||
|
|
||||||
if (this.bot.config.searchSettings.scrollRandomResults) {
|
if (this.bot.config.searchSettings.scrollRandomResults) {
|
||||||
await this.bot.utils.wait(2000)
|
await this.bot.utils.wait(2000)
|
||||||
@@ -185,6 +187,7 @@ export class Search extends Workers {
|
|||||||
break
|
break
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.bot.log('SEARCH-BING', 'Search failed, An error occurred:' + error, 'error')
|
this.bot.log('SEARCH-BING', 'Search failed, An error occurred:' + error, 'error')
|
||||||
this.bot.log('SEARCH-BING', `Retrying search, attempt ${i}/5`, 'warn')
|
this.bot.log('SEARCH-BING', `Retrying search, attempt ${i}/5`, 'warn')
|
||||||
|
|
||||||
@@ -286,16 +289,15 @@ export class Search extends Workers {
|
|||||||
|
|
||||||
private async clickRandomLink(page: Page) {
|
private async clickRandomLink(page: Page) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
await page.click('#b_results .b_algo h2', { timeout: 2000 }).catch(() => { }) // Since we don't really care if it did it or not
|
await page.click('#b_results .b_algo h2', { timeout: 2000 }).catch(() => { }) // Since we don't really care if it did it or not
|
||||||
|
|
||||||
// Will get current tab if no new one is created
|
// Will get current tab if no new one is created, this will always be the visited site or the result page if it failed to click
|
||||||
let lastTab = await this.bot.browser.utils.getLatestTab(page)
|
let lastTab = await this.bot.browser.utils.getLatestTab(page)
|
||||||
|
|
||||||
// Stay for 10 seconds
|
// Stay for 10 seconds
|
||||||
await this.bot.utils.wait(10_000)
|
await this.bot.utils.wait(10_000)
|
||||||
|
|
||||||
let lastTabURL = new URL(lastTab.url()) // Get new tab info
|
let lastTabURL = new URL(lastTab.url()) // Get new tab info, this is the website we've visited
|
||||||
|
|
||||||
// Check if the URL is different from the original one, don't loop more than 5 times.
|
// Check if the URL is different from the original one, don't loop more than 5 times.
|
||||||
let i = 0
|
let i = 0
|
||||||
@@ -325,11 +327,15 @@ export class Search extends Workers {
|
|||||||
// If only 1 tab is open, open a new one to search in
|
// If only 1 tab is open, open a new one to search in
|
||||||
} else if (tabs.length === 1) {
|
} else if (tabs.length === 1) {
|
||||||
const newPage = await browser.newPage()
|
const newPage = await browser.newPage()
|
||||||
await newPage.goto(this.searchPageURL)
|
await this.bot.utils.wait(1000)
|
||||||
|
await newPage.goto(this.bingHome)
|
||||||
|
await this.bot.utils.wait(3000)
|
||||||
|
this.searchPageURL = newPage.url()
|
||||||
|
|
||||||
// Else go back one page, this means the correct amount is open
|
// Else reset the last tab back to the search listing
|
||||||
} else {
|
} else {
|
||||||
await lastTab.goBack().catch(() => { })
|
lastTab = await this.bot.browser.utils.getLatestTab(lastTab)
|
||||||
|
await lastTab.goto(this.searchPageURL)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user