Random target

Opens a random page of inactives

当前为 2024-10-23 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Random target
// @namespace    http://tampermonkey.net/
// @version      2024-10-23
// @description  Opens a random page of inactives
// @author       BollePapzak
// @match        https://www.torn.com/*
// @icon         https://torn.com/favicon.ico
// @grant        GM_registerMenuCommand
// @grant        GM_setValue
// @grant        GM_getValue
// @license      MIT
// ==/UserScript==

console.log('randomtarget userscript loaded')

const maxLevelKey = 'maxLevel';
const maxLevelDefault = 50;

function getRandomInt(min, max) {
  const minCeiled = Math.ceil(min);
  const maxFloored = Math.floor(max);
  return Math.floor(Math.random() * (maxFloored - minCeiled) + minCeiled); // The maximum is exclusive and the minimum is inclusive
}

GM_registerMenuCommand('Update max level', () => {
    let userInput = prompt("Enter preferred max level", GM_getValue(maxLevelKey, maxLevelDefault));
    if (userInput !== null) {
        const parsedNumber = Number.parseInt(userInput);
        if (isNaN(parsedNumber)) {
            alert(`${userInput} is not a valid number`)
            return
        }
        GM_setValue(maxLevelKey, parsedNumber);
    }
})

GM_registerMenuCommand('Goto random target list', () => {
    const maxLevel = GM_getValue(maxLevelKey, maxLevelDefault);
    const pageStart = getRandomInt(100 * 25, 55000*25);
    const url = `https://www.torn.com/page.php?sid=UserList&levelFrom=1&levelTo=${maxLevel}&lastAction=7#start=${pageStart}`;
    window.location.replace(url);
})