From 0d943df844acd0d2e1eee8c88a2524dd2565e867 Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Tue, 21 Mar 2017 21:23:03 +0100 Subject: [PATCH] Fixed up iframe detection. Noticed that 'force aspect ratio' menu doesn't work. --- js/uw.js | 66 ++++++++++++++++++++++++++++++++++++++----------- res/settings.js | 64 +++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 105 insertions(+), 25 deletions(-) diff --git a/js/uw.js b/js/uw.js index 181627f..0e77c04 100644 --- a/js/uw.js +++ b/js/uw.js @@ -7,6 +7,7 @@ var debugmsg_message = false; var debugmsg_autoar = false; var debugmsg_periodic = false; var debugmsg_ui = true; +var force_conf_reload = true; if(debugmsg || debugmsg_click || debugmsg_message || debugmsg_autoar){ console.log("\n\n\n\n\n\n\n\n\n\n\n\n\n\n. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . "); console.log("\nLoading ultrawidify (uw)\nIf you can see this, extension at least tried to load\n\nRandom number: ",Math.floor(Math.random() * 20) + 1,"\n"); @@ -215,8 +216,15 @@ var UW_SITES = { name: "movie_player", isClass: false, }, - sampleButtonClass: "ytp-button ytp-settings-button", - sampleButtonIndex: 0, + iframe: { + name: "player", + isClass: false + }, + sampleButton: { + class: "ytp-button ytp-settings-button", + index: 0, + buttonSizeBase: "x", + }, uiParent: { name: "ytp-right-controls", isClass: true, @@ -234,6 +242,11 @@ var UW_SITES = { name: "placeholder", isClass: true, }, + sampleButton: { + class: "ytp-button ytp-settings-button", + index: 0, + buttonSizeBase: "x", + }, uiParent: { name: "placeholder", isClass: true, @@ -252,8 +265,11 @@ var UW_SITES = { name: "", isClass: false, }, - sampleButtonClass: "", - sampleButtonIndex: 0, + sampleButton: { + class: "ytp-button ytp-settings-button", + index: 0, + buttonSizeBase: "x", + }, uiParent: { name: "", isClass: false, @@ -340,11 +356,11 @@ function init(force_reload){ // SAMPLE_BUTTON_CLASS = "ytp-button ytp-settings-button"; - if(inIframe()) - player = document.getElementById("player") - else - player = document.getElementById("movie_player"); - +// if(inIframe()) +// player = document.getElementById("player") +// else +// player = document.getElementById("movie_player"); +// video_wrap = "video-stream"; return true; } @@ -797,11 +813,29 @@ function uinit(){ // // } // else{ - PLAYER = (site.player.isClass ? document.getElementsByClassName(site.player.name)[0] : document.getElementById(site.player.name)); - SAMPLE_BUTTON_CLASS = site.sampleButtonClass; - SAMPLE_BUTTON_INDEX = site.sampleButtonIndex; + SITE_ENABLED = site.enabled; + SITE_TYPE = site.type; + SITE_URL_RULES = site.urlRules; + + + if(debugmsg) + console.log("uw::uinit | are we in iframe?", inIframe(), "does the site have a separate config for iframe?", site.iframe ? true : false ); + + if(inIframe() && site.iframe){ + console.log("uw::uinit | we're in iframe."); + PLAYER = site.iframe.isClass ? document.getElementsByClassName(site.iframe.name)[0] : document.getElementById(site.iframe.name); + } + else{ + PLAYER = site.player.isClass ? document.getElementsByClassName(site.player.name)[0] : document.getElementById(site.player.name); + } + + SAMPLE_BUTTON_CLASS = site.sampleButton.class; + SAMPLE_BUTTON_INDEX = site.sampleButton.index; + BUTTON_SIZE_BASE = site.sampleButton.buttonSizeBase; // } - + + IMDB_AUTOAR_ALLOWED = site.autoar_imdb.enabled; + if(debugmsg) console.log("uw::uinit | initializing elements from the webpage"); } @@ -1010,7 +1044,7 @@ function extsetup_uiban(opt){ UW_UI_BANLIST = obj.ultrawidify_uiban; } -function extsetup_ui_mode(opt){ +function extsetup_ui_mode(opt){ if(opt.ultrawidify_ui === undefined) UW_UI_MODE = "all"; else @@ -1804,7 +1838,7 @@ function manual_autoar(){ function changeCSS(type, what_do){ if(debugmsg) - console.log("uw::changeCSS | starting function. type:", type, "; what_do:",what_do); + console.log("uw::changeCSS | starting function. type:", type, "; what_do:",what_do,"\nPlayer element is this:",PLAYER); // hideMenu("uw-armenu"); // hideMenu("uw-smenu"); @@ -2282,6 +2316,8 @@ function applyCSS(dimensions){ } function inIframe(){ + if(debugmsg) + console.log("uw::inIframe | checking if we're in an iframe"); try { return window.self !== window.top; } catch (e) { diff --git a/res/settings.js b/res/settings.js index c02625d..481740b 100644 --- a/res/settings.js +++ b/res/settings.js @@ -262,9 +262,13 @@ function gotsites(opts){ uw_sites = opts.ultrawidify_siterules; UW_SITES = uw_sites; - console.log("opts",opts); + if(debugmsg) + console.log("uw settings::gotopts | site opts:",opts); for (type in {"official":1,"non-official":1,"custom":1, "add new site":1} ) { // unparalleled laziness! + if(debugmsg){ + console.log("uw settings::gotopts | adding sites of type" , type); + } var head = document.createElement("div"); head.className = "sites_header"; head.textContent = type.charAt(0).toUpperCase() + type.slice(1); @@ -288,6 +292,9 @@ function gotsites(opts){ var category_counter = 0; for (site in uw_sites){ + if(debugmsg) + console.log("we're at site %s of type %s. We're %s this site.",site, uw_sites[site].type, uw_sites[site].type == type ? "processing" : "ignoring"); + if(uw_sites[site].type == type){ var entry = document.createElement("div"); @@ -389,6 +396,31 @@ function gotsites(opts){ iframe_playerClass.append(ipc_label); + var sampleButton = document.createElement("div"); + var sbc = document.createElement("div"); + var sbi = document.createElement("div"); + var sbo = document.createElement("div"); + var sbc_label = document.createElement("span"); + var sbi_label = document.createElement("span"); + var sbo_label = document.createElement("span"); + sbc_label.textContent = "Sample button class:"; + sbi_label.textContent = "Sample button index:"; + sbo_label.textContent = "Use height for UI scaling"; + var sampleButtonClass = mkebox(site, uw_sites[site].sampleButton.class, "sample_button_class"); + var sampleButtonIndex = mkebox(site, uw_sites[site].sampleButton.Index, "sample_button_index"); + var buttonSizeBase = mkcb(site, uw_sites[site].sampleButton.buttonSizeBase == "y", "sample_button_size_base"); + + sbc.append(sbc_label); + sbc.append(sampleButtonClass); + sampleButton.append(sbc); + + sbi.append(sbi_label); + sbi.append(sampleButtonIndex); + sampleButton.append(sbi); + + sbo.append(buttonSizeBase); + sbo.append(sbo_label); + sampleButton.append(sbo); var imdbar = document.createElement("div"); var imdbar_cb = mkcb(site, uw_sites[site].autoar_imdb, "imdbar"); @@ -415,18 +447,23 @@ function gotsites(opts){ + var optionspad = document.createElement("div"); + optionspad.textContent = "-------------"; siteDetails.append(urlRules); siteDetails.append(playerElement); + siteDetails.append(optionspad); siteDetails.append(iframe_playerName); siteDetails.append(iframe_playerClass); + siteDetails.append(optionspad); - + siteDetails.append(sampleButton); siteDetails.append(imdbar); siteDetails.append(imdbar_title); siteDetails.append(imdbar_class); +// siteDetails.append(optionspad); displayedInfo.append(siteTitle); @@ -437,6 +474,13 @@ function gotsites(opts){ list.append(entry); category_counter++; + + if(site == "dummy" && type == "add new site"){ + if(debugmsg) + console.log("uw settings::gotsites | we are adding dummy site"); + enableEditing("dummy"); + document.getElementById("dummy_title_ebox").disabled = false; + } } } if(! category_counter){ @@ -445,10 +489,6 @@ function gotsites(opts){ noEntriesMsg.classList = "red"; list.append(noEntriesMsg); } - if(site == "dummy" && type == "add new site"){ - enableEditing("dummy"); - document.getElementById("dummy_title_ebox").disabled = false; - } } } @@ -530,13 +570,17 @@ function disableEditing(site){ } function cancelEditing(site){ - disableEditing(site); - hideSiteDetails(site); + if(site != "dummy"){ + disableEditing(site); + hideSiteDetails(site); + } setSiteOpts(site, UW_SITES[site]); } function saveEdited(site){ + console.log("uw settings::saveEdited | this is our site:",site,"is this 'dummy'?", site == "dummy"); + if(site == "dummy"){ var newsite = getSiteOpts(site); newsite.type = "custom"; @@ -545,8 +589,8 @@ function saveEdited(site){ } else{ UW_SITES[site] = getSiteOpts(site); - disableEditing(site); - hideSiteDetails(site); +// disableEditing(site); +// hideSiteDetails(site); } setopt({ultrawidify_siterules: UW_SITES});