From 15b2b827eb9bf6d1b89e5fbaa3d54f3440fdf38f Mon Sep 17 00:00:00 2001 From: TheNetsky <56271887+TheNetsky@users.noreply.github.com> Date: Sun, 14 Jan 2024 14:09:57 +0100 Subject: [PATCH] 1.4.1 - Fixed typos - Added Dockerfile (experimental) - Increased scroll amount --- Dockerfile | 42 ++++++++++++++++++++++++++++++ README.md | 1 + package.json | 5 ++-- src/functions/Workers.ts | 2 +- src/functions/activities/Search.ts | 4 +-- 5 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8d14f9d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,42 @@ +# Use an official Node.js runtime as a base image +FROM node:18 + +# Set the working directory in the container +WORKDIR /usr/src/microsoft-rewards-script + +# Install jq +RUN apt-get update && apt-get install -y jq + + +# Copy all files to the working directory +COPY . . + +# Check if "headless" is set to "true" in the config.json file +RUN HEADLESS=$(cat src/config.json | jq -r .headless) \ + && if [ "$HEADLESS" != "true" ]; then \ + echo "Error: 'headless' in src/config.json is not true."; \ + exit 1; \ + fi + +# Install dependencies including Playwright +RUN apt-get install -y \ + xvfb \ + libgbm-dev \ + libnss3 \ + libasound2 \ + libxss1 \ + libatk-bridge2.0-0 \ + libgtk-3-0 \ + && rm -rf /var/lib/apt/lists/* + +# Install application dependencies +RUN npm install + +# Build the script +RUN npm run build + +# Install playwright chromium +RUN npx playwright install chromium + +# Define the command to run your application +CMD ["npm", "start"] diff --git a/README.md b/README.md index 4b6b09f..e6c2233 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ Under development, however mainly for personal use! ## Notes ## - If you end the script without closing the browser window first (only with headless as false), you'll be left with hanging chrome instances using resources. Use taskmanager to kill these or use the included `npm run chrome-kill-win` script. (Windows) - If you automate this script, set it to run at least 2 times a day to make sure it picked up all tasks, set `"runOnZeroPoints": false` so it doesn't run when no points are found. +- Docker container has to be recreated for any changes regardings the `config.json` and/or `accounts.json`. ## Config ## | Setting | Description | Default | diff --git a/package.json b/package.json index 3b43c18..c0569bf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "microsoft-rewards-script", - "version": "1.4.0", + "version": "1.4.1", "description": "Automatically do tasks for Microsoft Rewards but in TS!", "main": "index.js", "engines": { @@ -11,7 +11,8 @@ "start": "node ./dist/index.js", "ts-start": "ts-node ./src/index.ts", "dev": "ts-node ./src/index.ts -dev", - "kill-chrome-win": "powershell -Command \"Get-Process | Where-Object { $_.MainModule.FileVersionInfo.FileDescription -eq 'Google Chrome for Testing' } | ForEach-Object { Stop-Process -Id $_.Id -Force }\"" + "kill-chrome-win": "powershell -Command \"Get-Process | Where-Object { $_.MainModule.FileVersionInfo.FileDescription -eq 'Google Chrome for Testing' } | ForEach-Object { Stop-Process -Id $_.Id -Force }\"", + "create-docker" : "docker build -t microsoft-rewards-script-docker ." }, "keywords": [ "Bing Rewards", diff --git a/src/functions/Workers.ts b/src/functions/Workers.ts index 5b4f47d..7f672d8 100644 --- a/src/functions/Workers.ts +++ b/src/functions/Workers.ts @@ -95,7 +95,7 @@ export class Workers { } // Solve Activities - this.bot.log('MORE-PROMOTIONS', 'Started solving "More Promotions" item') + this.bot.log('MORE-PROMOTIONS', 'Started solving "More Promotions" items') page = await this.bot.browser.utils.getLatestTab(page) diff --git a/src/functions/activities/Search.ts b/src/functions/activities/Search.ts index 5510a2c..6bd34de 100644 --- a/src/functions/activities/Search.ts +++ b/src/functions/activities/Search.ts @@ -132,7 +132,7 @@ export class Search extends Workers { for (let i = 0; i < 5; i++) { try { const searchBar = '#sb_form_q' - await searchPage.waitForSelector(searchBar, { state: 'visible', timeout: 10_000 }) + await searchPage.waitForSelector(searchBar, { state: 'attached', timeout: 10_000 }) await searchPage.click(searchBar) // Focus on the textarea await this.bot.utils.wait(500) await searchPage.keyboard.down('Control') @@ -249,7 +249,7 @@ export class Search extends Workers { private async randomScroll(page: Page) { try { // Press the arrow down key to scroll - for (let i = 0; i < this.bot.utils.randomNumber(5, 400); i++) { + for (let i = 0; i < this.bot.utils.randomNumber(5, 600); i++) { await page.keyboard.press('ArrowDown') }