From b3176a8c0caca9b51c31901702a196f95ef916a4 Mon Sep 17 00:00:00 2001 From: O-01-67 <68935009+O-01-67@users.noreply.github.com> Date: Tue, 17 May 2022 13:27:28 -0400 Subject: [PATCH] Mod now supports triplets that are missing a # so FF0000 will become #FF0000 and be used --- mods/page_color.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/mods/page_color.js b/mods/page_color.js index 2b35b185..0af50c5b 100644 --- a/mods/page_color.js +++ b/mods/page_color.js @@ -13,4 +13,23 @@ if(urlParams.get('pageColor') != null) { //null check }; }; -document.body.style.backgroundColor = color; \ No newline at end of file +color_Would_Be_A_Triplet_If_It_Started_With_An_Octothorpe = null; +color_Is_Supported_As_A_Background_By_The_Browser = null; + +if( /^#([0-9A-F]{3}){1,2}$/i.test("#" + color) ) { + color_Would_Be_A_Triplet_If_It_Started_With_An_Octothorpe = true +} else { + color_Would_Be_A_Triplet_If_It_Started_With_An_Octothorpe = false +} + +if( CSS.supports('background',color) ) { + color_Is_Supported_As_A_Background_By_The_Browser = true +} else { + color_Is_Supported_As_A_Background_By_The_Browser = false +} + +if(color_Is_Supported_As_A_Background_By_The_Browser == false && color_Would_Be_A_Triplet_If_It_Started_With_An_Octothorpe == true) { + color = "#" + color +} + +document.body.style.background = color;