Center horizontal scroll bar

Auto center the horizontal scroll bar

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Center horizontal scroll bar
// @version      0.2.0
// @description  Auto center the horizontal scroll bar
// @author       dragonish
// @namespace    https://github.com/dragonish
// @license      GNU General Public License v3.0 or later
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function () {
  const debounced = {
    timer: {},
    debounce(key, func, delay, immediate) {
      window.clearTimeout(this.timer[key]);
      if (immediate) {
        if (this.timer[key] === undefined) {
          func();
        }
      }
      this.timer[key] = window.setTimeout(() => {
        func();
        this.timer[key] = undefined;
      }, delay);
      return {
        cancel: () => {
          window.clearTimeout(this.timer[key]);
          this.timer[key] = undefined;
        }
      };
    }
  };
  function scroll(msg) {
    console.log(msg);
    window.scrollTo({
      left: (document.documentElement.scrollWidth - document.documentElement.clientWidth) / 2
    });
  }
  window.addEventListener('load', () => {
    setTimeout(() => {
      scroll('window loaded, try rolling.');
    }, 0);
  });
  window.addEventListener('resize', () => {
    debounced.debounce('scroll', () => {
      scroll('window resized, try rolling.');
    }, 250);
  });
})();