PDA

View Full Version : Miscellaneous Hacks - [vBMods.rocks] Create an Inverted Color Theme off Existing Theme Using Just Few CSS


noypiscripter
02-03-2022, 10:00 PM
If you have a light theme in your forum, you can easily create a dark theme off it, or a dark theme into a light theme, using just few lines of CSS! :eek:

How cool is it that you don't have to customize every vB stylevars just to create a dark or light theme and you just let the browser do its magic to detect what the inverted color is for each the element on a page? :cool:

Here's a fun quick way to test how color inversion would look like in your own forum. Follow the below steps:
Navigate to your forum to any page.
Press F12 or right-click any element on your page and click Inspect or Inspect element.
Open the Console tab.
Paste the code below in the console.
$('body').css({filter:'invert(1)', 'backdrop-filter':'invert(0)'}); $('img,iframe').css({filter:'invert(1)'}); openAlertDialog({title:'Invert Color Theme Test by vBMods.rocks', message:"This is how your site would look like if colors are inverted. It still needs few CSS tweaks to undo color inversion on background images, icons, and others that you don't want to be inverted. You can try doing this test for each of your available styles/themes and for any page on your site.<br /><br/>NOTE: This style is obviously not saved to your site. It will go away when you reload this page."});
Press Enter.
Be amazed and say "Wow! " :eek:
If you want to proceed with this, then follow these steps to use it in your forum.
Logon to AdminCP.
Navigate to Styles > Style Manager.
Find the style/theme you want to base the inverted color style from.
In the "Choose Action..." dropdown, choose "Add Child Style".
Rename the title as desired.
Choose "No" in the Allow User Selection option. You will set it to "Yes" later when the style is fully ready.
Click Save.
Navigate to your forum.
Choose the new style you just created. It should be exactly identical to it parent style since you haven't made any CSS changes yet.
Go to AdminCP > Style Manager or SiteBuilder > Style > CSS Editor to edit the css_additional template of the new style you created.
Enter the following CSS code. (The below code is just the base CSS code you need. You still need to add more code to it to undo the color inversion for any elements you don't want to be inverted)

/* Invert Color Theme - START */
/* Invert color of all elements */
body {
filter: invert(1);
backdrop-filter: invert(0);
}
/* Undo invert of all images and iframes */
img,
iframe {
filter: invert(1);
}
/* Invert Color Theme - END */
Save.
Reload your forum to see the style changes.
To undo color inversion on elements you don't want to be inverted, do the following.
Find the element.
Right-click and choose Inspect or Inspect element.
Find the id or class of that element. There may be multiple classes in it. You don't have to add them all. Post any questions in vbmods.rocks on how to identify which class to use and I will help you.
Add the code in css_additional to undo the color inversion using the following format:

/* Undo color inversion of specific elements */
#ThisIsTheId,
#ThisIsAnotherId,
.ThisIsTheClass,
.ThisIsAnotherClass {
filter: invert(1);
}
But if you want to keep the color inversion of the site logo, then add this CSS:

/* Keep color inversion of site logo */
#header .site-logo img {
filter: invert(0);
}

Save.
Reload your forum to see the changes.
Keep finding new elements and adding new id or class to the above code.

When you're ready, you can release the new style to the public by doing the following steps.
Navigate to the new style by going to AdminCP > Style Manager > [New style you created] > Edit Settings.
Set the "Allow User Selection" option to Yes.
Save.
Go to Settings > Options > Style & Language Settings.
Set "Allow Users To Change Styles" to Yes.
Save.

Repeat the whole steps for every style/theme you want to create an inverted theme off it.
NOTE:
If you add new custom CSS in css_additional of the parent theme/style in the future, do not forget to also add it to the css_additional of the inverted-color child style.

Enjoy! ;)

Please see attached screenshot of how it looks like for the vB5 Default Style when using this mod.

For more details and support, please head over to https://vbmods.rocks/forum/vbulletin-5-modifications/vbulletin-5-miscellaneous-modifications/23626-how-to-create-an-inverted-color-theme-off-existing-theme-using-just-few-css

noypiscripter
02-09-2022, 07:39 PM
Let's take this mod to another level! :cool:

What if a user had enabled Dark mode preference through the Operating System setting or the browser setting and your forum automatically turned into a Dark mode too? Wouldn't that be super awesome? :cool: :cool:

How to Enable Dark Mode on Your Computer or Mobile Device
Windows

Go to Settings > Personalization > Colors and then choose Dark for the default app mode.

Mac

Go to Apple menu > System Preferences > General > Appearance and then choose Dark or Auto.

Chrome for Android

Go to Settings > Theme and then choose "System default" or Dark.
If System default is chosen, dark mode is enabled when you turn on Battery Saver on the device or enable Dark theme on the device.

iPhone

Go to Settings > Display & Brightness and then choose Dark or Automatic.


Without the CSS code in this post, setting Dark mode at the OS, device or browser level, only the browser tabs and browser controls will turn dark but not the websites. But with the CSS code below, your forum (or any website for that matter) will automatically turn into Dark mode. If the device has auto dark mode enabled based on certain event (e.g. sunset) or at a specific time, then when user visits your site, it will automatically be in Dark mode too!

Add this CSS in css_additional template of the light theme/style:

/* Auto Detect Dark Mode - START */
@media (prefers-color-scheme: dark) {
/* Copy and paste all CSS code for Dark Theme you've created based from the steps in the first post */
}
/* Auto Detect Dark Mode - END */

For browser support, please see this compatibility chart (https://caniuse.com/?search=prefers-color-scheme).

Watch demo on YouTube below:

https://www.youtube.com/watch?v=Ln4vqs1rWL0

In the demo, I used my Android phone and set "System default" in the Theme settings in Chrome browser app and then enabled Dark mode by turning on Battery Saver on the device.