Add Chalkboard SE to Google Docs/Slides

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

  1. // ==UserScript==
  2. // @name Add Chalkboard SE to Google Docs/Slides
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Adds Chalkboard SE as an option to Google Docs and Slides font list
  6. // @author YourName
  7. // @match https://docs.google.com/document/d/*
  8. // @match https://docs.google.com/presentation/d/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Function to inject Chalkboard SE into the font dropdown
  16. function addChalkboardFont() {
  17. let observer = new MutationObserver(function(mutations) {
  18. mutations.forEach(function(mutation) {
  19. // Check if the font dropdown exists
  20. let fontDropdown = document.querySelector('[aria-label="Font"]');
  21. if (fontDropdown && !document.querySelector('.chalkboard-font-option')) {
  22. // Create a new font option for Chalkboard SE
  23. let newFontOption = document.createElement('div');
  24. newFontOption.classList.add('goog-menuitem', 'goog-menuitem-content', 'chalkboard-font-option');
  25. newFontOption.setAttribute('role', 'menuitem');
  26. newFontOption.setAttribute('data-font', 'Chalkboard SE');
  27. newFontOption.style.fontFamily = '"Chalkboard SE", cursive, sans-serif';
  28. newFontOption.textContent = 'Chalkboard SE';
  29. // Add the new font option to the font dropdown
  30. let fontMenu = document.querySelector('.docs-fontmenu ul');
  31. if (fontMenu) {
  32. fontMenu.appendChild(newFontOption);
  33. }
  34.  
  35. // Event listener to apply the font when selected
  36. newFontOption.addEventListener('click', function() {
  37. document.execCommand('fontName', false, '"Chalkboard SE"');
  38. });
  39. }
  40. });
  41. });
  42.  
  43. observer.observe(document.body, { childList: true, subtree: true });
  44. }
  45.  
  46. // Run the function to add Chalkboard SE after a delay to ensure the page has loaded
  47. window.setTimeout(addChalkboardFont, 2000);
  48. })();