Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var interval = 15000;
- $(document).ready(function()
- {
- var now = Date.now(); //get current miliseconds since jan 1970
- window.localStorage.setItem('LastKeepAlive',now); //store it in localstorage so it persists across reloads
- setInterval(logToSystem, interval);
- });
- function browserCheckForConnectionToAHK() {
- var lastCheck = window.localStorage.getItem('LastKeepAlive'); //bring in the var from localStorage
- var now = Date.now(); //get time in MS
- if(now - lastCheck > (interval*2)) { //if the last time we updated was more than 2x the interval, we assume we're disconnected
- alert('Disconnected ' + ((now-lastCheck)/1000) + ' seconds ago from page. Please reload the app');
- } else {
- //might want to log this to the system some how so we can identify what they were doing to get disconnected.
- }
- AHK('confirmBrowserConnection'); //Now we'll reach out to AHK and try to confirm we're still connected
- }
- function ahkStillConnected() { //called by AHK
- var now = Date.now(); //get current time
- window.localStorage.setItem('LastKeepAlive',now); //update our localStorage with this new time, so browserCheckForConnectionToAHK has updated time to compare
- var response = "success"; //we need to return a value to AHK to prevent a sleep loop.
- return response
- }
- /*********************** AHK **********************************/
- confirmBrowserConnection() {
- pageInst:=reconnectToPage() ;connect to the existing instance of chrome page
- response:=pageInst.Evaluate("ahkStillConnected()").value ;eval the func, grab the return value.
- wb.Disconnect() ;disconnect from page - if you don't do this, the script will die.
- }
- reconnectToPage() {
- pageInst:=Chrome.GetPage(,,,,"event_callBack") ;connect to the first page in Chrome index. As long as yuou have a single page app this should work.
- return pageInst
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement