Greasy Fork is available in English.

Auto Refresh Twitter (X) Timeline

Automatically refreshes the Twitter (X) timeline every 5 seconds without refreshing the tab.

Nainstalovat skript?
Skript doporučený autorem

Mohlo by se vám také líbit YouTube - Remaining Time Indicator.

Nainstalovat skript
  1. // ==UserScript==
  2. // @name Auto Refresh Twitter (X) Timeline
  3. // @name:fr Actualisation automatique de la timeline Twitter (X)
  4. // @name:es Actualización automática de la línea de tiempo de Twitter (X)
  5. // @name:de Automatische Aktualisierung der Twitter (X) Timeline
  6. // @name:it Aggiornamento automatico della timeline di Twitter (X)
  7. // @name:zh-CN 自动刷新 Twitter (X) 时间轴
  8. // @namespace https://gist.github.com/4lrick/bedb39b069be0e4c94dc20214137c9f5
  9. // @version 2.4
  10. // @description Automatically refreshes the Twitter (X) timeline every 5 seconds without refreshing the tab.
  11. // @description:fr Actualise automatiquement la timeline Twitter (X) toutes les 5 secondes sans rafraîchir l'onglet.
  12. // @description:es Refresca automáticamente el timeline de Twitter (X) cada 5 segundos sin refrescar la pestaña.
  13. // @description:de Aktualisiert automatisch die Twitter (X) Timeline alle 5 Sekunden ohne das Tab neu zu laden.
  14. // @description:it Aggiorna automaticamente la timeline di Twitter (X) ogni 5 secondi senza aggiornare la scheda.
  15. // @description:zh-CN 在不刷新标签页的情况下, 每5秒自动刷新Twitter(X)时间轴。
  16. // @author 4lrick
  17. // @match https://x.com/*
  18. // @icon https://www.google.com/s2/favicons?sz=64&domain=twitter.com
  19. // @grant GM_getValue
  20. // @grant GM_setValue
  21. // @grant GM_registerMenuCommand
  22. // @grant GM_unregisterMenuCommand
  23. // @license GPL-3.0-only
  24. // ==/UserScript==
  25.  
  26. (function() {
  27. 'use strict';
  28.  
  29. let refreshInterval = GM_getValue('refreshInterval', 5);
  30. let refreshIntervalId;
  31. let menuCommandId;
  32.  
  33. function isAtTopOfPage() {
  34. const tablist = document.querySelector('[role="tab"][href="/home"]');
  35. const timeline = document.querySelector('main [role="region"]');
  36.  
  37. if (tablist && timeline) {
  38. const tablistBottom = tablist.getBoundingClientRect().bottom;
  39. const timelineTop = timeline.getBoundingClientRect().top;
  40.  
  41. return tablistBottom <= timelineTop + 1;
  42. }
  43. return false;
  44. }
  45.  
  46. function refreshTimeline() {
  47. if (window.location.href.startsWith('https://x.com/home')) {
  48. if (isAtTopOfPage()) {
  49. const refreshButton = document.querySelector('[href="/home"]');
  50. if (refreshButton) {
  51. refreshButton.click();
  52. window.scrollY = 0;
  53. }
  54. }
  55. }
  56. }
  57.  
  58. function setCustomInterval() {
  59. if (refreshIntervalId) {
  60. clearInterval(refreshIntervalId);
  61. }
  62. refreshIntervalId = setInterval(refreshTimeline, refreshInterval * 1000);
  63. updateMenuCommand();
  64. }
  65.  
  66. function settings() {
  67. const newInterval = prompt("Enter refresh interval in seconds:", refreshInterval);
  68. if (newInterval !== null) {
  69. const parsedInterval = parseInt(newInterval);
  70. if (!isNaN(parsedInterval) && parsedInterval > 0) {
  71. refreshInterval = parsedInterval;
  72. GM_setValue('refreshInterval', refreshInterval);
  73. setCustomInterval();
  74. } else {
  75. alert("Please enter a valid positive number.");
  76. }
  77. }
  78. }
  79.  
  80. function updateMenuCommand() {
  81. if (menuCommandId) {
  82. GM_unregisterMenuCommand(menuCommandId);
  83. }
  84. menuCommandId = GM_registerMenuCommand(`Set Refresh Interval (current: ${refreshInterval}s)`, settings);
  85. }
  86.  
  87. updateMenuCommand();
  88. setCustomInterval();
  89. })();