Skip to content
TORNLIFE More

Save Custom Race Settings (script help)

Started by Lick_My_Muff [3927175] on in Racing.

0 replies · 44 views · thread synced · 6 days ago · View on torn.com
About this thread

Posts archived: 1 / 1 posts (100%) · the total is Torn's reply count + the opening post at the last fetch

Counted by TornLife from the archived posts.

Archived posts
1
Discussion span
→
People posting
1
Likes on archived posts
0
Authority score
33 / 100
Historical score
15 / 100
Story score
28 / 100
Engagement score
33 / 100
Lick_My_Muff [3927175]

Hi, I'm doing a bunch of 1 lap Speedway runs and it looks like this will add a preset button, I just don't know where to enter the values in the script. If it all works (and is allowed) I would love some help.

 

Here's the full script:

 

// ==UserScript==
// @name         Torn: Racing: Save custom race settings
// @namespace    lugburz.racing.save_custom_settings
// @version      0.1.4
// @description  Saves and automatically loads custom race settings.
// @author       Lugburz
// @match        https://www.torn.com/loader.php?sid=racing*
// @match        https://www.torn.com/page.php?sid=racing*
// @require      https://raw.githubusercontent.com/f2404/torn-userscripts/master/lib/lugburz_lib.js
// @grant        GM_setValue
// @grant        GM_getValue
// ==/UserScript==

function setMenuValue(menu, value) {
    $(menu).val(value);
    $(menu).click();
    $(menu).change();
}

function loadSave() {
    if ($('#racingAdditionalContainer').find('div.title-black').text().trim() == 'Start a custom race') {
        let racename = $('#racename');
        let minDrivers = $('#createCustomRace').find('li.drivers-wrap').find('input[type=text]');
        let maxDrivers = $('#createCustomRace').find('li.drivers-max-wrap').find('input[type=text]');
        let track = $('#select-racing-track');
        let laps = $('#createCustomRace').find('li.laps-wrap').find('input[type=text]');
        let cars = $('#select-racing-cars');
        let upgrades = $('#select-allow-upgrades');
        let betAmount = $('#betAmount');
        let waitTime = $('#waitTime');
        let password = $('#password');

        if (GM_getValue('saved')) {
            $(racename).val(GM_getValue('racename'));
            $(minDrivers).val(GM_getValue('minDrivers'));
            $(maxDrivers).val(GM_getValue('maxDrivers'));
            setMenuValue(track, GM_getValue('track'));
            $(laps).val(GM_getValue('laps'));
            setMenuValue(cars, GM_getValue('cars'));
            setMenuValue(upgrades, GM_getValue('upgrades'));
            $(betAmount).val(GM_getValue('betAmount'));
            $(waitTime).val(GM_getValue('waitTime'));
            $(password).val(GM_getValue('password'));
        }

        $('#racingAdditionalContainer').find('div.custom-btn-wrap').find('input.btn-action-form').on('click', function() {
            GM_setValue('saved', 1);
            GM_setValue('racename', $(racename).val());
            GM_setValue('minDrivers', $(minDrivers).val());
            GM_setValue('maxDrivers', $(maxDrivers).val());
            GM_setValue('track', $(track).val());
            GM_setValue('laps', $(laps).val());
            GM_setValue('cars', $(cars).val());
            GM_setValue('upgrades', $(upgrades).val());
            GM_setValue('betAmount', $(betAmount).val());
            GM_setValue('waitTime', $(waitTime).val());
            GM_setValue('password', $(password).val());
        });
    }
}

(function() {
    'use strict';

    // Your code here...
    ajax((page) => {
        if (page !== 'loader' && page !== 'page') return;
        $('#racingAdditionalContainer').ready(loadSave);
    });

    $('#racingAdditionalContainer').ready(loadSave);
})();