Add Back Comic Sans to Google Docs/Slides

You want do bring back comic sans? Now You Can! With this userstyle BRINGS BACK COMIC SANS!

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Add Back Comic Sans to Google Docs/Slides
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  You want do bring back comic sans? Now You Can! With this userstyle BRINGS BACK COMIC SANS!
// @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 Comic Sans into the font dropdown
    function addComicSansFont() {
        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('.comic-sans-option')) {
                    // Create a new font option for Comic Sans
                    let newFontOption = document.createElement('div');
                    newFontOption.classList.add('goog-menuitem', 'goog-menuitem-content', 'comic-sans-option');
                    newFontOption.setAttribute('role', 'menuitem');
                    newFontOption.setAttribute('data-font', 'Comic Sans MS');
                    newFontOption.style.fontFamily = '"Comic Sans MS", cursive, sans-serif';
                    newFontOption.textContent = 'Comic Sans';
                    
                    // 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, '"Comic Sans MS"');
                    });
                }
            });
        });

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

    // Run the function to add Comic Sans after a delay to ensure the page has loaded
    window.setTimeout(addComicSansFont, 2000);
})();