2017-12-29 23:34:40 +01:00
|
|
|
if(Debug.debug)
|
|
|
|
console.log("[popup.js] loading popup script!");
|
|
|
|
|
2017-12-30 02:58:24 +01:00
|
|
|
document.getElementById("uw-version").textContent = browser.runtime.getManifest().version;
|
2017-12-29 23:34:40 +01:00
|
|
|
|
2017-12-30 02:58:24 +01:00
|
|
|
var Menu = {};
|
2018-02-02 00:21:29 +01:00
|
|
|
// Menu.noVideo = document.getElementById("no-videos-display");
|
2018-06-29 00:30:42 +02:00
|
|
|
Menu.thisSite = document.getElementById("settings-for-current-site");
|
|
|
|
Menu.arSettings = document.getElementById("aspect-ratio-settings");
|
|
|
|
Menu.autoAr = document.getElementById("autoar-basic-settings");
|
|
|
|
Menu.cssHacks = document.getElementById("css-hacks-settings");
|
|
|
|
Menu.about = document.getElementById("panel-about");
|
|
|
|
Menu.stretchSettings = document.getElementById("stretch-settings")
|
2017-12-29 23:34:40 +01:00
|
|
|
|
2017-12-30 02:58:24 +01:00
|
|
|
var MenuTab = {};
|
2018-06-29 00:30:42 +02:00
|
|
|
MenuTab.general = document.getElementById("_menu_general");
|
|
|
|
MenuTab.thisSite = document.getElementById("_menu_this_site");
|
|
|
|
MenuTab.arSettings = document.getElementById("_menu_aspectratio");
|
|
|
|
MenuTab.cssHacks = document.getElementById("_menu_hacks");
|
|
|
|
MenuTab.about = document.getElementById("_menu_about");
|
|
|
|
MenuTab.autoAr = document.getElementById("_menu_autoar");
|
|
|
|
MenuTab.stretchSettings = document.getElementById("_menu_stretch");
|
2017-12-29 23:34:40 +01:00
|
|
|
|
2018-06-27 23:55:37 +02:00
|
|
|
var ExtPanel = {};
|
2018-06-28 23:43:52 +02:00
|
|
|
ExtPanel.globalOptions = {};
|
|
|
|
ExtPanel.globalOptions.blacklist = document.getElementById("_ext_global_options_blacklist");
|
|
|
|
ExtPanel.globalOptions.whitelist = document.getElementById("_ext_global_options_whitelist");
|
|
|
|
ExtPanel.globalOptions.disabled = document.getElementById("_ext_global_options_disabled");
|
2018-06-27 23:55:37 +02:00
|
|
|
ExtPanel.siteOptions = {};
|
|
|
|
ExtPanel.siteOptions.disabled = document.getElementById("_ext_site_options_blacklist");
|
|
|
|
ExtPanel.siteOptions.enabled = document.getElementById("_ext_site_options_whitelist");
|
|
|
|
ExtPanel.siteOptions.default = document.getElementById("_ext_site_options_default");
|
|
|
|
|
|
|
|
var AutoArPanel = {};
|
2018-06-28 23:43:52 +02:00
|
|
|
AutoArPanel.globalOptions = {};
|
|
|
|
AutoArPanel.globalOptions.blacklist = document.getElementById("_ar_global_options_blacklist");
|
|
|
|
AutoArPanel.globalOptions.whitelist = document.getElementById("_ar_global_options_whitelist");
|
|
|
|
AutoArPanel.globalOptions.disabled = document.getElementById("_ar_global_options_disabled");
|
2018-06-27 23:55:37 +02:00
|
|
|
AutoArPanel.siteOptions = {};
|
2018-08-03 00:44:37 +02:00
|
|
|
AutoArPanel.siteOptions.disabled = document.getElementById("_ar_site_options_disabled");
|
|
|
|
AutoArPanel.siteOptions.enabled = document.getElementById("_ar_site_options_enabled");
|
2018-06-28 23:43:52 +02:00
|
|
|
AutoArPanel.siteOptions.default = document.getElementById("_ar_site_options_default");
|
2018-06-27 23:55:37 +02:00
|
|
|
|
|
|
|
var ArPanel = {};
|
2017-12-30 18:36:08 +01:00
|
|
|
ArPanel.alignment = {};
|
|
|
|
ArPanel.alignment.left = document.getElementById("_align_left");
|
|
|
|
ArPanel.alignment.center = document.getElementById("_align_center");
|
|
|
|
ArPanel.alignment.right = document.getElementById("_align_right");
|
|
|
|
ArPanel.autoar = {};
|
|
|
|
|
2018-06-29 00:30:42 +02:00
|
|
|
var StretchPanel = {};
|
|
|
|
StretchPanel.global = {};
|
|
|
|
StretchPanel.global.none = document.getElementById("_stretch_global_none");
|
|
|
|
StretchPanel.global.basic = document.getElementById("_stretch_global_basic");
|
|
|
|
StretchPanel.global.hybrid = document.getElementById("_stretch_global_hybrid");
|
|
|
|
StretchPanel.global.conditional = document.getElementById("_stretch_global_conditional");
|
|
|
|
|
2017-12-30 18:36:08 +01:00
|
|
|
|
2018-08-30 00:56:15 +02:00
|
|
|
var selectedMenu = "";
|
2017-12-30 02:58:24 +01:00
|
|
|
var hasVideos = false;
|
2017-12-29 23:34:40 +01:00
|
|
|
|
2017-12-30 18:36:08 +01:00
|
|
|
var _config;
|
2018-07-09 23:30:11 +02:00
|
|
|
var _changeAr_button_shortcuts = { "autoar":"none", "reset":"none", "219":"none", "189":"none", "169":"none", "custom":"none" }
|
2017-12-30 18:36:08 +01:00
|
|
|
|
2018-05-27 01:29:02 +02:00
|
|
|
var comms = new Comms();
|
2018-08-30 00:56:15 +02:00
|
|
|
var settings = new Settings(undefined, () => updateConfig());
|
|
|
|
|
|
|
|
var site = undefined;
|
2018-08-29 21:23:08 +02:00
|
|
|
|
2018-05-27 01:29:02 +02:00
|
|
|
var port = browser.runtime.connect({name: 'popup-port'});
|
|
|
|
port.onMessage.addListener( (m,p) => processReceivedMessage(m,p));
|
2018-01-08 22:48:45 +01:00
|
|
|
|
2018-08-29 21:23:08 +02:00
|
|
|
|
2018-05-27 01:29:02 +02:00
|
|
|
async function processReceivedMessage(message, port){
|
2018-08-30 00:56:15 +02:00
|
|
|
if(message.cmd === 'set-current-site'){
|
|
|
|
site = message.site;
|
|
|
|
loadConfig(message.site);
|
|
|
|
}
|
|
|
|
}
|
2018-08-21 23:48:47 +02:00
|
|
|
|
2018-08-30 00:56:15 +02:00
|
|
|
async function updateConfig() {
|
|
|
|
if (site) {
|
|
|
|
loadConfig(site);
|
2018-05-27 01:29:02 +02:00
|
|
|
}
|
2018-01-10 23:16:07 +01:00
|
|
|
}
|
|
|
|
|
2018-02-02 00:21:29 +01:00
|
|
|
function hideWarning(warn){
|
|
|
|
document.getElementById(warn).classList.add("hidden");
|
|
|
|
}
|
|
|
|
|
2018-01-02 03:36:29 +01:00
|
|
|
function stringToKeyCombo(key_in){
|
|
|
|
var keys_in = key_in.split("_");
|
|
|
|
var keys_out = "";
|
|
|
|
|
|
|
|
for(key of keys_in){
|
|
|
|
if(key == "ctrlKey")
|
|
|
|
keys_out += "ctrl + ";
|
|
|
|
else if(key == "shiftKey")
|
|
|
|
keys_out += "shift + ";
|
|
|
|
else if(key == "altKey")
|
|
|
|
keys_out += "alt + ";
|
|
|
|
else
|
|
|
|
keys_out += key;
|
|
|
|
}
|
|
|
|
|
|
|
|
return keys_out;
|
|
|
|
}
|
|
|
|
|
2018-08-30 00:56:15 +02:00
|
|
|
async function loadConfig(site){
|
2018-08-29 21:23:08 +02:00
|
|
|
|
2017-12-30 18:36:08 +01:00
|
|
|
if(Debug.debug)
|
2018-08-29 21:23:08 +02:00
|
|
|
console.log("[popup.js::loadConfig] loading config. conf object:", settings.active, "\n\n\n\n\n\n\n\n-------------------------------------");
|
2018-08-30 00:56:15 +02:00
|
|
|
|
|
|
|
// -----------------------
|
|
|
|
//#region tab-disabled
|
|
|
|
//
|
|
|
|
// if extension is disabled on current site, we can't do shit. Therefore, the following tabs will be disabled:
|
|
|
|
// * AutoAR options
|
|
|
|
// * Crop settings
|
|
|
|
// * Stretch settings
|
|
|
|
var canStartExtension = settings.canStartExtension(site);
|
|
|
|
|
|
|
|
if (canStartExtension) {
|
|
|
|
MenuTab.arSettings.classList.remove('disabled');
|
|
|
|
MenuTab.autoAr.classList.remove('disabled');
|
|
|
|
MenuTab.stretchSettings.classList.remove('disabled');
|
|
|
|
|
|
|
|
// only switch when popup is being opened for the first time
|
|
|
|
if(! selectedMenu) {
|
|
|
|
openMenu('arSettings');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
MenuTab.arSettings.classList.add('disabled');
|
|
|
|
MenuTab.autoAr.classList.add('disabled');
|
|
|
|
MenuTab.stretchSettings.classList.add('disabled');
|
|
|
|
|
|
|
|
// if popup isn't being opened for the first time, there's no reason to switch
|
|
|
|
// we're already in this tab
|
|
|
|
if(! selectedMenu) {
|
|
|
|
openMenu('thisSite');
|
|
|
|
}
|
|
|
|
}
|
2018-05-27 01:29:02 +02:00
|
|
|
|
2018-08-30 00:56:15 +02:00
|
|
|
//#endregion
|
|
|
|
//
|
2018-06-27 23:55:37 +02:00
|
|
|
// ----------------------
|
|
|
|
//#region extension-basics - SET BASIC EXTENSION OPTIONS
|
2018-06-29 00:30:42 +02:00
|
|
|
if(Debug.debug)
|
2018-08-29 21:23:08 +02:00
|
|
|
console.log("EXT: site is:", site, "|settings for this site: ", (site && settings.active.sites[site]) ? settings.active.sites[site] : "default site")
|
2018-06-29 00:30:42 +02:00
|
|
|
|
2018-06-27 23:55:37 +02:00
|
|
|
|
2018-06-28 23:43:52 +02:00
|
|
|
for(var button in ExtPanel.globalOptions) {
|
|
|
|
ExtPanel.globalOptions[button].classList.remove("selected");
|
|
|
|
}
|
2018-06-27 23:55:37 +02:00
|
|
|
for(var button in ExtPanel.siteOptions) {
|
|
|
|
ExtPanel.siteOptions[button].classList.remove("selected");
|
|
|
|
}
|
|
|
|
|
2018-08-29 21:23:08 +02:00
|
|
|
ExtPanel.globalOptions[settings.active.extensionMode].classList.add("selected");
|
|
|
|
if(site && settings.active.sites[site]) {
|
|
|
|
ExtPanel.siteOptions[settings.active.sites[site].status].classList.add("selected");
|
2018-06-28 23:43:52 +02:00
|
|
|
} else {
|
|
|
|
ExtPanel.siteOptions.default.classList.add("selected");
|
2018-06-27 23:55:37 +02:00
|
|
|
}
|
2018-07-09 23:30:11 +02:00
|
|
|
|
2018-06-27 23:55:37 +02:00
|
|
|
//#endregion extension-basics
|
|
|
|
//
|
|
|
|
// ------------
|
|
|
|
//#region autoar - SET AUTOAR OPTIONS
|
2018-06-28 23:43:52 +02:00
|
|
|
// if(Debug.debug)
|
2018-08-29 21:23:08 +02:00
|
|
|
// console.log("Autodetect mode?", settings.active.arDetect.mode, "| site & site options:", site, ",", (site && settings.active.sites[site]) ? settings.active.sites[site].arStatus : "fucky wucky?" );
|
|
|
|
// document.getElementById("_autoAr_disabled_reason").textContent = settings.active.arDetect.DisabledReason;
|
|
|
|
document.getElementById("_input_autoAr_timer").value = settings.active.arDetect.timer_playing;
|
2018-06-27 23:55:37 +02:00
|
|
|
|
2018-06-28 23:43:52 +02:00
|
|
|
|
|
|
|
for(var button in AutoArPanel.globalOptions) {
|
|
|
|
AutoArPanel.globalOptions[button].classList.remove("selected");
|
|
|
|
}
|
2018-06-27 23:55:37 +02:00
|
|
|
for(var button in AutoArPanel.siteOptions) {
|
|
|
|
AutoArPanel.siteOptions[button].classList.remove("selected");
|
|
|
|
}
|
|
|
|
|
2018-06-29 00:30:42 +02:00
|
|
|
|
2018-08-29 21:23:08 +02:00
|
|
|
AutoArPanel.globalOptions[settings.active.arDetect.mode].classList.add("selected");
|
|
|
|
if(site && settings.active.sites[site]) {
|
|
|
|
AutoArPanel.siteOptions[settings.active.sites[site].arStatus].classList.add("selected");
|
2018-06-28 23:43:52 +02:00
|
|
|
} else {
|
|
|
|
AutoArPanel.siteOptions.default.classList.add("selected");
|
2018-06-27 23:55:37 +02:00
|
|
|
}
|
|
|
|
//#endregion
|
|
|
|
|
2017-12-30 18:36:08 +01:00
|
|
|
// process video alignment:
|
2018-08-29 21:23:08 +02:00
|
|
|
if(settings.active.miscFullscreenSettings.videoFloat){
|
2017-12-30 18:36:08 +01:00
|
|
|
for(var button in ArPanel.alignment)
|
|
|
|
ArPanel.alignment[button].classList.remove("selected");
|
|
|
|
|
2018-08-29 21:23:08 +02:00
|
|
|
ArPanel.alignment[settings.active.miscFullscreenSettings.videoFloat].classList.add("selected");
|
2017-12-30 18:36:08 +01:00
|
|
|
}
|
2018-07-09 23:30:11 +02:00
|
|
|
|
2018-06-29 00:30:42 +02:00
|
|
|
//#region - SET STRETCH
|
2018-07-09 23:30:11 +02:00
|
|
|
|
|
|
|
// set stretching
|
2018-06-29 00:30:42 +02:00
|
|
|
for (var button in StretchPanel.global) {
|
|
|
|
StretchPanel.global[button].classList.remove("selected");
|
|
|
|
}
|
2018-08-29 21:23:08 +02:00
|
|
|
if (settings.active.stretch.initialMode === 0) {
|
2018-06-29 00:30:42 +02:00
|
|
|
StretchPanel.global.none.classList.add("selected");
|
2018-08-29 21:23:08 +02:00
|
|
|
} else if (settings.active.stretch.initialMode === 1) {
|
2018-06-29 00:30:42 +02:00
|
|
|
StretchPanel.global.basic.classList.add("selected");
|
2018-08-29 21:23:08 +02:00
|
|
|
} else if (settings.active.stretch.initialMode === 2) {
|
2018-06-29 00:30:42 +02:00
|
|
|
StretchPanel.global.hybrid.classList.add("selected");
|
2018-08-29 21:23:08 +02:00
|
|
|
} else if (settings.active.stretch.initialMode === 3) {
|
2018-06-29 00:30:42 +02:00
|
|
|
StretchPanel.global.conditional.classList.add("selected");
|
|
|
|
}
|
|
|
|
//#endregion
|
|
|
|
|
2018-01-02 03:36:29 +01:00
|
|
|
// process keyboard shortcuts:
|
2018-08-29 21:23:08 +02:00
|
|
|
if(settings.active.keyboard.shortcuts){
|
|
|
|
for(var key in settings.active.keyboard.shortcuts){
|
|
|
|
var shortcut = settings.active.keyboard.shortcuts[key];
|
2018-01-02 03:36:29 +01:00
|
|
|
var keypress = stringToKeyCombo(key);
|
|
|
|
|
|
|
|
|
|
|
|
try{
|
2018-05-27 01:29:02 +02:00
|
|
|
if(shortcut.action == "crop"){
|
2018-07-09 23:30:11 +02:00
|
|
|
if (key == 'q') {
|
|
|
|
_changeAr_button_shortcuts["custom"] = keypress;
|
|
|
|
}
|
|
|
|
else if(shortcut.arg == 2.0){
|
2018-01-02 03:36:29 +01:00
|
|
|
_changeAr_button_shortcuts["189"] = keypress;
|
|
|
|
}
|
2018-05-27 01:29:02 +02:00
|
|
|
else if(shortcut.arg == 2.39){
|
2018-01-02 03:36:29 +01:00
|
|
|
_changeAr_button_shortcuts["219"] = keypress;
|
|
|
|
}
|
2018-05-27 01:29:02 +02:00
|
|
|
else if(shortcut.arg == 1.78){
|
2018-01-02 03:36:29 +01:00
|
|
|
_changeAr_button_shortcuts["169"] = keypress;
|
|
|
|
}
|
2018-05-27 01:29:02 +02:00
|
|
|
else if(shortcut.arg == "fitw") {
|
|
|
|
_changeAr_button_shortcuts["fitw"] = keypress;
|
|
|
|
}
|
|
|
|
else if(shortcut.arg == "fith") {
|
|
|
|
_changeAr_button_shortcuts["fith"] = keypress;
|
|
|
|
}
|
|
|
|
else if(shortcut.arg == "reset") {
|
|
|
|
_changeAr_button_shortcuts["reset"] = keypress;
|
|
|
|
}
|
2018-01-02 03:36:29 +01:00
|
|
|
}
|
2018-05-27 01:29:02 +02:00
|
|
|
else if(shortcut.action == "auto-ar") {
|
|
|
|
_changeAr_button_shortcuts["auto-ar"] = keypress;
|
2018-01-02 03:36:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(Ex){
|
|
|
|
//do nothing if key doesn't exist
|
|
|
|
}
|
2018-07-09 23:30:11 +02:00
|
|
|
|
|
|
|
// fill in custom aspect ratio
|
2018-08-29 21:23:08 +02:00
|
|
|
if (settings.active.keyboard.shortcuts.q) {
|
|
|
|
document.getElementById("_input_custom_ar").value = settings.active.keyboard.shortcuts.q.arg;
|
2018-07-09 23:30:11 +02:00
|
|
|
}
|
2018-01-02 03:36:29 +01:00
|
|
|
}
|
|
|
|
for(var key in _changeAr_button_shortcuts){
|
|
|
|
try{
|
2018-05-27 01:29:02 +02:00
|
|
|
document.getElementById(`_b_changeAr_${key}_key`).textContent = `(${_changeAr_button_shortcuts[key]})`;
|
2018-01-02 03:36:29 +01:00
|
|
|
}
|
|
|
|
catch(ex){
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-27 01:29:02 +02:00
|
|
|
|
|
|
|
if(Debug.debug)
|
|
|
|
console.log("[popup.js::loadConfig] config loaded");
|
2017-12-30 18:36:08 +01:00
|
|
|
}
|
|
|
|
|
2018-08-30 00:56:15 +02:00
|
|
|
async function getSite(){
|
|
|
|
port.postMessage({cmd: 'get-current-site'});
|
2018-05-27 01:29:02 +02:00
|
|
|
}
|
2017-12-30 18:36:08 +01:00
|
|
|
|
2017-12-30 02:58:24 +01:00
|
|
|
function openMenu(menu){
|
|
|
|
if(Debug.debug){
|
|
|
|
console.log("[popup.js::openMenu] trying to open menu", menu, "| element: ", Menu[menu]);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(var m in Menu){
|
2018-08-07 23:31:28 +02:00
|
|
|
if(Menu[m] === null)
|
|
|
|
continue; //todo: remove menus that are no longer there
|
|
|
|
|
2017-12-30 02:58:24 +01:00
|
|
|
Menu[m].classList.add("hidden");
|
|
|
|
}
|
|
|
|
for(var m in MenuTab){
|
|
|
|
if(MenuTab[m])
|
|
|
|
MenuTab[m].classList.remove("selected");
|
|
|
|
}
|
|
|
|
|
|
|
|
if(menu == "arSettings" || menu == "cssHacks" ){
|
2018-05-27 01:29:02 +02:00
|
|
|
// if(!hasVideos)
|
|
|
|
// Menu.noVideo.classList.remove("hidden");
|
|
|
|
// else{
|
2017-12-30 02:58:24 +01:00
|
|
|
Menu[menu].classList.remove("hidden");
|
|
|
|
if(Debug.debug){
|
|
|
|
console.log("[popup.js::openMenu] unhid", menu, "| element: ", Menu[menu]);
|
2018-05-27 01:29:02 +02:00
|
|
|
}
|
|
|
|
// }
|
2017-12-30 02:58:24 +01:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
Menu[menu].classList.remove("hidden");
|
|
|
|
if(Debug.debug){
|
|
|
|
console.log("[popup.js::openMenu] unhid", menu, "| element: ", Menu[menu]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-04 17:39:26 +01:00
|
|
|
selectedMenu = menu;
|
|
|
|
MenuTab[menu].classList.add("selected");
|
2017-12-30 02:58:24 +01:00
|
|
|
}
|
2017-12-29 23:34:40 +01:00
|
|
|
|
2018-02-01 00:26:16 +01:00
|
|
|
|
2018-07-09 23:30:11 +02:00
|
|
|
function getCustomAspectRatio() {
|
|
|
|
var textBox_value = document.getElementById("_input_custom_ar").value.trim();
|
|
|
|
// validate value - this spaghett will match the following stuff
|
|
|
|
// [int]/[int]
|
|
|
|
// 1:[float]
|
|
|
|
// [float]
|
|
|
|
if (! /(^[0-9]+\/[0-9]+$|^(1:)?[0-9]+\.?[0-9]*$)/.test(textBox_value)) {
|
|
|
|
return false; // validation failed!
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! isNaN(parseFloat(textBox_value))) {
|
|
|
|
return parseFloat(textBox_value);
|
|
|
|
}
|
|
|
|
if (/\//.test(textBox_value)) {
|
|
|
|
const vars = textBox_value.split('/');
|
|
|
|
return parseInt(vars[0])/parseInt(vars[1]); // non-ints shouldn't make it past regex
|
|
|
|
}
|
|
|
|
if (/:/.test(textBox_value)) {
|
|
|
|
const vars = textBox_value.split(':');
|
|
|
|
return parseFloat(vars[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// we should never come this far.
|
|
|
|
// If we do, then there's something wrong with the input and our regex
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function validateCustomAr(){
|
|
|
|
const valid = getCustomAspectRatio() !== false;
|
|
|
|
const inputField = document.getElementById("_input_custom_ar");
|
|
|
|
const valueSaveButton = document.getElementById("_b_changeAr_save_custom_ar");
|
|
|
|
|
|
|
|
if (valid) {
|
|
|
|
inputField.classList.remove("invalid-input");
|
|
|
|
valueSaveButton.classList.remove("disabled-button");
|
|
|
|
} else {
|
|
|
|
inputField.classList.add("invalid-input");
|
|
|
|
valueSaveButton.classList.add("disabled-button");
|
|
|
|
}
|
|
|
|
}
|
2018-03-13 00:36:10 +01:00
|
|
|
|
2018-07-09 23:40:26 +02:00
|
|
|
function validateAutoArTimeout(){
|
|
|
|
const inputField = document.getElementById("_input_autoAr_timer");
|
2018-08-30 00:56:15 +02:00
|
|
|
const valueSaveButton = document.getElementById("_b_autoar_save_autoar_timer");
|
2018-07-09 23:40:26 +02:00
|
|
|
|
2018-08-30 00:56:15 +02:00
|
|
|
if (! isNaN(parseInt(inputField.value.trim().value()))) {
|
2018-07-09 23:40:26 +02:00
|
|
|
inputField.classList.remove("invalid-input");
|
|
|
|
valueSaveButton.classList.remove("disabled-button");
|
|
|
|
} else {
|
|
|
|
inputField.classList.add("invalid-input");
|
|
|
|
valueSaveButton.classList.add("disabled-button");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-29 23:34:40 +01:00
|
|
|
document.addEventListener("click", (e) => {
|
|
|
|
|
|
|
|
|
|
|
|
function getcmd(e){
|
|
|
|
var command = {};
|
|
|
|
command.sender = "popup";
|
|
|
|
command.receiver = "uwbg";
|
|
|
|
|
2017-12-30 02:58:24 +01:00
|
|
|
if(e.target.classList.contains("disabled"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(e.target.classList.contains("menu-item")){
|
2018-02-01 00:26:16 +01:00
|
|
|
if(e.target.classList.contains("_menu_this_site")){
|
|
|
|
openMenu("thisSite");
|
|
|
|
}
|
2017-12-30 02:58:24 +01:00
|
|
|
else if(e.target.classList.contains("_menu_aspectratio")){
|
|
|
|
openMenu("arSettings");
|
|
|
|
}
|
2018-06-29 00:30:42 +02:00
|
|
|
else if(e.target.classList.contains("_menu_stretch")){
|
|
|
|
openMenu("stretchSettings");
|
|
|
|
}
|
2017-12-30 02:58:24 +01:00
|
|
|
else if(e.target.classList.contains("_menu_hacks")){
|
|
|
|
openMenu("cssHacks");
|
|
|
|
}
|
|
|
|
else if(e.target.classList.contains("_menu_about")){
|
|
|
|
openMenu("about");
|
|
|
|
}
|
2018-03-13 00:36:10 +01:00
|
|
|
else if(e.target.classList.contains("_menu_autoar")){
|
|
|
|
openMenu("autoAr");
|
|
|
|
}
|
2017-12-30 02:58:24 +01:00
|
|
|
|
|
|
|
// don't send commands
|
|
|
|
return;
|
|
|
|
}
|
2018-06-27 23:55:37 +02:00
|
|
|
if(e.target.classList.contains("_ext")) {
|
|
|
|
var command = {};
|
2018-06-28 23:43:52 +02:00
|
|
|
if(e.target.classList.contains("_ext_global_options")){
|
|
|
|
if (e.target.classList.contains("_blacklist")) {
|
2018-08-29 21:23:08 +02:00
|
|
|
settings.active.extensionMode = "blacklist";
|
2018-06-28 23:43:52 +02:00
|
|
|
} else if (e.target.classList.contains("_whitelist")) {
|
2018-08-29 21:23:08 +02:00
|
|
|
settings.active.extensionMode = "whitelist";
|
2018-06-28 23:43:52 +02:00
|
|
|
} else {
|
2018-08-29 21:23:08 +02:00
|
|
|
settings.active.extensionMode = "disabled";
|
2018-06-28 23:43:52 +02:00
|
|
|
}
|
2018-08-29 21:23:08 +02:00
|
|
|
settings.save();
|
|
|
|
return;
|
2018-06-27 23:55:37 +02:00
|
|
|
} else if (e.target.classList.contains("_ext_site_options")) {
|
2018-08-30 00:56:15 +02:00
|
|
|
var mode;
|
2018-06-27 23:55:37 +02:00
|
|
|
if(e.target.classList.contains("_blacklist")){
|
2018-08-30 00:56:15 +02:00
|
|
|
mode = "disabled";
|
2018-06-27 23:55:37 +02:00
|
|
|
} else if(e.target.classList.contains("_whitelist")) {
|
2018-08-30 00:56:15 +02:00
|
|
|
mode = "enabled";
|
2018-06-27 23:55:37 +02:00
|
|
|
} else {
|
2018-08-30 00:56:15 +02:00
|
|
|
mode = "default";
|
2018-06-27 23:55:37 +02:00
|
|
|
}
|
2018-08-30 00:56:15 +02:00
|
|
|
|
|
|
|
if(settings.active.sites[site]) {
|
|
|
|
settings.active.sites[site].status = mode;
|
|
|
|
settings.active.sites[site].statusEmbedded = mode;
|
|
|
|
} else {
|
|
|
|
settings.active.sites[site] = {
|
|
|
|
status: mode,
|
|
|
|
statusEmbedded: mode,
|
|
|
|
arStatus: 'default',
|
|
|
|
type: 'user-defined'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
settings.save();
|
|
|
|
return;
|
2018-06-27 23:55:37 +02:00
|
|
|
}
|
|
|
|
}
|
2017-12-29 23:34:40 +01:00
|
|
|
if(e.target.classList.contains("_changeAr")){
|
|
|
|
if(e.target.classList.contains("_ar_auto")){
|
2018-06-15 00:33:10 +02:00
|
|
|
command.cmd = "autoar-start";
|
2018-05-27 21:41:08 +02:00
|
|
|
command.enabled = true;
|
2017-12-29 23:34:40 +01:00
|
|
|
return command;
|
|
|
|
}
|
|
|
|
if(e.target.classList.contains("_ar_reset")){
|
2018-05-27 01:29:02 +02:00
|
|
|
command.cmd = "set-ar";
|
|
|
|
command.ratio = "reset";
|
2018-02-01 00:26:16 +01:00
|
|
|
return command;
|
|
|
|
}
|
|
|
|
if(e.target.classList.contains("_ar_fitw")){
|
2018-05-27 01:29:02 +02:00
|
|
|
command.cmd = "set-ar";
|
|
|
|
command.ratio = "fitw";
|
2018-02-01 00:26:16 +01:00
|
|
|
return command;
|
|
|
|
}
|
|
|
|
if(e.target.classList.contains("_ar_fitw")){
|
2018-05-27 01:29:02 +02:00
|
|
|
command.cmd = "set-ar";
|
|
|
|
command.ratio = "fith";
|
2017-12-29 23:34:40 +01:00
|
|
|
return command;
|
|
|
|
}
|
|
|
|
if(e.target.classList.contains("_ar_219")){
|
2018-05-27 01:29:02 +02:00
|
|
|
command.cmd = "set-ar";
|
|
|
|
command.ratio = 2.39;
|
2017-12-29 23:34:40 +01:00
|
|
|
return command;
|
|
|
|
}
|
|
|
|
if(e.target.classList.contains("_ar_189")){
|
2018-05-27 01:29:02 +02:00
|
|
|
command.cmd = "set-ar";
|
|
|
|
command.ratio = 2.0;
|
2017-12-29 23:34:40 +01:00
|
|
|
return command;
|
|
|
|
}
|
|
|
|
if(e.target.classList.contains("_ar_169")){
|
2018-05-27 01:29:02 +02:00
|
|
|
command.cmd = "set-ar";
|
|
|
|
command.ratio = 1.78;
|
2017-12-29 23:34:40 +01:00
|
|
|
return command;
|
|
|
|
}
|
|
|
|
if(e.target.classList.contains("_ar_1610")){
|
2018-05-27 01:29:02 +02:00
|
|
|
command.cmd = "set-ar";
|
|
|
|
command.ratio = 1.6;
|
2017-12-29 23:34:40 +01:00
|
|
|
return command;
|
|
|
|
}
|
2018-07-09 23:30:11 +02:00
|
|
|
if(e.target.classList.contains("_ar_custom")){
|
|
|
|
ratio = getCustomAspectRatio();
|
|
|
|
command.cmd = "set-ar";
|
|
|
|
command.ratio = ratio;
|
|
|
|
return ratio !== false ? command : null;
|
|
|
|
}
|
|
|
|
if(e.target.classList.contains("_ar_save_custom_ar")){
|
|
|
|
ratio = getCustomAspectRatio();
|
|
|
|
command.cmd = "set-custom-ar";
|
|
|
|
command.ratio = ratio;
|
|
|
|
return ratio !== false ? command : null; // this validates input
|
|
|
|
}
|
2017-12-29 23:34:40 +01:00
|
|
|
}
|
2018-05-27 21:41:08 +02:00
|
|
|
if(e.target.classList.contains("_stretch")){
|
2018-06-29 00:30:42 +02:00
|
|
|
if (e.target.classList.contains("_ar_stretch_global")) {
|
|
|
|
if (e.target.classList.contains("_none")) {
|
2018-08-29 21:23:08 +02:00
|
|
|
settings.active.stretch.initialMode = 0;
|
2018-06-29 00:30:42 +02:00
|
|
|
} else if (e.target.classList.contains("_basic")) {
|
2018-08-29 21:23:08 +02:00
|
|
|
settings.active.stretch.initialMode = 1;
|
2018-06-29 00:30:42 +02:00
|
|
|
} else if (e.target.classList.contains("_hybrid")) {
|
2018-08-29 21:23:08 +02:00
|
|
|
settings.active.stretch.initialMode = 2;
|
2018-06-29 00:30:42 +02:00
|
|
|
} else if (e.target.classList.contains("_conditional")) {
|
2018-08-29 21:23:08 +02:00
|
|
|
settings.active.stretch.initialMode = 3;
|
2018-06-29 00:30:42 +02:00
|
|
|
}
|
2018-08-29 21:23:08 +02:00
|
|
|
settings.save();
|
|
|
|
return;
|
2018-06-29 00:30:42 +02:00
|
|
|
}
|
|
|
|
|
2018-05-27 21:41:08 +02:00
|
|
|
if(e.target.classList.contains("_ar_stretch_none")) {
|
|
|
|
command.cmd = "set-stretch";
|
|
|
|
command.mode = "NO_STRETCH";
|
|
|
|
} else if(e.target.classList.contains("_ar_stretch_basic")) {
|
|
|
|
command.cmd = "set-stretch";
|
|
|
|
command.mode = "BASIC";
|
|
|
|
} else if(e.target.classList.contains("_ar_stretch_hybrid")) {
|
|
|
|
command.cmd = "set-stretch";
|
|
|
|
command.mode = "HYBRID";
|
|
|
|
} else if(e.target.classList.contains("_ar_stretch_conditional")) {
|
|
|
|
command.cmd = "set-stretch";
|
|
|
|
command.mode = "CONDITIONAL";
|
|
|
|
}
|
|
|
|
return command;
|
|
|
|
}
|
2018-03-13 00:36:10 +01:00
|
|
|
if(e.target.classList.contains("_autoAr")){
|
2018-07-16 20:38:16 +02:00
|
|
|
if(e.target.classList.contains("_ar_global_options")){
|
2018-06-28 23:43:52 +02:00
|
|
|
if (e.target.classList.contains("_blacklist")) {
|
2018-08-29 21:23:08 +02:00
|
|
|
settings.active.arDetect.mode = "blacklist";
|
2018-06-28 23:43:52 +02:00
|
|
|
} else if (e.target.classList.contains("_whitelist")) {
|
2018-08-29 21:23:08 +02:00
|
|
|
settings.active.arDetect.mode = "whitelist";
|
2018-06-28 23:43:52 +02:00
|
|
|
} else {
|
2018-08-29 21:23:08 +02:00
|
|
|
settings.active.arDetect.mode = "disabled";
|
2018-06-28 23:43:52 +02:00
|
|
|
}
|
2018-08-29 21:23:08 +02:00
|
|
|
settings.save();
|
|
|
|
return;
|
2018-08-30 00:56:15 +02:00
|
|
|
} else if (e.target.classList.contains("_save_autoAr_timer")) {
|
|
|
|
var value = parseInt(document.getElementById("_input_autoAr_timer").value.trim());
|
2018-03-13 23:55:38 +01:00
|
|
|
|
2018-03-13 00:36:10 +01:00
|
|
|
if(! isNaN(value)){
|
2018-07-09 23:30:11 +02:00
|
|
|
var timeout = parseInt(value);
|
2018-08-29 21:23:08 +02:00
|
|
|
settings.active.arDetect.timer_playing = timeout;
|
|
|
|
settings.save();
|
2018-03-13 00:36:10 +01:00
|
|
|
}
|
2018-03-13 23:55:38 +01:00
|
|
|
return;
|
2018-06-27 23:55:37 +02:00
|
|
|
} else if (e.target.classList.contains("_ar_site_options")) {
|
2018-08-30 00:56:15 +02:00
|
|
|
var mode;
|
2018-08-03 00:44:37 +02:00
|
|
|
if(e.target.classList.contains("_disabled")){
|
2018-08-30 00:56:15 +02:00
|
|
|
mode = "disabled";
|
2018-08-03 00:44:37 +02:00
|
|
|
} else if(e.target.classList.contains("_enabled")) {
|
2018-08-30 00:56:15 +02:00
|
|
|
mode = "enabled";
|
2018-06-27 23:55:37 +02:00
|
|
|
} else {
|
2018-08-30 00:56:15 +02:00
|
|
|
mode = "default";
|
2018-06-27 23:55:37 +02:00
|
|
|
}
|
2018-08-30 00:56:15 +02:00
|
|
|
|
|
|
|
if(settings.active.sites[site]) {
|
|
|
|
settings.active.sites[site].arStatus = mode;
|
|
|
|
} else {
|
|
|
|
settings.active.sites[site] = {
|
|
|
|
status: settings.active.extensionMode,
|
|
|
|
statusEmbedded: settings.active.extensionMode,
|
|
|
|
arStatus: mode,
|
|
|
|
type: 'user-defined'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
settings.save();
|
|
|
|
return;
|
2017-12-29 23:34:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(e.target.classList.contains("_align")){
|
|
|
|
|
|
|
|
command.global = true;
|
|
|
|
|
2018-08-29 21:23:08 +02:00
|
|
|
if (e.target.classList.contains("_align_left")) {
|
|
|
|
settings.active.miscFullscreenSettings.videoFloat = 'left';
|
|
|
|
} else if (e.target.classList.contains("_align_center")) {
|
|
|
|
settings.active.miscFullscreenSettings.videoFloat = 'center';
|
|
|
|
} else if (e.target.classList.contains("_align_right")) {
|
|
|
|
settings.active.miscFullscreenSettings.videoFloat = 'left';
|
2017-12-29 23:34:40 +01:00
|
|
|
}
|
2018-08-29 21:23:08 +02:00
|
|
|
|
|
|
|
settings.save();
|
|
|
|
return;
|
|
|
|
}
|
2017-12-29 23:34:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var command = getcmd(e);
|
2017-12-30 02:58:24 +01:00
|
|
|
if(command)
|
2018-05-27 01:29:02 +02:00
|
|
|
port.postMessage(command);
|
2018-01-18 00:11:03 +01:00
|
|
|
|
|
|
|
return true;
|
2017-12-29 23:34:40 +01:00
|
|
|
});
|
2017-12-30 02:58:24 +01:00
|
|
|
|
2018-07-09 23:40:26 +02:00
|
|
|
|
2018-07-09 23:30:11 +02:00
|
|
|
|
2018-07-09 23:40:26 +02:00
|
|
|
|
2018-08-30 00:56:15 +02:00
|
|
|
|
|
|
|
|
|
|
|
async function popup_init() {
|
|
|
|
// let's init settings and check if they're loaded
|
|
|
|
await settings.init();
|
|
|
|
|
|
|
|
if (Debug.debug) {
|
|
|
|
console.log("[popup] Are settings loaded?", settings)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const customArInputField = document.getElementById("_input_custom_ar");
|
|
|
|
const autoarFrequencyInputField = document.getElementById("_input_autoAr_timer");
|
|
|
|
|
|
|
|
customArInputField.addEventListener("blur", (event) => {
|
|
|
|
validateCustomAr();
|
|
|
|
});
|
|
|
|
customArInputField.addEventListener("mouseleave", (event) => {
|
|
|
|
validateCustomAr();
|
|
|
|
});
|
|
|
|
|
|
|
|
autoarFrequencyInputField.addEventListener("blur", (event) => {
|
|
|
|
validateAutoArTimeout();
|
|
|
|
});
|
|
|
|
autoarFrequencyInputField.addEventListener("mouseleave", (event) => {
|
|
|
|
validateAutoArTimeout();
|
|
|
|
});
|
|
|
|
|
|
|
|
hideWarning("script-not-running-warning");
|
|
|
|
getSite();
|
|
|
|
}
|
|
|
|
|
|
|
|
popup_init();
|