LOLZ_Refresh

Lolz Auto Refresh

  1. // ==UserScript==
  2. // @name LOLZ_Refresh
  3. // @namespace Lolz Auto Refresh
  4. // @description Lolz Auto Refresh
  5. // @version 0.5
  6. // @author el9in
  7. // @license el9in
  8. // @match https://zelenka.guru
  9. // @match https://lolz.guru
  10. // @match https://lolz.live
  11. // @match https://zelenka.guru/*
  12. // @match https://lolz.guru/*
  13. // @match https://lolz.live/*
  14. // @icon https://www.google.com/s2/favicons?sz=64&domain=zelenka.guru
  15. // @grant GM.setValue
  16. // @grant GM.getValue
  17. // ==/UserScript==
  18.  
  19. (async function() {
  20. 'use strict';
  21. const autoReloadTimeout = 5000; // Автоматическая перезагрузка в МС 1000 мс = 1 секунда
  22. const reloadButton = document.querySelector(".UpdateFeedButton");
  23. let _timer = null;
  24. if(reloadButton) {
  25. let _refresh = await GM.getValue("LZT_Auto_Refresh");
  26. let spanElement = document.createElement('span');
  27. spanElement.className = 'fa fa-clock lolzauthrefresh';
  28. spanElement.title = 'Обновить ленту';
  29. spanElement.style.marginLeft = '15px';
  30. spanElement.style.padding = '11px';
  31. reloadButton.parentNode.insertBefore(spanElement, reloadButton.nextSibling);
  32. spanElement.addEventListener('click', function() {
  33. set();
  34. });
  35. function set() {
  36. if(_timer) {
  37. GM.setValue("LZT_Auto_Refresh", 0);
  38. clearInterval(_timer);
  39. _timer = null;
  40. XenForo.alert('Автоматическое обновление отключено.', "LOLZ Auto Refresh", 2000);
  41. } else {
  42. GM.setValue("LZT_Auto_Refresh", 1);
  43. _timer = setInterval(click, autoReloadTimeout);
  44. XenForo.alert('Автоматическое обновление активировано.', "LOLZ Auto Refresh", 2000);
  45. }
  46. }
  47. function click() {
  48. if(document.hasFocus()) reloadButton.click();
  49. }
  50. document.addEventListener('keydown', function(event) {
  51. if (event.altKey && event.keyCode === 53) {
  52. set();
  53. } else if(event.keyCode === 53) {
  54. click();
  55. XenForo.alert('Обновили страницу.', "LOLZ Auto Refresh", 2000);
  56. }
  57. });
  58. if(autoReloadTimeout > 2000 && _refresh) _timer = setInterval(click, autoReloadTimeout)
  59. }
  60. })();