Jump to content

User:Modestginger/vector-2022.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Modestginger (talk | contribs) at 20:03, 2 October 2022. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
(function() {

  function updateViewport() {
    const viewportMeta = document.querySelector('meta[name="viewport"]');
    if (viewportMeta) {
      console.log(viewportMeta.getAttribute('content'));
      viewportMeta.setAttribute('content','width=device-width,initial-scale=1.0,minimum-scale=1.0');
      document.documentElement.classList.add('fixedViewport');
      window.scrollBy(-1000, 0);
    }
  }
  
  updateViewport();


  const darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)');

  function syncDarkModeToSystem() {
    if (!window.mw || !window.mw.user || !window.mw.user.options || !document.getElementById('pt-darkmode')) {
      return false;
    }

    const toggleButton = document.getElementById('pt-darkmode');

    const isPageInDarkMode = (window.mw.user.options.get('gadget-dark-mode') === 1);
    const isSystemInDarkMode = (darkModeMediaQuery.matches);

    if (isPageInDarkMode !== isSystemInDarkMode) {
      toggleButton.click();
    }
  }


  syncDarkModeToSystem();

  darkModeMediaQuery.addEventListener('change', evt => {
    syncDarkModeToSystem();
  })

})();