AutoScroll Mobile

AutoScroll avec boutons tactiles pour mobiles et tablettes

  1. // ==UserScript==
  2. // @name AutoScroll Mobile
  3. // @namespace https://greasyfork.org/users/1429467
  4. // @description AutoScroll avec boutons tactiles pour mobiles et tablettes
  5. // @include http*
  6. // @version 1.3
  7. // @author Lakfu sama
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function () {
  12. 'use strict';
  13.  
  14. let scrolling = false;
  15. let speed = 50;
  16. let scrollInterval;
  17.  
  18. function startScrolling() {
  19. if (!scrolling) {
  20. scrolling = true;
  21. scrollInterval = setInterval(() => {
  22. window.scrollBy(0, 5);
  23. }, speed);
  24. updateButtonState();
  25. }
  26. }
  27.  
  28. function stopScrolling() {
  29. scrolling = false;
  30. clearInterval(scrollInterval);
  31. updateButtonState();
  32. }
  33.  
  34. function toggleScrolling() {
  35. scrolling ? stopScrolling() : startScrolling();
  36. }
  37.  
  38. function increaseSpeed() {
  39. if (speed > 10) {
  40. speed -= 10;
  41. restartScrolling();
  42. }
  43. }
  44.  
  45. function decreaseSpeed() {
  46. speed += 10;
  47. restartScrolling();
  48. }
  49.  
  50. function restartScrolling() {
  51. if (scrolling) {
  52. stopScrolling();
  53. startScrolling();
  54. }
  55. }
  56.  
  57. function scrollToTop() {
  58. window.scrollTo({ top: 0, behavior: 'smooth' });
  59. }
  60.  
  61. function scrollToBottom() {
  62. window.scrollTo({ top: document.body.scrollHeight, behavior: 'smooth' });
  63. }
  64.  
  65. function updateButtonState() {
  66. let button = document.getElementById('scroll-toggle');
  67. if (scrolling) {
  68. button.textContent = '⏸️ Stop';
  69. button.style.backgroundColor = '#ff5555';
  70. } else {
  71. button.textContent = '▶️ Start';
  72. button.style.backgroundColor = '#4CAF50';
  73. }
  74. }
  75.  
  76. // Supprimer les anciens boutons pour éviter les doublons
  77. function removeExistingButtons() {
  78. document.querySelectorAll('.scroll-btn').forEach(btn => btn.remove());
  79. }
  80.  
  81. // Création des boutons tactiles
  82. function createButton(id, text, onClick, bgColor, position) {
  83. let button = document.createElement('button');
  84. button.id = id;
  85. button.textContent = text;
  86. button.onclick = onClick;
  87. button.style.position = 'fixed';
  88. button.style.bottom = '5px'; // Position basse
  89. button.style.right = position + 'vw'; // Position horizontale dynamique
  90. button.style.width = '50px'; // Taille adaptée au tactile
  91. button.style.height = '50px';
  92. button.style.fontSize = '16px';
  93. button.style.border = 'none';
  94. button.style.borderRadius = '10px';
  95. button.style.backgroundColor = bgColor;
  96. button.style.color = 'white';
  97. button.style.zIndex = '10000';
  98. button.className = 'scroll-btn';
  99. document.body.appendChild(button);
  100. }
  101.  
  102. // Supprimer les boutons existants avant de les recréer
  103. removeExistingButtons();
  104.  
  105. // Création des boutons avec un espacement uniforme
  106. let buttons = [
  107. { id: 'scroll-toggle', text: '▶️ Start', action: toggleScrolling, color: '#4CAF50', pos: 2 },
  108. { id: 'scroll-up', text: '⬆️', action: scrollToTop, color: '#2196F3', pos: 12 },
  109. { id: 'scroll-down', text: '⬇️', action: scrollToBottom, color: '#2196F3', pos: 22 },
  110. { id: 'speed-up', text: '⏩+', action: increaseSpeed, color: '#FF9800', pos: 32 },
  111. { id: 'speed-down', text: '⏪-', action: decreaseSpeed, color: '#FF9800', pos: 42 }
  112. ];
  113.  
  114. buttons.forEach(btn => {
  115. createButton(btn.id, btn.text, btn.action, btn.color, btn.pos);
  116. });
  117.  
  118. })();