PDA

View Full Version : Help me edit this GM script?



Infiniti
10-12-2017, 03:12 PM
I'll apologize in advance, I don't know any programming languages well. xD That being said;

I came across this Neocola machine script. After it gets your prize, you have the manually click "Play again", then "Onward". I wanted to add a redirect link from /neocola3 back to /neocola 2 to allow the script to loop until all the tokens are used.

LINK TO SCRIPT ([Only registered and activated users can see links])

I tried adding

redirectToPage("[Only registered and activated users can see links]", "[Only registered and activated users can see links]");

function redirectToPage(page1, page2){
if(window.location.href.indexOf(page1) != -1){
window.location.href = page2;
}
}


To the script, but it seemed to have no effect. Anyone know what I'm doing wrong, or perhaps a different remedy to this problem? I know we could edit it so it clicks both buttons, but I think it would be easier to just link back to the previous page. I feel like this is pretty simple, but my lack of knowledge is showing. :P +rep for help, and we can add the script to the GM script repository when finished to help everyone else. :) Thanks in advance, I'll keep working on it for the time being. xD

EDIT: Oh hey I got it working. :D I'll post the script in a few minutes after I change the timing.

Accelerator
10-12-2017, 03:18 PM
// ==UserScript==
// name Neocola Machine APer
// namespace Neocola Machine APer
[Only registered and activated users can see links]
// Description Selects a random combination at the Neocola Machine
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
// ==/UserScript==

var butt = document.getElementsByTagName('input');

//Selects Random Token
var elements = document.getElementsByName('token_id');
for(var i = 0; i < elements.length; ++i){
var max = elements[i].length;
max = parseInt(max)
max = max-1;
var tempN = Math.floor((Math.random()*max)+1);
elements[i].selectedIndex = tempN;
}

// Predefined Combo
// Selects Combination
var selCriteria = document.querySelector("select[name=neocola_flavor]");
if (selCriteria != null) selCriteria.selectedIndex = 6;
var selCriteria = document.querySelector("select[name=red_button]");
if (selCriteria != null) selCriteria.selectedIndex = 4;


/* // Random Combo
// var selCriteria = document.querySelector("select[name=neocola_flavor]");
// if (selCriteria != null) selCriteria.selectedIndex = 3;
var elements = document.getElementsByName('neocola_flavor');
for(var i = 0; i < elements.length; ++i){
var max = elements[i].length;
max = parseInt(max)
max = max-1;
var tempN = Math.floor((Math.random()*max)+1);
elements[i].selectedIndex = tempN;
}
// var selCriteria = document.querySelector("select[name=red_button");
// if (selCriteria != null) selCriteria.selectedIndex = 2;
var elements = document.getElementsByName('red_button');
for(var i = 0; i < elements.length; ++i){
var max = elements[i].length;
max = parseInt(max)
max = max-1;
var tempN = Math.floor((Math.random()*max)+1);
elements[i].selectedIndex = tempN;
} */
//Presses buttons
for(var j = 0; j < butt.length; ++j) {
if (butt[j].value == "Onward!")
{
setTimeout(777);
butt[j].click();
}
}
for(var j = 0; j < butt.length; ++j) {
if (butt[j].value == "Continue to your doom...")
{
setTimeout(777);
butt[j].click();
}
}
for(var j = 0; j < butt.length; ++j) {
if (butt[j].value == "Play Again!")
{
setTimeout(777);
butt[j].click();
}
}


console.log(butt);

Infiniti
i made that for myself like 3 years ago, it just clicks buttons and randomly selects stuff from the drop-down lists
Right now it's set to use a pre-defined combination, if you want a random one comment the entire section from line 24 to 29 and uncomment from 32 to 52.

Infiniti
10-12-2017, 03:46 PM
// ==UserScript==
// name Neocola Machine APer
// namespace Neocola Machine APer
[Only registered and activated users can see links]
// Description Selects a random combination at the Neocola Machine
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
// ==/UserScript==

var butt = document.getElementsByTagName('input');

//Selects Random Token
var elements = document.getElementsByName('token_id');
for(var i = 0; i < elements.length; ++i){
var max = elements[i].length;
max = parseInt(max)
max = max-1;
var tempN = Math.floor((Math.random()*max)+1);
elements[i].selectedIndex = tempN;
}

// Predefined Combo
// Selects Combination
var selCriteria = document.querySelector("select[name=neocola_flavor]");
if (selCriteria != null) selCriteria.selectedIndex = 6;
var selCriteria = document.querySelector("select[name=red_button]");
if (selCriteria != null) selCriteria.selectedIndex = 4;


/* // Random Combo
// var selCriteria = document.querySelector("select[name=neocola_flavor]");
// if (selCriteria != null) selCriteria.selectedIndex = 3;
var elements = document.getElementsByName('neocola_flavor');
for(var i = 0; i < elements.length; ++i){
var max = elements[i].length;
max = parseInt(max)
max = max-1;
var tempN = Math.floor((Math.random()*max)+1);
elements[i].selectedIndex = tempN;
}
// var selCriteria = document.querySelector("select[name=red_button");
// if (selCriteria != null) selCriteria.selectedIndex = 2;
var elements = document.getElementsByName('red_button');
for(var i = 0; i < elements.length; ++i){
var max = elements[i].length;
max = parseInt(max)
max = max-1;
var tempN = Math.floor((Math.random()*max)+1);
elements[i].selectedIndex = tempN;
} */
//Presses buttons
for(var j = 0; j < butt.length; ++j) {
if (butt[j].value == "Onward!")
{
setTimeout(777);
butt[j].click();
}
}
for(var j = 0; j < butt.length; ++j) {
if (butt[j].value == "Continue to your doom...")
{
setTimeout(777);
butt[j].click();
}
}
for(var j = 0; j < butt.length; ++j) {
if (butt[j].value == "Play Again!")
{
setTimeout(777);
butt[j].click();
}
}


console.log(butt);

Infiniti
i made that for myself like 3 years ago, it just clicks buttons and randomly selects stuff from the drop-down lists
Right now it's set to use a pre-defined combination, if you want a random one comment the entire section from line 24 to 29 and uncomment from 32 to 52.

Very nice, thank you. I knew someone had already made one, but I searched around and couldn't find one so I figured I would edit the one already out there. I was trying to get the setTimeout to work for the redirect on mine, but was struggling with it. I scrapped my project as yours is perfect for me. Thanks again bro.