How to create an auto click button - html

I have a list of cases in the queue that I need to grab. As you can imagine, it's a bit repetitive and time consuming. I'm new at programming and haven't figured a way to create a script that auto-click/grab these cases. Can someone help?
Code to:
1) Search and Click "Grab"
- will take 4 seconds for the page to refresh
2) Click grab again
3) stop after 50 cases are grabbed
This code doesn't work
window.setTimeout("pushSubmit()",3000);
function pushSubmit()
{document.getElementById('Grab').click();

Assuming your page is not refreshed in the process, you could keep a counter of how many "Grabs" you have done:
var counter = 0;
var maxCount = 50;
function pushSubmit() {
if(counter++ < maxCount) {
document.getElementById('Grab').click();
window.setTimeout(pushSubmit,3000);
}
}
//start the process
pushSubmit();
Here is a jsfiddle example
EDIT:
Or what I would probably prefer, set up the function so it can be used with any number of iterations.
function pushSubmit(max, count) {
count = typeof count !== 'undefined' ? count : 1;
if(count <= max) {
document.getElementById('Grab').click();
window.setTimeout(function() { pushSubmit(max, ++count) },3000);
}
}
//start the process with the max number of iterations it should perform
pushSubmit(50);
Example

Related

Save Number with Shared Object and Add to that Saved Number.

Hey everyone so basically what I am trying to accomplish is saving a number with the Shared Object which the the coins that the player collects in the game and if they player quits out of the game and comes back to play again the amount of coins he had when he quit will still show and he will be able to add to that amount if the player picks up more coins. I had this working for a bit but then the textfield started displaying "NAN".
Here is how I have it set up.
The Variable private var nCoins:Number;
In the constructor function I have:
sharedObjectCoins = SharedObject.getLocal("CoinsData");
nCoins = 0 + sharedObjectCoins.data.tCoins;
if (sharedObjectCoins.data.tCoins == null)
{
sharedObjectCoins.data.tCoins = nCoins;
}else
{
trace("Save data found."); // if we did find data...
loadDataTimeAttack(); // ...load the data
}
and in the games Enter.Frame Loop I have the function saveDataCoins which is setup like so:
private function saveDataCoins():void
{
if (nCoins > sharedObjectCoins.data.tCoins )
{
sharedObjectCoins.data.tCoins = nCoins;
}
coinsGraphic.coinsText.text = " " + sharedObjectCoins.data.tCoins;
sharedObjectCoins.flush();
}
not sure if you need the function to where the hitTest takes place between the coins and player but here it is:
private function checkPlayerHitCoins():void
{
for (var i:int = 0; i < aCoinsArray.length; i++)
{
//get current point in i loop
var currentCoins:mcCoin = aCoinsArray[i];
//test if player is hitting current point
if(player.hitTestObject(currentCoins))
{
nCoins += 1;
updatecoinsTextScore();
updateCoinsPauseScreen();
//Add points sound effects
var coinsSEffect:Sound = new coinsSound();
coinsSEffect.play();
//remove point on stage
currentCoins.destroyCoins();
//remove points from array
aCoinsArray.splice(i, 1);
trace("Hit: " + aCoinsArray.length);
}
}
}
Please if anyone could help me with this maybe point something out that I am doing wrong. This code worked perfect one time and when I closed the screen and came back to re test it the textfield displayed NAN and thats it when I hitTest the coins sometimes the NAN switches to a number for like a second but then goes back to NAN.
The first time (or rather every time it creates a new shared object) you will be trying to add undefined to 0, which will result in either a runtime error or NaN.
You need to check if the value exists before attempting to do addition with it.
if(sharedObjectCoints.data && sharedObjectCoins.data.tCoins && !isNaN(sharedObjectCoins.data.tCoins)){
nCoins = Number(sharedObjectCoins.data.tCoins); //there's not point in adding 0
trace("Save data found."); // if we did find data...
loadDataTimeAttack(); // ...load the data
}else{
sharedObjectCoins.data.tCoins = nCoins;
}
Also, if you don't manually set a value to a number var, it will start off life as NaN. eg var nCoins:Number will be NaN until you set it to something.
That said, working with the sharedObject directly like this is a very sloppy way to code your program. Really you should just use shared object to load and save the value, and everything in between use a strongly typed variable.
var nCoins:int = 0;
var tCoins:int = 0;
sharedObjectCoins = SharedObject.getLocal("CoinsData");
if(sharedObjectCoins.data && sharedObjectCoins.data.tCoins && !isNaN(sharedObjectCoins.data.tCoins){
tCoins = int(sharedObjectCoins.data.tCoins);
}else{
//no shared object, use default value for tCoins
tCoins = 0; //or whatever it should start off as.
}
Then write a save function
private function saveSharedObject():void {
sharedObjectCoins.data.tCoins = tCoins;
sharedObjectCoins.flush();
}
Then replace all other instances of sharedObjectCoins.data.tCoins with the var tCoins
It's probably best not to flush the shared object every frame for performance purposes.
Also, shared objects may or may not actually save, depending on user preferences, storage space available, etc. They should not be relied upon for critical data retention.
You can listen for problems with the shared object with AsyncErrorEvent.ASYNC_ERROR I believe (It's been a while since I've worked with AS3 Shared Objects)

Count how many times a function is called

I'm making a game in AS3.
I was wondering if it's possible to count how many times a function is called and do something when it has been called 5 times for exemple. (and then it's restarting to count at 0).
If we take an exemple, what would it be ?
Somethink like :
movieClip.addEventListener(MouseEvent.CLICK, functionExemple, false, 0, true);
function functionExemple(e:MouseEvent):void{
//do something;
count 1;
if (count = 5){
doThat();
count = 0;
}
So the function doThat would be called every 5 times.
I know the code is wrong. It's just in order to explain as good as possible what I meant.
Thank you for your help,
There are some errors in your example.
var count:int=0; //variable declaration
function functionExemple(e:MouseEvent):void{
//do something;
count++;//<=>count 1;
if (count == 5){//<=>if (count = 5){
doThat();
count = 0;
}
}
My initial guess would be to set a global variable that acts as a counter then when the function is called - increment its value. When value hits 5 take action. I would also guess using some form of "getter" to get the counter value would also help. This is my initial stab at it.

Gmail Snooze error: moveSnoozes "service invoked too many times in a short time"

I trying to find a way to snooze e-mail in my Gmail. Yes, I had Mailbox.app on my iDevice, but I want a way to Snooze or "Laterize" some emails.
I found a Blog Spot post and a Lifehacker one. The Lifehacker article just adds more pictures to the Blog Sport one. I followed the Lifehacker instructions. I made only one deviation from the code. In the two instances that the code says "7", I replaced it with "200".
The code I have is:
var MARK_UNREAD = false;
var ADD_UNSNOOZED_LABEL = false;
function getLabelName(i) {
return "Snooze/Snooze " + i + " days";
}
function setup() {
// Create the labels we’ll need for snoozing
GmailApp.createLabel("Snooze");
for (var i = 1; i <= 200; ++i) {
GmailApp.createLabel(getLabelName(i));
}
if (ADD_UNSNOOZED_LABEL) {
GmailApp.createLabel("Unsnoozed");
}
}
function moveSnoozes() {
var oldLabel, newLabel, page;
for (var i = 1; i <= 200; ++i) {
newLabel = oldLabel;
oldLabel = GmailApp.getUserLabelByName(getLabelName(i));
page = null;
// Get threads in "pages" of 100 at a time
while(!page || page.length == 100) {
page = oldLabel.getThreads(0, 100);
if (page.length > 0) {
if (newLabel) {
// Move the threads into "today’s" label
newLabel.addToThreads(page);
} else {
// Unless it’s time to unsnooze it
GmailApp.moveThreadsToInbox(page);
if (MARK_UNREAD) {
GmailApp.markThreadsUnread(page);
}
if (ADD_UNSNOOZED_LABEL) {
GmailApp.getUserLabelByName("Unsnoozed")
.addToThreads(page);
}
}
// Move the threads out of "yesterday’s" label
oldLabel.removeFromThreads(page);
}
}
}
}
But I'm getting an error:
Your script, Gmail Snooze, has recently failed to finish
successfully. A summary of the failure(s) is shown below.
Details:
Start: 9/10/13 12:16 AM
Function: moveSnoozes
Error Message: Service invoked too many times in a short time: gmail rateMax. Try Utilities.sleep(1000) between calls. (line 24, file "Code")
Trigger: time-based
End: 9/10/13 12:22 AM
Does anybody know how I can make use of Utilities.sleep(1000)? Where do I type that in?
The error you got is because creating 200 labels at the speed-of-code is too fast for Gmail and considered abuse of it's API. SO, as the error message suggests, you could use Utilities.sleep(1000) to wait a second between each label creation.
I'm not familiar with the script (Boomerang works well for me), but you might try making your 30, 60, 90 180 day labels by hand and letting the script pick up on them. Then you don't need to worry about the label creation at all.
In an effort to help you better understand the code you are reading. Below is an explanation of what's going on and how to insert the Utilities.sleep(). You will need to decide for how long you want to wait 1000ms means that you're waiting for 200 seconds, and if you have 3 min to spare that will do just fine. You could experiment to see at what point the Gmail app says 'Woah that's enough there. Take it slower please.'
NOTE: I am not attempting to re-engineer this to allow for a better creation/management of labels. There are a probably a number of enhancements that can be made to the code, and although tempting, they will be left as an exercise for the reader.
RE your pastie:
function setup() {
// This creates 1 label called "Snooze"
// it probably isn't causing the problem
GmailApp.createLabel("Snooze");
// This piece is a loop that will execute 200 times.
// It will do so as fast as GAS will let it.
// This is probably where the problem is...
for (var i = 1; i <= 200; ++i) {
// Create the label
GmailApp.createLabel(getLabelName(i));
// We should wait a bit before making the next one
// Utilities.sleep() will do well to go here
Utilities.sleep(/*Milliseconds to wait*/);
}
// I doubt this is causing the problem either.
// It's only one label creation
if (ADD_UNSNOOZED_LABEL) {
GmailApp.createLabel("Unsnoozed");
}
}

Game Simulator Times Out

This is my first post on here. Thank you in advance for taking the time to read my question.
I am a novice coder. I have a minor in Computer Science that I got a decade ago. I had an urge to do some simple coding, and an opportunity came up, so I did!
In developing a game, I wanted to run a program to determine the chances of given outcomes with given parameters. I excitedly reached the point where it was a go, but Google Scripts couldn't handle running the 60,000,000 possible scenarios in order to compute a win%.
I got, "error: Exceeded maximum execution time."
I'm just trying to find the shortest path between me and running this program. Ideas:
1) Is there a way to remove the maximum execution time and let it just take all day? Is there some other way I can get it to run in Google Scripts?
2) Perhaps I can run a smaller number of trials by inputing random numbers. Is there a way to generate random numbers in Google Scripts?
3) Should I be doing this kind of thing in something besides Google Scripts? If so, is there a free/affordable compiler for Mac I should look into? I tried importing it into Xcode, but I'm bewildered and can't seem to get to a simple place to compile. Also, importing it to "C" is creating some compatibility issues; though I may just have to suck it up and retool it here.
For reference, here's the function that's timing it out:
function dieFeeder(winCount, fSkill, fMagnitude, fHeart, fDie1, fDie2, fDie3, fDie4, fDie5, cSkill, cMagnitude, cHeart, cDie1, cDie2, cDie3, cDie4, cDie5){
// a parent function to function questionMatrix, feeds the changing dice into it
var matrixWinner;
//This 'for' clause keeps going until all dice permutations have been tried out
for (var i=0; i<60466176; i++){
//This part changes the dice to go through all combiations in a way similar to counting in base 6
if (cDie5 == 7){
cDie5 = 1;
cDie4 = cDie4+1;
}
if (cDie4 == 7){
cDie4 = 1;
cDie3 = cDie3 +1;
}
if (cDie3 == 7){
cDie3 = 1;
cDie2 = cDie2 +1;
}
if (cDie2 == 7){
cDie2 = 1;
cDie1 = cDie1 +1;
}
if (cDie1 == 7){
cDie1 = 1;
fDie5 = fDie5 +1;
}
if (fDie5 == 7){
fDie5 = 1;
fDie4 = fDie4 +1;
}
if (fDie4 == 7){
fDie4 = 1;
fDie3 = fDie3 +1;
}
if (fDie3 == 7){
fDie3 = 1;
fDie2 = fDie2 +1;
}
if (fDie2 == 7){
fDie2 = 1;
fDie1 = fDie1 +1;
}
cDie5 = cDie5 + 1;
//This part checks to see who wins and increases the winCount if it was the Favorite
matrixWinner = questionMatrix(fSkill, fMagnitude, fHeart, fDie1, fDie2, fDie3, fDie4, fDie5, cSkill, cMagnitude, cHeart, cDie1, cDie2, cDie3, cDie4, cDie5);
if (matrixWinner == 'favorite'){
winCount = winCount +1;
}
}
return winCount;
}
There is no way to lift the maximum execution time. The limit is there so that other users (like me) can have time to run our scripts too! The solution to this problem is to break up your problem into many subproblems.
One solution would be to continue executing your script while your running time is under some threshold (say, 3 minutes) (i.e. keep track of how long your script has been running). Then save all state relating to your script (variables, etc.). Save these to ScriptDb. Then have your script run on a 5-minute trigger. When your script runs again, it reads the values from ScriptDb and picks up where it left off.
If you're looking for random numbers, use Math.random(). Google Apps Scripts is built off of javascript, so basic javascript functions are available.
Relating to my answer to #2, what you have shown is entirely javascript, so you can just copy your code over to some webpage to run it. (For testing, you can use jsfiddle).
Also you need to define if (cDie5 == 7){

Checking for same values using if statement in actionscript?

I'm working on a match-3 style puzzle game using Flixel, and so I'm working on checking each row and column to see if there is a match at any given time. However, I have 6 different pieces (as of right now) that are active, and each piece is identified by an integer. Given that, I can check, for each and every single piece, by doing something like this:
public function matchingCheck():void
{
if (piecesArray[0][1] == 1 && piecesArray[1][1] == 1 && piecesArray[2][1] == 1) {
FlxG.log("Yay!");
}
}
However, this is rather unwieldy and would basically cause way too much repetition for my liking.
At the very least, I would like to be able to check if the values in these arrays are equal to one another, without having to specify which value it is. At the very best, I'd love to be able to check an entire row for three (or more) adjacent pieces, but I will settle for doing that part manually.
Thanks for your help!
EDIT: Nevermind, my edit didn't work. It was just checking if piecesArray[2][1] == 1, which makes me a sad panda.
EDIT 2: I've selected the correct answer below - it's not exactly what I used, but it definitely got me started. Thanks Apocalyptic0n3!
You could cut down on that code a little bit by using another function
private function checkValid( arrayOfItemsToCheck:Array, value:* ):Boolean {
for ( var i:Number = 0; i < arrayOfItemsToCheck.length; i++ ) {
if ( arrayOfItemsToCheck[i] != value ) {
return false;
}
}
return true;
}
Then you just do this in your if statement:
if ( checkValid( [ piecesArray[0][1], piecesArray[1][1], piecesArray[2][1] ], 1 ) ) {
FlxG.log("Yay!");
}
That does assume all items need to be equal to 1, though. It's still a lot of code, but it cuts out one set of "= 1 &&" for each check.
How about something like this which would tell you both if a match existed and what match it was:
public function checkForMatch():void{
var rows:int = piecesArray.length;
for(var i:int=0; i<rows; i++){
var match:int = checkRow(piecesArray[i]);
if(match > -1) {
FlxG.log("Yay you matched " + match);
}
}
}
private function ckeckRow(row:Array):int{
if(row[0] == row[1] == row[2]){
return row[0];
}
return -1;
}