Random target

Opens a random page of inactives

  1. // ==UserScript==
  2. // @name Random target
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024-10-23
  5. // @description Opens a random page of inactives
  6. // @author BollePapzak
  7. // @match https://www.torn.com/*
  8. // @icon https://torn.com/favicon.ico
  9. // @grant GM_registerMenuCommand
  10. // @grant GM_setValue
  11. // @grant GM_getValue
  12. // @license MIT
  13. // ==/UserScript==
  14.  
  15. console.log('randomtarget userscript loaded')
  16.  
  17. const maxLevelKey = 'maxLevel';
  18. const maxLevelDefault = 50;
  19.  
  20. function getRandomInt(min, max) {
  21. const minCeiled = Math.ceil(min);
  22. const maxFloored = Math.floor(max);
  23. return Math.floor(Math.random() * (maxFloored - minCeiled) + minCeiled); // The maximum is exclusive and the minimum is inclusive
  24. }
  25.  
  26. GM_registerMenuCommand('Update max level', () => {
  27. let userInput = prompt("Enter preferred max level", GM_getValue(maxLevelKey, maxLevelDefault));
  28. if (userInput !== null) {
  29. const parsedNumber = Number.parseInt(userInput);
  30. if (isNaN(parsedNumber)) {
  31. alert(`${userInput} is not a valid number`)
  32. return
  33. }
  34. GM_setValue(maxLevelKey, parsedNumber);
  35. }
  36. })
  37.  
  38. GM_registerMenuCommand('Goto random target list', () => {
  39. const maxLevel = GM_getValue(maxLevelKey, maxLevelDefault);
  40. const pageStart = getRandomInt(100 * 25, 55000*25);
  41. const url = `https://www.torn.com/page.php?sid=UserList&levelFrom=1&levelTo=${maxLevel}&lastAction=7#start=${pageStart}`;
  42. window.location.replace(url);
  43. })