(()=>{"use strict";const e={ruffleEnable:!0,ignoreOptout:!1,warnOnUnsupportedContent:!0,logLevel:"error",showSwfDownload:!1};let t,n,s,o,r;function c(e){return new Promise(((t,n)=>{e((e=>{const s=chrome.runtime.lastError;s?n(s):t(e)}))}))}function a(e){return{get:t=>c((n=>e.get(t||null,n))),remove:t=>c((n=>e.remove(t,n))),set:t=>c((n=>e.set(t,n)))}}if("undefined"!=typeof chrome)t=chrome.i18n,n={local:a(chrome.storage.local),sync:a(chrome.storage.sync),onChanged:{addListener:e=>chrome.storage.onChanged.addListener(e)}},s={reload:e=>c((t=>chrome.tabs.reload(e,void 0,t))),query:e=>c((t=>chrome.tabs.query(e,t))),sendMessage:(e,t,n)=>c((s=>chrome.tabs.sendMessage(e,t,n||{},s)))},o=chrome.runtime,r=()=>c((e=>chrome.tabs.create({url:"/options.html"},e)));else{if("undefined"==typeof browser)throw new Error("Extension API not found.");t=browser.i18n,n=browser.storage,s=browser.tabs,o=browser.runtime,r=()=>browser.runtime.openOptionsPage()}class i{constructor(e,t){this.checkbox=e,this.label=t}get input(){return this.checkbox}get value(){return this.checkbox.checked}set value(e){this.checkbox.checked=e}}class l{constructor(e,t){this.select=e,this.label=t}get input(){return this.select}get value(){const e=this.select.selectedIndex;return this.select.options[e].value}set value(e){const t=Array.from(this.select.options).findIndex((t=>t.value===e));this.select.selectedIndex=t}}function u(e){const[t]=e.getElementsByTagName("label"),[n]=e.getElementsByTagName("input");if(n&&"checkbox"===n.type)return new i(n,t);const[s]=e.getElementsByTagName("select");if(s)return new l(s,t);throw new Error("Unknown option element")}window.addEventListener("DOMContentLoaded",(()=>{document.title=t.getMessage("settings_page"),async function(s){const o=function(){const e=new Map;for(const t of document.getElementsByClassName("option")){const n=u(t),s=n.input.id.replace(/[^a-z\d](.)/gi,((e,t)=>t.toUpperCase()));e.set(s,n)}return e}(),r=await async function(){const t=await n.sync.get();return Object.assign(Object.assign({},e),t)}();for(const[e,s]of o.entries()){s.value=r[e],s.label.classList.add("notransition"),s.label.offsetHeight,s.label.classList.remove("notransition");const o=t.getMessage(`settings_${s.input.id}`);o&&(s.label.textContent=o),s.input.addEventListener("change",(()=>{const t=s.value;r[e]=t,n.sync.set({[e]:t})}))}n.onChanged.addListener(((e,t)=>{if("sync"===t){for(const[t,n]of Object.entries(e)){const e=o.get(t);e&&(e.value=n.newValue,r[t]=n.newValue)}s&&s(r)}})),s&&s(r)}()}))})();