Auto Refresh with Pop-out GUI

Automatically refreshes the page every 20 seconds with start/stop functionality and a pop-out GUI.

  1. // ==UserScript==
  2. // @name Auto Refresh with Pop-out GUI
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Automatically refreshes the page every 20 seconds with start/stop functionality and a pop-out GUI.
  6. // @author Your Name
  7. // @match *://*/*
  8. // @grant none
  9. // @license All
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Create a container for the GUI
  16. const guiContainer = document.createElement('div');
  17. guiContainer.style.position = 'fixed';
  18. guiContainer.style.bottom = '10px';
  19. guiContainer.style.right = '10px';
  20. guiContainer.style.zIndex = '9999';
  21. guiContainer.style.backgroundColor = 'white';
  22. guiContainer.style.border = '1px solid #ccc';
  23. guiContainer.style.padding = '10px';
  24. guiContainer.style.borderRadius = '5px';
  25. guiContainer.style.boxShadow = '0 2px 5px rgba(0,0,0,0.2)';
  26. guiContainer.style.cursor = 'pointer';
  27. guiContainer.textContent = 'Refresh Page';
  28.  
  29. // Create start button
  30. const startButton = document.createElement('button');
  31. startButton.textContent = 'Start';
  32. startButton.style.marginRight = '10px';
  33. startButton.onclick = startRefresh;
  34. guiContainer.appendChild(startButton);
  35.  
  36. // Create stop button
  37. const stopButton = document.createElement('button');
  38. stopButton.textContent = 'Stop';
  39. stopButton.onclick = stopRefresh;
  40. guiContainer.appendChild(stopButton);
  41.  
  42. document.body.appendChild(guiContainer);
  43.  
  44. let intervalId;
  45.  
  46. function startRefresh() {
  47. stopRefresh(); // Stop any existing refresh interval
  48.  
  49. intervalId = setInterval(function() {
  50. location.reload();
  51. }, 20000); // 20 seconds
  52. }
  53.  
  54. function stopRefresh() {
  55. clearInterval(intervalId);
  56. }
  57.  
  58. // Toggle pop-out GUI on click
  59. let isExpanded = false;
  60. guiContainer.addEventListener('click', function() {
  61. if (isExpanded) {
  62. guiContainer.style.bottom = '10px';
  63. guiContainer.style.right = '10px';
  64. } else {
  65. guiContainer.style.bottom = 'auto';
  66. guiContainer.style.right = 'auto';
  67. guiContainer.style.top = '10px';
  68. guiContainer.style.left = '10px';
  69. }
  70. isExpanded = !isExpanded;
  71. });
  72. })();