MediaWiki:Gadget-EditShortcut.js

From JoJo's Bizarre Encyclopedia - JoJo Wiki
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
(function() {
    // List of namespaces where the script should work
    var namespaces = [0, 2, 4, 6, 8, 10, 14, 7000];

    // Check if the current namespace is in the list and the current action is not 'edit'
    if (namespaces.includes(mw.config.get('wgNamespaceNumber')) && mw.config.get('wgAction') !== 'edit') {
        document.addEventListener('keydown', function(event) {
            // Check if the pressed key is 'e', no modifier keys are pressed, and the search input is not focused
            if (event.key === 'e' && !event.altKey && !event.ctrlKey && !event.shiftKey && !event.metaKey && document.activeElement.id !== 'searchInput') {
                // Check if VisualEditor is not active
                if (!document.querySelector('.ve-init-mw-desktopArticleTarget')) {
                    // Prevent the default action to avoid any unwanted behavior
                    event.preventDefault();
                    // Redirect to the "edit source" URL
                    window.location.href = mw.util.getUrl(mw.config.get('wgPageName'), { action: 'edit' });
                }
            }
        });
    }
})();