Add Extra Fonts to Google Docs/Slides

Add extra fonts to the Google Docs and Google Slides font dropdown menus

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Add Extra Fonts to Google Docs/Slides
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Add extra fonts to the Google Docs and Google Slides font dropdown menus
// @match        https://docs.google.com/document/d/*
// @match        https://docs.google.com/presentation/d/*
// @grant        none
// @run-at       document-end
// ==/UserScript==

(function() {
    'use strict';

    function addFontsToDropdown() {
        // Wait for the Google Docs/Slides page to fully load
        const interval = setInterval(() => {
            // Select the font dropdown element
            const fontDropdown = document.querySelector('.quantumWizMenuPaperselectPopup');
            
            if (fontDropdown) {
                // Clear the interval once the dropdown is found
                clearInterval(interval);
                
                // Define the extra fonts to add
                const extraFonts = ['Comic Sans MS', 'Arial Black', 'Courier New'];
                
                // Add the extra fonts to the dropdown
                extraFonts.forEach(font => {
                    const fontOption = document.createElement('div');
                    fontOption.className = 'quantumWizMenuPaperselectOption';
                    fontOption.textContent = font;
                    fontDropdown.appendChild(fontOption);
                });

                // Optionally, you can also add event listeners to handle font selection
                // Example:
                // fontDropdown.addEventListener('click', function(event) {
                //     if (event.target && event.target.className.includes('quantumWizMenuPaperselectOption')) {
                //         const selectedFont = event.target.textContent;
                //         // Apply the selected font to the document
                //     }
                // });
            }
        }, 1000); // Check every second
    }

    // Add extra fonts to the dropdown when the page loads
    window.addEventListener('load', addFontsToDropdown);
})();