Skip to content

Instantly share code, notes, and snippets.

@driversti
Last active December 9, 2023 11:39
Show Gist options
  • Save driversti/cc09081067bdb98c5a57074a1b38acfb to your computer and use it in GitHub Desktop.
Save driversti/cc09081067bdb98c5a57074a1b38acfb to your computer and use it in GitHub Desktop.
Automated over time work

README for Automated Overtime Work Script


Overview

This script is designed to work over time by spending all either available energy or overtime points. It runs in a loop every 5 seconds and checks certain conditions in the response data to decide whether to continue or stop the loop.

How to Use

  1. Open the Browser Console:

    • Google Chrome or Brave:
      • Right-click on the webpage and select "Inspect," then click on the "Console" tab.
      • Alternatively, press Ctrl+Shift+J (Windows/Linux) or Cmd+Option+J (Mac).
    • Mozilla Firefox:
      • Right-click on the webpage and select "Inspect Element," then click on the "Console" tab.
      • Alternatively, press Ctrl+Shift+K (Windows/Linux) or Cmd+Option+K (Mac).
    • Safari:
      • First, enable the Develop menu by going to Safari > Preferences > Advanced and checking "Show Develop menu in menu bar."
      • Then, press Cmd+Option+C to open the Console.
    • Microsoft Edge:
      • Right-click on the webpage and select "Inspect," then click on the "Console" tab.
      • Alternatively, press Ctrl+Shift+I.
  2. Run the Script:

    • Copy the provided script.
    • Paste it into the console and press Enter to run it.

What the Script Does

  • The script makes an HTTP GET request to https://www.erepublik.com/en/main/job-data to find out how many energy and over time points are available to spend.
  • It parses the JSON response and logs it to the console for viewing.
  • It checks if overTime.points or overTime.usableEnergy in the response is zero.
  • If either is zero, the script stops making further requests.
  • This process repeats every 5 seconds.

Important Notes

  • Ensure you have a stable internet connection while running this script.
  • Be aware that making automated requests might not be allowed on all websites. Use this script responsibly and in compliance with the website's terms of service.
  • If the script does not work as expected, check if the website's API or response format has changed.

Troubleshooting

  • If the script does not run, ensure that you have copied and pasted it correctly into the console.
  • Check for any error messages in the console for clues on what might be wrong.

Script

setInterval(function(){var xhr=new XMLHttpRequest();xhr.open('GET','https://www.erepublik.com/en/main/job-data',true);xhr.setRequestHeader('authority','www.erepublik.com');xhr.setRequestHeader('accept','application/json, text/plain, */*');xhr.setRequestHeader('accept-language',navigator.language);xhr.setRequestHeader('cookie','erpk='+document.cookie.match(/erpk=([^;]+)/)[1]);xhr.setRequestHeader('referer',document.location.href);xhr.setRequestHeader('sec-ch-ua',navigator.userAgent);xhr.setRequestHeader('sec-ch-ua-mobile','?0');xhr.setRequestHeader('sec-ch-ua-platform',navigator.platform);xhr.setRequestHeader('sec-fetch-dest','empty');xhr.setRequestHeader('sec-fetch-mode','cors');xhr.setRequestHeader('sec-fetch-site','same-origin');xhr.setRequestHeader('sec-gpc','1');xhr.setRequestHeader('user-agent',navigator.userAgent);xhr.setRequestHeader('x-requested-with','XMLHttpRequest');xhr.onreadystatechange=function(){if(xhr.readyState===4&&xhr.status===200){var response=JSON.parse(xhr.responseText);console.log(response);if(response.overTime.points===0||response.overTime.usableEnergy===0){clearInterval(interval);}}};xhr.send();},5000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment