Switch CharacterID

Switch Characters ID by Ctrl + arrow buttons in panel.php

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Switch CharacterID
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  Switch Characters ID by Ctrl + arrow buttons in panel.php
// @author       grin3671
// @match        https://myanimelist.net/panel.php*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    window.addEventListener('keyup', (event) => {
      // No extra action w/o modifier
      if (event.getModifierState('Control')) {
        let params, linkID, newCID;
        // Get current url parameters
        params = new URLSearchParams(document.location.search.substring(1));
        // Get current Character ID (CID)
        linkID = parseInt(params.get('character_id'), 10);
        // Open character page if pressed Arrow UP
        if (!isNaN(linkID) && event.code === 'ArrowUp') {
          // NOTE: "href" create new history entry so we can return to panel.php
          window.location.href = 'https://myanimelist.net/character/' + linkID.toString();
        }
        // Set new CID but don't change it if used any other button
        newCID = event.code === 'ArrowLeft' ? linkID - 1 : event.code === 'ArrowRight' ? linkID + 1 : linkID;
        if (!isNaN(newCID) && linkID !== newCID) {
          // Set new url parameters
          params.set('character_id', newCID);
          // Change current url
          // NOTE: "replace" doesn't create new history entry so we can return to start point faster
          window.location.replace(window.location.origin + window.location.pathname + '?' + params.toString());
        }
      }
    });
})();