DC_auto_refresh

Refresh the windows if no network activity for a while.

当前为 2015-07-17 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name DC_auto_refresh
  3. // @author Ladoria
  4. // @version 0.4
  5. // @grant none
  6. // @description Refresh the windows if no network activity for a while.
  7. // @match http://www.dreadcast.net/Main
  8. // @copyright 2015+, Ladoria
  9. // @namespace InGame
  10. // ==/UserScript==
  11.  
  12. var last_request = new Date();
  13. var last_refresh = new Date();
  14. var request_time_limit = 20000; // In ms. Time limit to refresh.
  15. var refresh_time_limit = 10000; // In ms. Time limit to refresh again.
  16.  
  17. $(document).ready( function() {
  18. setInterval( function() {
  19. var date_now = new Date().getTime();
  20. // If no network activity for a while, reload.
  21. if (date_now - last_request.getTime() >= request_time_limit) {
  22. // If reload failed, waiting for a while.
  23. if (date_now - last_refresh.getTime() >= refresh_time_limit) {
  24. last_refresh = new Date();
  25. window.location.reload();
  26. }
  27. }
  28. }, 1000);
  29. // Update last request time
  30. $(document).ajaxComplete( function(a,b,c) {
  31. last_request = new Date();
  32. });
  33. });
  34. console.log('DC - Auto Refresh started');