Skip to content

Instantly share code, notes, and snippets.

@Kenya-West
Last active July 6, 2020 03:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kenya-West/a5d5b976d1e12ec56b54c5ea92723454 to your computer and use it in GitHub Desktop.
Save Kenya-West/a5d5b976d1e12ec56b54c5ea92723454 to your computer and use it in GitHub Desktop.
A JS file for Tampermonkey that allows you to enable dark theme on Whatsapp Web website

Whatsapp Web dark theme enabler

Description

A js file for Tampermonkey that allows you to enable dark theme on Whatsapp Web website.

How to contribute

Clone this project on GitHub and start your changes. If you want to use the script from source code, then create new script in Tampermonkey extension and put source code in opened window.

How to use this script?

You need Tampermonkey extension installed on your browser to use this style.

You can install the script from Greasyfork.

Attention!

This script is designed for new browsers, such as new versions of Chromium-based browsers (Microsoft Edge, Opera, Google Chrome, etc.) and Firefox. The script will not run on the browsers released earlier than 2019. Thank you.

P. S. Author is not affiliated in any of mentioned organizations, events and links.

// ==UserScript==
// @name Whatsapp Web dark theme enabler
// @namespace http://web.whatsapp.com/
// @version 1.02
// @description A JS file for Tampermonkey that allows you to enable dark theme on Whatsapp Web website.
// @author Kenya-West
// @match https://web.whatsapp.com
// @grant none
// ==/UserScript==
class WhatsappWebDarkThemeEnabler {
constructor(htmlClass, addClass) {
this.start(htmlClass, addClass);
}
start(htmlClass, addClass) {
const element = this.findElement(htmlClass);
console.info(`Found ${element}`);
if (element && !this.doesElementHaveThemeEnabled(element, addClass)) {
console.info(`It doesn't have "${addClass}" class`);
this.enableTheme(element, addClass);
console.log(`Dew it!`);
} else if (!element) {
console.error(`No element is found`)
} else if (this.doesElementHaveThemeEnabled(element, addClass)) {
console.warn(`It already has "${addClass}" class`);
}
}
findElement(selector) {
return document.querySelector(selector);
}
doesElementHaveThemeEnabled(element, addClass) {
return element.classList.contains(addClass);
}
enableTheme(element, addClass) {
element.classList.add(addClass);
}
}
setTimeout(() => new WhatsappWebDarkThemeEnabler("body", "dark"), 5000);
@Korb
Copy link

Korb commented May 22, 2020

Firefox 77.0b9 (64-bit), Tampermonkey 4.10.6112. The script is not recognized as Tampermonkey compatibled userscript.

@Kenya-West
Copy link
Author

@Korb thanks for info but I do not have Firefox to test it out for now. Maybe on weekends

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment