-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathracing_save_custom_settings.user.js
More file actions
72 lines (65 loc) · 2.89 KB
/
racing_save_custom_settings.user.js
File metadata and controls
72 lines (65 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// ==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);
})();