Fixed up iframe detection. Noticed that 'force aspect ratio' menu doesn't work.

This commit is contained in:
Tamius Han 2017-03-21 21:23:03 +01:00
parent d41f06ccf8
commit 0d943df844
2 changed files with 105 additions and 25 deletions

View File

@ -7,6 +7,7 @@ var debugmsg_message = false;
var debugmsg_autoar = false; var debugmsg_autoar = false;
var debugmsg_periodic = false; var debugmsg_periodic = false;
var debugmsg_ui = true; var debugmsg_ui = true;
var force_conf_reload = true;
if(debugmsg || debugmsg_click || debugmsg_message || debugmsg_autoar){ 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("\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"); 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", name: "movie_player",
isClass: false, isClass: false,
}, },
sampleButtonClass: "ytp-button ytp-settings-button", iframe: {
sampleButtonIndex: 0, name: "player",
isClass: false
},
sampleButton: {
class: "ytp-button ytp-settings-button",
index: 0,
buttonSizeBase: "x",
},
uiParent: { uiParent: {
name: "ytp-right-controls", name: "ytp-right-controls",
isClass: true, isClass: true,
@ -234,6 +242,11 @@ var UW_SITES = {
name: "placeholder", name: "placeholder",
isClass: true, isClass: true,
}, },
sampleButton: {
class: "ytp-button ytp-settings-button",
index: 0,
buttonSizeBase: "x",
},
uiParent: { uiParent: {
name: "placeholder", name: "placeholder",
isClass: true, isClass: true,
@ -252,8 +265,11 @@ var UW_SITES = {
name: "", name: "",
isClass: false, isClass: false,
}, },
sampleButtonClass: "", sampleButton: {
sampleButtonIndex: 0, class: "ytp-button ytp-settings-button",
index: 0,
buttonSizeBase: "x",
},
uiParent: { uiParent: {
name: "", name: "",
isClass: false, isClass: false,
@ -340,11 +356,11 @@ function init(force_reload){
// SAMPLE_BUTTON_CLASS = "ytp-button ytp-settings-button"; // SAMPLE_BUTTON_CLASS = "ytp-button ytp-settings-button";
if(inIframe()) // if(inIframe())
player = document.getElementById("player") // player = document.getElementById("player")
else // else
player = document.getElementById("movie_player"); // player = document.getElementById("movie_player");
//
video_wrap = "video-stream"; video_wrap = "video-stream";
return true; return true;
} }
@ -797,11 +813,29 @@ function uinit(){
// //
// } // }
// else{ // else{
PLAYER = (site.player.isClass ? document.getElementsByClassName(site.player.name)[0] : document.getElementById(site.player.name)); SITE_ENABLED = site.enabled;
SAMPLE_BUTTON_CLASS = site.sampleButtonClass; SITE_TYPE = site.type;
SAMPLE_BUTTON_INDEX = site.sampleButtonIndex; 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) if(debugmsg)
console.log("uw::uinit | initializing elements from the webpage"); console.log("uw::uinit | initializing elements from the webpage");
} }
@ -1010,7 +1044,7 @@ function extsetup_uiban(opt){
UW_UI_BANLIST = obj.ultrawidify_uiban; UW_UI_BANLIST = obj.ultrawidify_uiban;
} }
function extsetup_ui_mode(opt){ function extsetup_ui_mode(opt){
if(opt.ultrawidify_ui === undefined) if(opt.ultrawidify_ui === undefined)
UW_UI_MODE = "all"; UW_UI_MODE = "all";
else else
@ -1804,7 +1838,7 @@ function manual_autoar(){
function changeCSS(type, what_do){ function changeCSS(type, what_do){
if(debugmsg) 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-armenu");
// hideMenu("uw-smenu"); // hideMenu("uw-smenu");
@ -2282,6 +2316,8 @@ function applyCSS(dimensions){
} }
function inIframe(){ function inIframe(){
if(debugmsg)
console.log("uw::inIframe | checking if we're in an iframe");
try { try {
return window.self !== window.top; return window.self !== window.top;
} catch (e) { } catch (e) {

View File

@ -262,9 +262,13 @@ function gotsites(opts){
uw_sites = opts.ultrawidify_siterules; uw_sites = opts.ultrawidify_siterules;
UW_SITES = uw_sites; 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! 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"); var head = document.createElement("div");
head.className = "sites_header"; head.className = "sites_header";
head.textContent = type.charAt(0).toUpperCase() + type.slice(1); head.textContent = type.charAt(0).toUpperCase() + type.slice(1);
@ -288,6 +292,9 @@ function gotsites(opts){
var category_counter = 0; var category_counter = 0;
for (site in uw_sites){ 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){ if(uw_sites[site].type == type){
var entry = document.createElement("div"); var entry = document.createElement("div");
@ -389,6 +396,31 @@ function gotsites(opts){
iframe_playerClass.append(ipc_label); 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 = document.createElement("div");
var imdbar_cb = mkcb(site, uw_sites[site].autoar_imdb, "imdbar"); 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(urlRules);
siteDetails.append(playerElement); siteDetails.append(playerElement);
siteDetails.append(optionspad);
siteDetails.append(iframe_playerName); siteDetails.append(iframe_playerName);
siteDetails.append(iframe_playerClass); siteDetails.append(iframe_playerClass);
siteDetails.append(optionspad);
siteDetails.append(sampleButton);
siteDetails.append(imdbar); siteDetails.append(imdbar);
siteDetails.append(imdbar_title); siteDetails.append(imdbar_title);
siteDetails.append(imdbar_class); siteDetails.append(imdbar_class);
// siteDetails.append(optionspad);
displayedInfo.append(siteTitle); displayedInfo.append(siteTitle);
@ -437,6 +474,13 @@ function gotsites(opts){
list.append(entry); list.append(entry);
category_counter++; 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){ if(! category_counter){
@ -445,10 +489,6 @@ function gotsites(opts){
noEntriesMsg.classList = "red"; noEntriesMsg.classList = "red";
list.append(noEntriesMsg); 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){ function cancelEditing(site){
disableEditing(site); if(site != "dummy"){
hideSiteDetails(site); disableEditing(site);
hideSiteDetails(site);
}
setSiteOpts(site, UW_SITES[site]); setSiteOpts(site, UW_SITES[site]);
} }
function saveEdited(site){ function saveEdited(site){
console.log("uw settings::saveEdited | this is our site:",site,"is this 'dummy'?", site == "dummy");
if(site == "dummy"){ if(site == "dummy"){
var newsite = getSiteOpts(site); var newsite = getSiteOpts(site);
newsite.type = "custom"; newsite.type = "custom";
@ -545,8 +589,8 @@ function saveEdited(site){
} }
else{ else{
UW_SITES[site] = getSiteOpts(site); UW_SITES[site] = getSiteOpts(site);
disableEditing(site); // disableEditing(site);
hideSiteDetails(site); // hideSiteDetails(site);
} }
setopt({ultrawidify_siterules: UW_SITES}); setopt({ultrawidify_siterules: UW_SITES});