How to simulate Click in cronjob? - javascript

I'm using a web service to transfer files from ftp to dropbox. I want to update the version in dropbox every week. Right now I have to go into the service and manually click the 'transfer now' button every week.
I'd like to create a cron job or other automated solution that runs every week, logs into the service and clicks on a set of buttons with an interval of 60s between each button (to give the service enough time to start the action).
The buttons are nothing but a div with an id and an actual click on it triggers a JS listener.
The way I was going to approach this was to write a cURL script in php that loads the page and then tries to do the action that occurs when the button is pressed (i.e. triggers the listener). It's not easy though and before I spend too much time on it, I'd like to know if anyone can think of a simpler approach?
The basic structure of the process should be:
Runs automatically every week (e.g. on a LAMP server or using a web service)
Logs into service (simple form triggering a POST request)
Clicks on all the buttons with class 'buttonNow' and waits x amount of seconds between the clicks
Ideally it would send some kind of confirmation once the task has been completed

Related

Create a timer which will auto restart after every button click with the same information visible to all the users who are currently using the site

I am planning to develop a website which works completely based on a timer. This is basically for a discount sales. Here I might have a number of users participating at the same time where the timer is initialized to zero , and each time users click the discount button, the timer starts from 11 sec, counting down to zero. And if any users click the discount button in between, then again the timer needs to starts from 11 sec. And it will continue until when no users click the discount button. Here I am able to restart the timer, but its working is not synchronized in all browsers. Means, the timer that one users see in his browser is not same to the one another user see in his browser, that too for a same product, which all users are playing for. The concept is more of that of bidding only. Can anyone please help me with this?
Your site needs to not only to reset the counter when the button is clicked, but also check the counter during the countdown. So basically on a timer on the client side you'll need to make an AJAX call back to update the counter.
So on the client side:
- Start the counter when the page is loaded with the current value.
- React to a click of the Discount button by sending a message to the server with with an AJAX call or by reloading the page. Likely AJAX as you need it anyway for the next item.
- Check the server regularly for updates. Given we only have 11s, you are going to have to decide on timing. Every 3-4s might be best. Make an AJAX call back to get an update.
On the server side:
- Send out pages to clients with the current counter value to start with.
- React to a press of a Discount button by resetting the counter.
- React to an update request with a quick return of the state of the counter.
I think all of those steps are required to get this to work. How you do them exactly is up to you, especially seeing as you've provided no code or anything.

When the users are on the same webpage, is it possible that one user has clicked on a button and that will notify all other users?

Just like the title says. I want to create a shared online timer for my friends and say when one of my friends clicked the "refresh timer" button, ideally that all my other friends' page should get automatically refreshed with the new timer, or a notification saying that the timer has refreshed and require them to refresh the page.
I think at least the latter one is possible since when you get a comment of your question on Stackoverflow, you will get notified somewhere in the page telling you there's a new comment.
How to achieve this functionality? In JS or? Thanks in advance!
Javascript setInterval
using Javascript setInterval when the page is loaded, if you're not using MySQL, check a notepad for the text update(or whatever you want) and when it's found, clear it and then run whatever code
When the user presses a button, have it write to the file update(the same thing as above)
There would be 2 ways to go about it:
Simpler one would be to use polling through setInterval and look for changes on the backend.
A more accurate way would be to use Websockets which relay information to the clients that the timer has been reset.
Your choice of tool would depend on how complex you're willing to let it be

Send an alert from an open page to another (php, javascript, html)

I am developing a website that has a receptionist page and a user page with multiple user logins. The logged in users are displayed in a table at the receptionist page and one of the columns of the table is the status of the user ( ready or busy). The table is refreshed using ajax every 5 seconds to prevent the web page from refreshing. Each user can log in ( with thier own page) and change their status( ready to busy or busy to ready).
The table is stored in a sql database.
The user page has the option to change the state of the logged in user from ready to busy ( or vice verse) with a drop down menu and a submit button. What i need is to also send and alert or sound to the receptionist page whenever any user switches to the ready state.
I have looked all over the internet but none of the answers have worked for me.
Thanks for your replies. I understand that I could use ajax to query the database to see if a user is ready, however that will cause it to make a notification every time it checks. What i need is for the receptionist to be notified only 1 time each time that a user sets status to ready. I was thinking of making another table that gets updated every time a user changes their status to ready and time stamp it. So that if there is a change in the time stamp it means that some one newly updated it so the signal should be sent.
I made the table and made a php page that returns a string with the time stamp of the table but i dont know how to use the returned string in java script.
I figured it out. I made an SQL table with a time stamp, whenever any user sets their status to ready the time stamp gets updated. I made a java script that reads the time stamp every few seconds. If the time stamp is different than the initial time stamp then a sound is played.
#O.Rases gave you the best solution.I did something like this in past using ajax and php.
A solution can be the following.
1 Every 10s, sent a Ajax call to the server.
2 In the server, using php, you can select users that changed their status in the last 11s (+1s for time-consuming script in the server).
3 after selection is done, sent the user back to the receptionist page.
hope it helps

Previous form data getting posted along with the current data

I am creating an application which has a slide in and slide out window. This slide in and slide out window has a form which the user needs to fill. On click of the 'Save' button the POST request is fired. Everything goes well till here. But the second time when the user tries to post, there are 2 POST requests sent over network, the first request has the older data and the 2nd request carries the new data. Third time, when the user fills the form, 3 POST requests are sent.
I am using backbone to create this application, I tried cleaning up the views before sending the data, but that didn't work, can someone suggest me where am I going wrong?
Check your events and make sure that you don't have a submit event and a click event.
Also, if you are rendering the view several times, you might end up with several events attached to one button.
It would be helpful if you had some code so we could actually see what is going on. As #fbynite noted, you might also check your event bindings.

Score system based on time in Javascript

I have used a jQuery script in order to have a countdown script on a php page that I am doing, but I would also like to have a score system in it based on the time the user takes to answer some questions.
I am using some drag and drops and click in a certain link into an image map -which is the only correct link in the webpage- and in the three pages I am using this countdown, but I would like to, once the user has completed the drags&drops or clicked the links, get the number on the countdown just when the user clicked on a "submit" button...but I am not even sure if I can do this.
Alternatively, could I use any countdown script that would let me get the actual number that is being showed just when the user click on the submit button?
Thanks a lot everybody in advance!
Only use the javascript countdown for display purposes, you cannot trust the client.
Keep the count down server side. Store it in the SESSION variable, or in the database.
Javascript is insecure because the client can change it. I could save your page on my machine, open it up, and modify how the timer reports and you'd get a completely different time than you should get. I could also just change the variable using the browsers address bar. The client can always, always change anything in javascript, and you must, absolutely must rely on the server to keep your users honest.
Why not just stash the time (as a numeric value) when you want the timer to start, and then just check the difference when you want to know how long it's been? In other words, you've already got the client computer's clock counting, because that's what clocks do. Just remember what time it was when the drag&drop completes (or whatever point in time serves as your reference), and then check the time again in an event handler for the submit button.

Categories

Resources