Skip to content

Commit

Permalink
added list options for exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Villhellm committed Jul 26, 2020
1 parent b2212ea commit 2ae0262
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 22 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ Exceptions can be used if you would like to define an order for a specific user/
| Name | Type | Requirement | Description
| ---- | ---- | ------- | -----------
| base_order | bool | **Optional** | If true this will run rearrangement for your base order configuration before running this exception. Default is false.
| user | string | **Optional** | Home Assistant user name you would like to display this order for.
| device | string | **Optional** | Type of device you would like to display this order for. ex: ipad, iphone, macintosh, windows, android
| not_user | string | **Optional** | Every Home Assistant user name *except* this user name.
| not_device | string | **Optional** | Every device *except* this device. ex: ipad, iphone, macintosh, windows, android
| user | string, list | **Optional** | Home Assistant user name you would like to display this order for.
| device | string, list | **Optional** | Type of device you would like to display this order for. ex: ipad, iphone, macintosh, windows, android
| not_user | string, list | **Optional** | Every Home Assistant user name *except* this user name.
| not_device | string, list | **Optional** | Every device *except* this device. ex: ipad, iphone, macintosh, windows, android
| order | [order](#order) | **Required** | Define and order.

Ex sidebar-order.yaml using exceptions:
Expand All @@ -141,7 +141,7 @@ exceptions:
order:
- item: map
hide: false
- item: developer_tools
- item: developer tools
hide: true
```
Expand Down
76 changes: 59 additions & 17 deletions dist/custom-sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,67 @@ function Current_Order(config) {
var current_environment_enabled = true;
var current_exception_keys = Object.keys(current_exception);
for (var x = 0; x < current_exception_keys.length; x++) {
console.log(navigator.userAgent);
switch (current_exception_keys[x]) {
case "user":
if (current_exception.user.toLowerCase() != Haobj.user.name.toLowerCase()) {
current_environment_enabled = false;
if(current_exception.user.includes(',')){
current_exception.user = current_exception.user.replace(/, /g, ',').split(',');
}
if (current_exception.user instanceof Array) {
current_environment_enabled = current_exception.user.map(x => x.toLowerCase()).some(x => x == Haobj.user.name.toLowerCase());
}
else {
if (current_exception.user.toLowerCase() != Haobj.user.name.toLowerCase()) {
current_environment_enabled = false;
}
}
break;
case "device":
if (!navigator.userAgent.toLowerCase().includes(current_exception.device.toLowerCase())) {
if(current_exception.device.includes(',')){
current_exception.device = current_exception.device.replace(/, /g, ',').split(',');
}
if (current_exception.device instanceof Array) {
current_environment_enabled = false;
current_exception.device.forEach(device=>{
if (navigator.userAgent.toLowerCase().includes(device.toLowerCase())) {
current_environment_enabled = true;
}
});
}
else {
if (!navigator.userAgent.toLowerCase().includes(current_exception.device.toLowerCase())) {
current_environment_enabled = false;
}
}
break;
case "not_user":
if (current_exception.not_user.toLowerCase() == Haobj.user.name.toLowerCase()) {
current_environment_enabled = false;
if(current_exception.not_user.includes(',')){
current_exception.not_user = current_exception.not_user.replace(/, /g, ',').split(',');
}
if (current_exception.not_user instanceof Array) {
current_environment_enabled = !current_exception.not_user.map(x => x.toLowerCase()).some(x => x == Haobj.user.name.toLowerCase());
}
else {
if (current_exception.not_user.toLowerCase() == Haobj.user.name.toLowerCase()) {
current_environment_enabled = false;
}
}
break;
case "not_device":
if (navigator.userAgent.toLowerCase().includes(current_exception.not_device.toLowerCase())) {
current_environment_enabled = false;
if(current_exception.not_device.includes(',')){
current_exception.not_device = current_exception.not_device.replace(/, /g, ',').split(',');
}
if (current_exception.not_device instanceof Array) {
current_exception.not_device.forEach(not_device=>{
if (navigator.userAgent.toLowerCase().includes(not_device.toLowerCase())) {
current_environment_enabled = false;
}
});
}
else {
if (navigator.userAgent.toLowerCase().includes(current_exception.not_device.toLowerCase())) {
current_environment_enabled = false;
}
}
break;
}
Expand Down Expand Up @@ -126,7 +168,7 @@ function getConfigurationElement(elements) {
function moveItem(elements, config_entry) {
for (var i = 0; i < elements.children.length; i++) {
if (elements.children[i].tagName == "A") {
var current = elements.children[i].children[0].getElementsByTagName("span")[0].innerHTML.replace('<!---->','').replace('<!---->','');
var current = elements.children[i].children[0].getElementsByTagName("span")[0].innerHTML.replace('<!---->', '').replace('<!---->', '');
var match = false;
if (config_entry.exact) {
match = current == config_entry.item;
Expand All @@ -139,8 +181,8 @@ function moveItem(elements, config_entry) {
elements.children[i].href = config_entry.href;
}

if(config_entry.name){
elements.children[i].children[0].getElementsByTagName("span")[0].innerHTML = elements.children[i].children[0].getElementsByTagName("span")[0].innerHTML.replace(current,config_entry.name);
if (config_entry.name) {
elements.children[i].children[0].getElementsByTagName("span")[0].innerHTML = elements.children[i].children[0].getElementsByTagName("span")[0].innerHTML.replace(current, config_entry.name);
}

if (config_entry.icon) {
Expand Down Expand Up @@ -213,7 +255,7 @@ function rando() {
Inline = require('./Inline');

Dumper = (function () {
function Dumper() {}
function Dumper() { }

Dumper.indentation = 4;

Expand Down Expand Up @@ -275,7 +317,7 @@ function rando() {
Escaper = (function () {
var ch;

function Escaper() {}
function Escaper() { }

Escaper.LIST_ESCAPEES = ['\\', '\\\\', '\\"', '"', "\x00", "\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07", "\x08", "\x09", "\x0a", "\x0b", "\x0c", "\x0d", "\x0e", "\x0f", "\x10", "\x11", "\x12", "\x13", "\x14", "\x15", "\x16", "\x17", "\x18", "\x19", "\x1a", "\x1b", "\x1c", "\x1d", "\x1e", "\x1f", (ch = String.fromCharCode)(0x0085), ch(0x00A0), ch(0x2028), ch(0x2029)];

Expand Down Expand Up @@ -481,7 +523,7 @@ function rando() {
DumpException = require('./Exception/DumpException');

Inline = (function () {
function Inline() {}
function Inline() { }

Inline.REGEX_QUOTED_STRING = '(?:"(?:[^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'(?:[^\']*(?:\'\'[^\']*)*)\')';

Expand Down Expand Up @@ -1700,7 +1742,7 @@ function rando() {
Pattern = require('./Pattern');

Unescaper = (function () {
function Unescaper() {}
function Unescaper() { }

Unescaper.PATTERN_ESCAPED_CHARACTER = new Pattern('\\\\([0abt\tnvfre "\\/\\\\N_LP]|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8})');

Expand Down Expand Up @@ -1788,7 +1830,7 @@ function rando() {
Pattern = require('./Pattern');

Utils = (function () {
function Utils() {}
function Utils() { }

Utils.REGEX_LEFT_TRIM_BY_CHAR = {};

Expand Down Expand Up @@ -2027,7 +2069,7 @@ function rando() {
name = ref[j];
try {
xhr = new ActiveXObject(name);
} catch (undefined) {}
} catch (undefined) { }
}
}
}
Expand Down Expand Up @@ -2093,7 +2135,7 @@ function rando() {
Utils = require('./Utils');

Yaml = (function () {
function Yaml() {}
function Yaml() { }

Yaml.parse = function (input, exceptionOnInvalidType, objectDecoder) {
if (exceptionOnInvalidType == null) {
Expand Down

0 comments on commit 2ae0262

Please sign in to comment.