mirror of
https://github.com/TitanEmbeds/Titan.git
synced 2024-11-15 02:21:21 +01:00
Improve capability with user defined css and themes
This commit is contained in:
parent
16232cf434
commit
8f277f15f6
@ -9,6 +9,7 @@
|
|||||||
(function () {
|
(function () {
|
||||||
const theme_options = ["DiscordDark", "BetterTitan"]; // All the avaliable theming names
|
const theme_options = ["DiscordDark", "BetterTitan"]; // All the avaliable theming names
|
||||||
|
|
||||||
|
var user_def_css; // Saves the user defined css
|
||||||
var has_already_been_focused = false; // keep track of if the embed has initially been focused.
|
var has_already_been_focused = false; // keep track of if the embed has initially been focused.
|
||||||
var logintimer; // timer to keep track of user inactivity after hitting login
|
var logintimer; // timer to keep track of user inactivity after hitting login
|
||||||
var fetchtimeout; // fetch routine timer
|
var fetchtimeout; // fetch routine timer
|
||||||
@ -92,6 +93,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
|
if ($("#user-defined-css").length > 0) {
|
||||||
|
user_def_css = $("#user-defined-css").text();
|
||||||
|
}
|
||||||
|
|
||||||
$('select').material_select();
|
$('select').material_select();
|
||||||
$("#focusmodal").modal({
|
$("#focusmodal").modal({
|
||||||
dismissible: true,
|
dismissible: true,
|
||||||
@ -109,16 +114,6 @@
|
|||||||
outDuration: 400,
|
outDuration: 400,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (document.hasFocus()) {
|
|
||||||
primeEmbed();
|
|
||||||
}
|
|
||||||
|
|
||||||
$(window).focus(function() {
|
|
||||||
if (!has_already_been_focused) {
|
|
||||||
primeEmbed();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#nameplate").click(function () {
|
$("#nameplate").click(function () {
|
||||||
$("#userembedmodal").modal("open");
|
$("#userembedmodal").modal("open");
|
||||||
});
|
});
|
||||||
@ -130,7 +125,7 @@
|
|||||||
|
|
||||||
var themeparam = getParameterByName('theme');
|
var themeparam = getParameterByName('theme');
|
||||||
var localstore_theme = localStorage.getItem("theme");
|
var localstore_theme = localStorage.getItem("theme");
|
||||||
if ((themeparam && $.inArray(themeparam, theme_options) != -1) || (localstore_theme)) {
|
if ((getParameterByName("css") == null) && ((themeparam && $.inArray(themeparam, theme_options) != -1) || (localstore_theme))) {
|
||||||
var theme;
|
var theme;
|
||||||
if (themeparam) {
|
if (themeparam) {
|
||||||
theme = themeparam;
|
theme = themeparam;
|
||||||
@ -142,15 +137,25 @@
|
|||||||
$("#theme-selector option[value=" + theme + "]").attr('selected', 'selected');
|
$("#theme-selector option[value=" + theme + "]").attr('selected', 'selected');
|
||||||
$('select').material_select();
|
$('select').material_select();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (document.hasFocus()) {
|
||||||
|
primeEmbed();
|
||||||
|
}
|
||||||
|
|
||||||
|
$(window).focus(function() {
|
||||||
|
if (!has_already_been_focused) {
|
||||||
|
primeEmbed();
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function changeTheme(theme) {
|
function changeTheme(theme) {
|
||||||
if (theme == "") {
|
if (theme == "") {
|
||||||
$("#css-theme").attr("href", "");
|
$("#css-theme").attr("href", "");
|
||||||
disable_userdef_css(false);
|
$("#user-defined-css").text(user_def_css);
|
||||||
localStorage.removeItem("theme");
|
localStorage.removeItem("theme");
|
||||||
} else if ($.inArray(theme, theme_options) != -1) {
|
} else if ($.inArray(theme, theme_options) != -1) {
|
||||||
disable_userdef_css(true);
|
$("#user-defined-css").text("");
|
||||||
$("#css-theme").attr("href", "/static/themes/" + theme + "/css/style.css");
|
$("#css-theme").attr("href", "/static/themes/" + theme + "/css/style.css");
|
||||||
localStorage.setItem("theme", theme);
|
localStorage.setItem("theme", theme);
|
||||||
}
|
}
|
||||||
@ -167,19 +172,6 @@
|
|||||||
return decodeURIComponent(results[2].replace(/\+/g, " "));
|
return decodeURIComponent(results[2].replace(/\+/g, " "));
|
||||||
}
|
}
|
||||||
|
|
||||||
function disable_userdef_css(boolean) {
|
|
||||||
var usrcss = $("#user-defined-css").text();
|
|
||||||
const disable_header = "/* DISABLED_USER_CSS===";
|
|
||||||
if (usrcss.length > 0) {
|
|
||||||
if (boolean && usrcss.substring(0, disable_header.length) != disable_header) {
|
|
||||||
usrcss = disable_header + usrcss + "*/";
|
|
||||||
} else if (!boolean && usrcss.substring(0, disable_header.length) == disable_header) {
|
|
||||||
usrcss = usrcss.substring(disable_header.length, usrcss.length - 2);
|
|
||||||
}
|
|
||||||
$("#user-defined-css").text(usrcss);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function primeEmbed() {
|
function primeEmbed() {
|
||||||
$("#focusmodal").modal("close");
|
$("#focusmodal").modal("close");
|
||||||
has_already_been_focused = true;
|
has_already_been_focused = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user