Skip to content

Instantly share code, notes, and snippets.

@ma-he-sh
Last active April 1, 2023 17:18
Show Gist options
  • Save ma-he-sh/8acc46b07b9c24b73aa020f9ce7ddc0e to your computer and use it in GitHub Desktop.
Save ma-he-sh/8acc46b07b9c24b73aa020f9ce7ddc0e to your computer and use it in GitHub Desktop.
DarkMode for google apps

Add dark mode to google docs without 3rd party plugins

On google doc goto Extenstions > App Script and add following code and save.

If active, it will show a new menu item called "Dark Mode".

function onOpen() {
var ui = DocumentApp.getUi();
var menu = ui.createMenu('Dark Mode');
menu.addItem('Enable Dark Mode', 'enableDarkMode');
menu.addItem('Disable Dark Mode', 'disableDarkMode');
menu.addToUi();
}
function enableDarkMode() {
var doc = DocumentApp.getActiveDocument();
var body = doc.getBody();
body.setBackgroundColor('#1e1e1e');
var paras = body.getParagraphs();
for (var i = 0; i < paras.length; i++) {
var para = paras[i];
para.editAsText().setForegroundColor('#ffffff');
}
}
function disableDarkMode() {
var doc = DocumentApp.getActiveDocument();
var body = doc.getBody();
body.setBackgroundColor('#ffffff');
var paras = body.getParagraphs();
for (var i = 0; i < paras.length; i++) {
var para = paras[i];
para.editAsText().setForegroundColor('#000000');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment