ArkhamDB Dynamic Title

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

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==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);
  }

})();