-
Notifications
You must be signed in to change notification settings - Fork 209
Browser Mod Ghost ‐ Managing multiple tabs on a desktop
This experimental mod was created by @dcapslock per feature request #687
Browser Mod Ghost allows for 'Ghosting' certain Browser Mod commands when using multiple tabs on a desktop Browser. The following Ghost options are available.
- Ghost Player Commands - allows for a tab to not respond to any Browser Mod media player commands.
- Ghost Navigate - allows for tab to not respond to
browser_mod.navigate
. - Ghost Popup - allows for tab to not respond to
browser_mod.popup
. - Ghost Notification - allows for tab to not respond to
browser_mod.notification
. - Ghost Updates - allows for tab to not send any updates including media player status.
Browser Mod Ghost settings are saved in session storage, so will remain set so long as the tab is kept open, even surving page refresh.
NOTE: In most cases, using browser calls should alleviate any need for Browser Mod Ghost. However, if you are using automations to the Browser but don't want to target all tabs, or you are using the Browser media player, you may find Browser Mod Ghost useful.
IMPORTANT: While Browser Mod Ghost javascript items have been throughly tested, use at your own risk.
Included below are the Javascript snippets used in Browser Mod Ghost with a short explanation of what each snippet does.
window.browser_mod_ghost_commands=JSON.parse(window.sessionStorage.getItem("browser_mod_ghost_commands")||'{"command-player":false,"command-navigate":false,"command-popup":false,"command-notification":false,"sendUpdate":false}');
- Reads Browser Mod Ghost settings from session storage, setting defaults of
false
(no Ghost) if they do not exist.
window.browser_mod.fireBrowserEvent=function(e,t=void 0){let g=!1;for(const[k,v] of Object.entries(window.browser_mod_ghost_commands)){if(e.startsWith(k)&&v)g=!0};if(g)return;this.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0}))}
- Patches Browser Mod main event firing function, allowing for commands to be Ghosted for a tab.
window.browser_mod_ghost_config=function(){window.browser_mod.showPopup("Browser Mod Ghost",[{selector:{boolean:{}},label:"Ghost Player Commands",name:"command-player",default:window.browser_mod_ghost_commands?.['command-player']},{selector:{boolean:{}},label:"Ghost Navigate",name:"command-navigate",default:window.browser_mod_ghost_commands?.['command-navigate']},{selector:{boolean:{}},label:"Ghost Popup",name:"command-popup",default:window.browser_mod_ghost_commands?.['command-popup']},{selector:{boolean:{}},label:"Ghost Notification",name:"command-notification",default:window.browser_mod_ghost_commands?.['command-notification']},{selector:{boolean:{}},label:"Ghost Updates",name:"sendUpdate",default:window.browser_mod_ghost_commands?.['sendUpdate']}],{right_button:"OK",right_button_action:(d)=>{window.browser_mod_ghost_commands=d;window.sessionStorage.setItem("browser_mod_ghost_commands",JSON.stringify(d))},left_button:"Cancel"})}
- A configuration option which allows for changing Browser Mod Ghost settings. It uses Browser Mod popup internally directly so will always function no matter if you have set to have popups Ghosted.
document.body.addEventListener("ll-custom",(ev)=>{if(ev.detail.browser_mod_ghost_config){window.browser_mod_ghost_config()}});
- Setting up a listener to be able to open up Browser Mod Ghost settings from a Home Assistant action.
window.browser_mod.sendUpdateOrig=window.browser_mod.sendUpdate;window.browser_mod.sendUpdate=function(d){if(window.browser_mod_ghost_commands?.['sendUpdate'])return;window.browser_mod.sendUpdateOrig(d)}
- Patches Browser Mod sensor update routine so as to be able to Ghost Updates.
To get Browser Mod Ghost setup, all you need to do is put together the above Javascript snippets into the Browser Mod Default action Frontend setting for the Browser. Once this is done you will be able to use a Home Assistant action to call up Browser Mod Ghost settings.
Copy and paste the yaml below into the Default action for your Browser.
- action: browser_mod.javascript
data:
code: >
window.browser_mod_ghost_commands=JSON.parse(window.sessionStorage.getItem("browser_mod_ghost_commands")||'{"command-player":false,"command-navigate":false,"command-popup":false,"command-notification":false,"sendUpdate":false}');
- action: browser_mod.javascript
data:
code: >
window.browser_mod.fireBrowserEvent=function(e,t=void 0){let
g=!1;for(const[k,v] of
Object.entries(window.browser_mod_ghost_commands)){if(e.startsWith(k)&&v)g=!0};if(g)return;this.dispatchEvent(new
CustomEvent(e,{detail:t,bubbles:!0}))}
- action: browser_mod.javascript
data:
code: >
window.browser_mod_ghost_config=function(){window.browser_mod.showPopup("Browser
Mod Ghost",[{selector:{boolean:{}},label:"Ghost Player
Commands",name:"command-player",default:window.browser_mod_ghost_commands?.['command-player']},{selector:{boolean:{}},label:"Ghost
Navigate",name:"command-navigate",default:window.browser_mod_ghost_commands?.['command-navigate']},{selector:{boolean:{}},label:"Ghost
Popup",name:"command-popup",default:window.browser_mod_ghost_commands?.['command-popup']},{selector:{boolean:{}},label:"Ghost
Notification",name:"command-notification",default:window.browser_mod_ghost_commands?.['command-notification']},{selector:{boolean:{}},label:"Ghost
Updates",name:"sendUpdate",default:window.browser_mod_ghost_commands?.['sendUpdate']}],{right_button:"OK",right_button_action:(d)=>{window.browser_mod_ghost_commands=d;window.sessionStorage.setItem("browser_mod_ghost_commands",JSON.stringify(d))},left_button:"Cancel"})}
- action: browser_mod.javascript
data:
code: >
document.body.addEventListener("ll-custom",(ev)=>{if(ev.detail.browser_mod_ghost_config){window.browser_mod_ghost_config()}});
- action: browser_mod.javascript
data:
code: >
window.browser_mod.sendUpdateOrig=window.browser_mod.sendUpdate;window.browser_mod.sendUpdate=function(d){if(window.browser_mod_ghost_commands?.['sendUpdate'])return;window.browser_mod.sendUpdateOrig(d)}
Use the yaml below to set up a Home Assistant action to call up the Browser Mod Ghost settings for the Browser tab.
tap_action:
action: fire-dom-event
browser_mod_ghost_config: true
Below is full config for a simple button to call up Browser Mod Ghost settings.
show_name: true
show_icon: true
type: button
name: Browser Mod Ghost config
tap_action:
action: fire-dom-event
browser_mod_ghost_config: true