Refresh Unavailable

Auto refresh when pages are unavailable

目前為 2017-05-15 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Refresh Unavailable
  3. // @namespace iFantz7E.RefreshUnavailable
  4. // @description Auto refresh when pages are unavailable
  5. // @include *
  6. // @version 1.04
  7. // @grant none
  8. // @run-at document-start
  9. // @copyright 2016, 7-elephant
  10. // ==/UserScript==
  11.  
  12. (function ()
  13. {
  14. "use strict";
  15. // jshint multistr:true
  16. function attachOnLoad(callback)
  17. {
  18. window.addEventListener("load", function (e)
  19. {
  20. callback();
  21. });
  22. }
  23.  
  24. function attachOnReady(callback)
  25. {
  26. document.addEventListener("DOMContentLoaded", function (e)
  27. {
  28. callback();
  29. });
  30. }
  31.  
  32. function reload()
  33. {
  34. window.location.reload();
  35. }
  36.  
  37. function ready()
  38. {
  39. var isAvailable = true;
  40. if (document.body)
  41. {
  42. var child = document.body.firstChild;
  43. if (child && child.nodeType === 3 && child.textContent === "Service unavailable")
  44. {
  45. isAvailable = false;
  46. }
  47. }
  48. if (isAvailable)
  49. {
  50. if (document.title === "Network Error")
  51. {
  52. var eleBig = document.querySelector("body > blockquote:nth-child(2) > table:nth-child(1) "
  53. + " > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) "
  54. + " > font:nth-child(1) > big:nth-child(1)");
  55. if (eleBig && eleBig.textContent.trim() === "Network Error (tcp_error)")
  56. {
  57. isAvailable = false;
  58. }
  59. }
  60. }
  61. if (isAvailable)
  62. {
  63. var eleErr = document.querySelector("body > center:nth-child(1) > h1:nth-child(1)");
  64. if (eleErr && eleErr.textContent.trim() === "502 Bad Gateway")
  65. {
  66. isAvailable = false;
  67. }
  68. }
  69. if (isAvailable)
  70. {
  71. // Cloudflare
  72. var eleErr = document.querySelector(".cf-error-header-desc > h4");
  73. if (eleErr && eleErr.textContent.trim() === "Website is offline")
  74. {
  75. isAvailable = false;
  76. }
  77. if (isAvailable)
  78. {
  79. eleErr = document.querySelector(".cf-error-type");
  80. if (eleErr && eleErr.textContent.trim() === "Error")
  81. {
  82. isAvailable = false;
  83. }
  84. }
  85. }
  86. if (!isAvailable)
  87. {
  88. console.log("Autorefresh: Service unavailable");
  89. setTimeout(reload, 3000);
  90. }
  91. }
  92.  
  93. attachOnReady(function()
  94. {
  95. ready();
  96. });
  97.  
  98. })();
  99.  
  100. // End

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址