From bdfab7caeff8d0c3a9e249c981268470ccf3cb1c Mon Sep 17 00:00:00 2001 From: Smithster Date: Sun, 4 Apr 2021 19:33:59 +0100 Subject: [PATCH] -Now able to clear background images -removed default image -can now use enter to save background image -removed pointless test --- src/js/config.js | 12 ++++++++---- src/js/settings.js | 6 ++++++ src/js/theme-controller.js | 14 ++++++-------- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/js/config.js b/src/js/config.js index b670b9008..1c9fb98eb 100644 --- a/src/js/config.js +++ b/src/js/config.js @@ -113,7 +113,7 @@ let defaultConfig = { monkey: false, repeatQuotes: "off", oppositeShiftMode: "off", - customBackground: "https://i.imgur.com/OWbWz6i.jpg", + customBackground: "", customBackgroundSize: "cover", }; @@ -1349,9 +1349,13 @@ export function setCustomBackground(value, nosave) { if (value == null || value == undefined) { value = ""; } - config.customBackground = value; - ThemeController.applyCustomBackground(); - if (!nosave) saveToCookie(); + if( /(https|http):\/\/(www\.|).+\..+\/.+(\.png|\.gif|\.jpeg|\.jpg)/gi.test(value) || value == ""){ + config.customBackground = value; + ThemeController.applyCustomBackground(); + if (!nosave) saveToCookie(); + } else { + Notifications.add("Invalid custom background URL", 0); + } } export function setCustomBackgroundSize(value, nosave) { diff --git a/src/js/settings.js b/src/js/settings.js index 53ef33e8b..eeeb65fa2 100644 --- a/src/js/settings.js +++ b/src/js/settings.js @@ -746,4 +746,10 @@ $(".pageSettings .section.customBackground .inputAndButton .cover").on("click", $(".pageSettings .section.customBackground .inputAndButton .contain").on("click", (e) => { UpdateConfig.setCustomBackgroundSize("contain"); +}); + +$(".pageSettings .section.customBackground .inputAndButton input").keypress( (e) => { + if(e.keyCode == 13){ + UpdateConfig.setCustomBackground($(".pageSettings .section.customBackground .inputAndButton input").val()) + } }); \ No newline at end of file diff --git a/src/js/theme-controller.js b/src/js/theme-controller.js index 79ad46253..c91bc9a52 100644 --- a/src/js/theme-controller.js +++ b/src/js/theme-controller.js @@ -152,14 +152,12 @@ export function clearRandom() { } export function applyCustomBackground(){ - if (Config.customBackground != ""){ - $("body").css({ - backgroundImage: `url(${Config.customBackground})`, - backgroundRepeat: "no-repeat", - backgroundPosition: "center center", - backgroundAttachment: "fixed", - }) - } + $("body").css({ + backgroundImage: `url(${Config.customBackground})`, + backgroundRepeat: "no-repeat", + backgroundPosition: "center center", + backgroundAttachment: "fixed", + }) } export function applyCustomBackgroundSize(){