Docassemble Docs Improved Titles

Generate a better URL based page title for Docassemble docs

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.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

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         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();
})();