Docassemble Docs Improved Titles

Generate a better URL based page title for Docassemble docs

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         Docassemble Docs Improved Titles
// @namespace    https://github.com/jpagh/
// @version      1.1
// @description  Generate a better URL based page title for Docassemble docs
// @author       Jack Adamson
// @license      MIT
// @match        https://docassemble.org/docs/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=docassemble.org
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function capitalizeFirst(str) {
        return str.charAt(0).toUpperCase() + str.slice(1);
    }

    function getTitleFromUrl() {
        const pathParts = window.location.pathname.split('/');
        const filename = pathParts[pathParts.length - 1].replace('.html', '');
        const baseTitle = capitalizeFirst(filename);
        if (location.hash) {
            const decodedHash = decodeURIComponent(location.hash);
            return `${baseTitle} ${decodedHash}`;
        }
        return baseTitle;
    }

    function updateTitle() {
        document.title = getTitleFromUrl();
    }

    window.addEventListener('hashchange', updateTitle);
    updateTitle();
})();