Add Chalkboard SE to Google Docs/Slides

Adds Chalkboard SE as an option to Google Docs and Slides font list

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Add Chalkboard SE to Google Docs/Slides
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Adds Chalkboard SE as an option to Google Docs and Slides font list
// @author       YourName
// @match        https://docs.google.com/document/d/*
// @match        https://docs.google.com/presentation/d/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Function to inject Chalkboard SE into the font dropdown
    function addChalkboardFont() {
        let observer = new MutationObserver(function(mutations) {
            mutations.forEach(function(mutation) {
                // Check if the font dropdown exists
                let fontDropdown = document.querySelector('[aria-label="Font"]');
                
                if (fontDropdown && !document.querySelector('.chalkboard-font-option')) {
                    // Create a new font option for Chalkboard SE
                    let newFontOption = document.createElement('div');
                    newFontOption.classList.add('goog-menuitem', 'goog-menuitem-content', 'chalkboard-font-option');
                    newFontOption.setAttribute('role', 'menuitem');
                    newFontOption.setAttribute('data-font', 'Chalkboard SE');
                    newFontOption.style.fontFamily = '"Chalkboard SE", cursive, sans-serif';
                    newFontOption.textContent = 'Chalkboard SE';
                    
                    // Add the new font option to the font dropdown
                    let fontMenu = document.querySelector('.docs-fontmenu ul');
                    if (fontMenu) {
                        fontMenu.appendChild(newFontOption);
                    }

                    // Event listener to apply the font when selected
                    newFontOption.addEventListener('click', function() {
                        document.execCommand('fontName', false, '"Chalkboard SE"');
                    });
                }
            });
        });

        observer.observe(document.body, { childList: true, subtree: true });
    }

    // Run the function to add Chalkboard SE after a delay to ensure the page has loaded
    window.setTimeout(addChalkboardFont, 2000);
})();