ArkhamDB Dynamic Title

Update the title of ArkhamDB deck pages to include the first 30 characters of the deck name.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         ArkhamDB Dynamic Title
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  Update the title of ArkhamDB deck pages to include the first 30 characters of the deck name.
// @author       Chr1Z
// @match        https://*.arkhamdb.com/deck/*
// @icon         https://i.imgur.com/T3vHgln.png
// @grant        none
// ==/UserScript==

(function () {
  'use strict';

  // Function to trim the deck name and update the title
  function updateDocumentTitle(deckName) {
    deckName = deckName.trim();

    if (deckName.length > 30) {
      deckName = deckName.substring(0, 30) + '...';
    }

    document.title = deckName + ' · ArkhamDB';
  }

  function updateTitleForView() {
    var deckNameElement = document.querySelector('#wrapper .main.container h1');
    if (deckNameElement) {
      var deckName = deckNameElement.textContent;
      updateDocumentTitle(deckName);
    }
  }

  function updateTitleForEdit() {
    var deckNameInput = document.querySelector('input.decklist-name');
    if (deckNameInput) {
      var deckName = deckNameInput.value;
      updateDocumentTitle(deckName);

      // Update title as user types
      deckNameInput.addEventListener('input', function () {
        var newDeckName = deckNameInput.value;
        updateDocumentTitle(newDeckName);
      });
    }
  }

  // Check if the user is viewing or editing a deck and run the appropriate function
  if (window.location.href.includes('/deck/view/')) {
    window.addEventListener('load', updateTitleForView);
  } else if (window.location.href.includes('/deck/edit/')) {
    window.addEventListener('load', updateTitleForEdit);
  }

})();