Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite logic to check config for enabled status #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 34 additions & 43 deletions dist/animated-background.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ function currentConfig() {
//logic for checking if enabled in configuration
function enabled() {
var temp_enabled = false;
var excluded = {
user: false,
device: false
}
if (Animated_Config) {
if (Animated_Config.default_url || Animated_Config.entity || Animated_Config.views || Animated_Config.groups) {
temp_enabled = true;
Expand All @@ -229,93 +233,80 @@ function enabled() {
//Root configuration exceptions
if (Animated_Config.excluded_devices) {
if (Animated_Config.excluded_devices.some(deviceIncluded)) {
if (temp_enabled) {
DEBUG_MESSAGE("Current device is excluded", null, true);
temp_enabled = false;
}
DEBUG_MESSAGE("Current device is excluded", null, true);
excluded.device = true;
}
}

if (Animated_Config.excluded_users) {
if (Animated_Config.excluded_users.map(username => username.toLowerCase()).includes(Haobj.user.name.toLowerCase())) {
if (temp_enabled) {
DEBUG_MESSAGE("Current user: " + Haobj.user.name + " is excluded", null, true);
temp_enabled = false;
}
DEBUG_MESSAGE("Current user: " + Haobj.user.name + " is excluded", null, true);
excluded.user = true;
}
}

if (Animated_Config.included_users) {
if (Animated_Config.included_users.map(username => username.toLowerCase()).includes(Haobj.user.name.toLowerCase())) {
temp_enabled = true;
excluded.user = false;
}
else {
if (temp_enabled) {
DEBUG_MESSAGE("Current user: " + Haobj.user.name + " is not included", null, true);
temp_enabled = false;
}
DEBUG_MESSAGE("Current user: " + Haobj.user.name + " is not included", null, true);
excluded.user = true;
}
}

if (Animated_Config.included_devices) {
if (Animated_Config.included_devices.some(deviceIncluded)) {
temp_enabled = true;
excluded.device = false;
}
else {
if (temp_enabled) {
DEBUG_MESSAGE("Current device is not included", null, true);
temp_enabled = false;
}
DEBUG_MESSAGE("Current device is not included", null, true);
excluded.device = true;
}
}

//Current config overrides (only does anything if curre_config and Animated_Config are different)
if (current_config.excluded_devices) {
if (current_config.excluded_devices.some(deviceIncluded)) {
if (temp_enabled) {
DEBUG_MESSAGE("Current device is excluded", null, true);
temp_enabled = false;
}
DEBUG_MESSAGE("Current device is excluded", null, true);
excluded.device = true;
}
}

if (current_config.excluded_users) {
if (current_config.excluded_users.map(username => username.toLowerCase()).includes(Haobj.user.name.toLowerCase())) {
if (temp_enabled) {
DEBUG_MESSAGE("Current user: " + Haobj.user.name + " is excluded", null, true);
temp_enabled = false;
}
DEBUG_MESSAGE("Current user: " + Haobj.user.name + " is excluded", null, true);
excluded.user = true;
}
}

if (current_config.included_users) {
if (current_config.included_users.map(username => username.toLowerCase()).includes(Haobj.user.name.toLowerCase())) {
temp_enabled = true;
excluded.user = false;
}
else {
if (temp_enabled) {
DEBUG_MESSAGE("Current user: " + Haobj.user.name + " is not included", null, true);
temp_enabled = false;
}
DEBUG_MESSAGE("Current user: " + Haobj.user.name + " is not included", null, true);
excluded.user = true;
}
}

if (current_config.included_devices) {
if (current_config.included_devices.some(deviceIncluded)) {
temp_enabled = true;
excluded.device = false;
}
else {
if (temp_enabled) {
DEBUG_MESSAGE("Current device is not included", null, true);
temp_enabled = false;
}
DEBUG_MESSAGE("Current device is not included", null, true);
excluded.device = true;
}
}

if (Object.values(excluded).some(element => element == true)) {
temp_enabled = false;
}
if (current_config.enabled == false) {
temp_enabled = false;
}
if (current_config.enabled == true) {
if (current_config.enabled == true && !Object.values(excluded).some(element => element == true)) {
temp_enabled = true;
}

Expand Down Expand Up @@ -448,7 +439,7 @@ function renderBackgroundHTML() {
margin: 0;
position: relative;
}

video {
min-width: 100%;
min-height: 100%;
Expand All @@ -471,7 +462,7 @@ function renderBackgroundHTML() {
transform: translate(-50%, -50%);
}
</style>
</head>
</head>
<body id='source-body'>
${doc_body}
</body>
Expand All @@ -483,23 +474,23 @@ function renderBackgroundHTML() {
var style = document.createElement("style");
style.innerHTML = `
.bg-video{
min-width: 100vw;
min-width: 100vw;
min-height: 100vh;

}
.bg-wrap{
position: fixed;
right: 0;
top: 0;
min-width: 100vw;
min-width: 100vw;
min-height: 100vh;
z-index: -10;
}`;
var div = document.createElement("div");
div.id = "background-video";
div.className = "bg-wrap"
div.innerHTML = `
<iframe id="background-iframe" class="bg-video" frameborder="0" srcdoc="${source_doc}"/>
<iframe id="background-iframe" class="bg-video" frameborder="0" srcdoc="${source_doc}"/>
`;
Root.shadowRoot.appendChild(style);
Root.shadowRoot.appendChild(div)
Expand Down