Fixed basic stretching

This commit is contained in:
Tamius Han 2018-06-15 00:33:10 +02:00
parent 3e787be684
commit c5debb40a7
7 changed files with 472 additions and 373 deletions

View File

@ -29,7 +29,7 @@ class CommsClient {
ExtensionConf = message.conf;
} else if (message.cmd === "set-stretch") {
this.pageInfo.setStretchMode(StretchMode[message.mode]);
} else if (message.cmd === "autoar-enable") {
} else if (message.cmd === "autoar-start") {
if (message.enabled !== false) {
this.pageInfo.initArDetection();
this.pageInfo.startArDetection();
@ -41,6 +41,9 @@ class CommsClient {
} else if (message.cmd === "resume-processing") {
// todo: autoArStatus
this.pageInfo.resumeProcessing(message.autoArStatus);
} else if (message.cmd === "reload-settings") {
ExtensionConf = message.newConf;
this.pageInfo.reset();
}
}
@ -214,15 +217,40 @@ class CommsServer {
if (message.cmd === 'get-config') {
port.postMessage({cmd: "set-config", conf: ExtensionConf})
}
if (message.cmd === 'set-stretch') {
} else if (message.cmd === 'set-stretch') {
this.sendToActive(message);
}
if (message.cmd === 'set-ar') {
} else if (message.cmd === 'set-ar') {
this.sendToActive(message);
}
if (message.cmd === 'autoar-enable') {
} else if (message.cmd === 'autoar-start') {
this.sendToActive(message);
} else if (message.cmd === "autoar-enable") {
ExtensionConf.arDetect.mode = "blacklist";
Settings.save(ExtensionConf);
this.sendToAll({cmd: "reload-settings", sender: "uwbg"})
if(Debug.debug){
console.log("[uw-bg] autoar set to enabled (blacklist). evidenz:", ExtensionConf);
}
} else if (message.cmd === "autoar-disable") {
ExtensionConf.arDetect.mode = "disabled";
if(message.reason){
ExtensionConf.arDetect.disabledReason = message.reason;
} else {
ExtensionConf.arDetect.disabledReason = 'User disabled';
}
Settings.save(ExtensionConf);
this.sendToAll({cmd: 'reload-settings', newConf: ExtensionConf});
if(Debug.debug){
console.log("[uw-bg] autoar set to disabled. evidenz:", ExtensionConf);
}
} else if (message.cmd === "autoar-set-interval") {
if(Debug.debug)
console.log("[uw-bg] trying to set new interval for autoAr. New interval is",message.timeout,"ms");
// set fairly liberal limit
var timeout = message.timeout < 4 ? 4 : message.timeout;
ExtensionConf.arDetect.timer_playing = timeout;
Settings.save(ExtensionConf);
this.sendToAll({cmd: 'reload-settings', newConf: ExtensionConf});
}
}
@ -237,9 +265,34 @@ class CommsServer {
console.log("%c[CommsServer.js::processMessage_nonpersistent_ff] Returning this:", "background-color: #11D; color: #aad", ret);
}
Promise.resolve(ret);
}
if (message.cmd === "enable-autoar"){
this.sendToActive({cmd: "autoar-enable", enabled: true})
} else if (message.cmd === "autoar-enable") {
ExtensionConf.arDetect.mode = "blacklist";
Settings.save(ExtensionConf);
this.sendToAll({cmd: "reload-settings", sender: "uwbg"})
if(Debug.debug){
console.log("[uw-bg] autoar set to enabled (blacklist). evidenz:", ExtensionConf);
}
} else if (message.cmd === "autoar-disable") {
ExtensionConf.arDetect.mode = "disabled";
if(message.reason){
ExtensionConf.arDetect.disabledReason = message.reason;
} else {
ExtensionConf.arDetect.disabledReason = 'User disabled';
}
Settings.save(ExtensionConf);
this.sendToAll({cmd: 'reload-settings', newConf: ExtensionConf});
if(Debug.debug){
console.log("[uw-bg] autoar set to disabled. evidenz:", ExtensionConf);
}
} else if (message.cmd === "autoar-set-interval") {
if(Debug.debug)
console.log("[uw-bg] trying to set new interval for autoAr. New interval is",message.timeout,"ms");
// set fairly liberal limit
var timeout = message.timeout < 4 ? 4 : message.timeout;
ExtensionConf.arDetect.timer_playing = timeout;
Settings.save(ExtensionConf);
this.sendToAll({cmd: 'reload-settings', newConf: ExtensionConf});
}
}
@ -251,6 +304,34 @@ class CommsServer {
if(message.cmd === 'get-config') {
sendResponse({extensionConf: JSON.stringify(ExtensionConf)});
// return true;
} else if (message.cmd === "autoar-enable") {
ExtensionConf.arDetect.mode = "blacklist";
Settings.save(ExtensionConf);
this.sendToAll({cmd: "reload-settings", sender: "uwbg"})
if(Debug.debug){
console.log("[uw-bg] autoar set to enabled (blacklist). evidenz:", ExtensionConf);
}
} else if (message.cmd === "autoar-disable") {
ExtensionConf.arDetect.mode = "disabled";
if(message.reason){
ExtensionConf.arDetect.disabledReason = message.reason;
} else {
ExtensionConf.arDetect.disabledReason = 'User disabled';
}
Settings.save(ExtensionConf);
this.sendToAll({cmd: 'reload-settings', newConf: ExtensionConf});
if(Debug.debug){
console.log("[uw-bg] autoar set to disabled. evidenz:", ExtensionConf);
}
} else if (message.cmd === "autoar-set-interval") {
if(Debug.debug)
console.log("[uw-bg] trying to set new interval for autoAr. New interval is",message.timeout,"ms");
// set fairly liberal limit
var timeout = message.timeout < 4 ? 4 : message.timeout;
ExtensionConf.arDetect.timer_playing = timeout;
Settings.save(ExtensionConf);
this.sendToAll({cmd: 'reload-settings', newConf: ExtensionConf});
}
}
}
@ -284,167 +365,167 @@ class Comms {
}
var _com_queryTabs = async function(tabInfo){
if(BrowserDetect.usebrowser != "firefox"){
return await _com_chrome_tabquery_wrapper(tabInfo);
}
else{
return browser.tabs.query(tabInfo);
}
}
var _com_getActiveTab = async function(tabInfo){
if(BrowserDetect.firefox){
return await browser.tabs.query({currentWindow: true, active: true});
}
return _com_chrome_tabquery_wrapper({currentWindow: true, active: true});
}
var _com_chrome_tabs_sendmsg_wrapper = async function(tab, message, options){
return new Promise(function (resolve, reject){
try{
browser.tabs.sendMessage(tab, message, /*options, */function(response){
console.log("TESTING what is this owo? (response)", response);
// Chrome/js shittiness mitigation — remove this line and an empty array will be returned
var r = response;
resolve(r);
});
}
catch(e){
reject(e);
}
});
}
var _com_sendMessage = async function(tab, message, options){
if(BrowserDetect.usebrowser != "firefox"){
var r = await _com_chrome_tabs_sendmsg_wrapper(tab, message, options);
console.log("TESTING what is this owo? (should be a promise)", r);
return r;
}
else{
return browser.tabs.sendMessage(tab, message, options);
}
}
var _com_chrome_tabs_sendmsgrt_wrapper = async function(message){
return new Promise(function (resolve, reject){
try{
browser.runtime.sendMessage(message, function(response){
// Chrome/js shittiness mitigation — remove this line and an empty array will be returned
var r = response;
resolve(r);
});
}
catch(e){
reject(e);
}
});
}
var _com_sendMessageRuntime = async function(message){
if(BrowserDetect.usebrowser != "firefox"){
return _com_chrome_tabs_sendmsgrt_wrapper(message);
}
else{
return browser.runtime.sendMessage(message);
}
}
// pošlje sporočilce vsem okvirjem v trenutno odprtem zavihku. Vrne tisti odgovor od tistega okvira, ki prispe prvi.
// sends a message to all frames in the currently opened tab. Returns the response of a frame that replied first
var _com_sendToAllFrames = async function(message) {
if(Debug.debug)
console.log("[Comms::_com_sendToAllFrames] sending message to all frames of currenntly active tab");
var tabs = await browser.tabs.query({currentWindow: true, active: true});
if(Debug.debug)
console.log("[Comms::_com_sendToAllFrames] trying to send message", message, " to tab ", tabs[0], ". (all tabs:", tabs,")");
var response = await browser.tabs.sendMessage(tabs[0].id, message);
console.log("[Comms::_com_sendToAllFrames] response is this:",response);
return response;
// if(BrowserDetect.firefox){
// return
// var _com_queryTabs = async function(tabInfo){
// if(BrowserDetect.usebrowser != "firefox"){
// return await _com_chrome_tabquery_wrapper(tabInfo);
// }
}
// else{
// return browser.tabs.query(tabInfo);
// }
// }
// pošlje sporočilce vsem okvirjem v trenutno odprtem zavihku in vrne _vse_ odgovore
// sends a message to all frames in currently opened tab and returns all responses
var _com_sendToEachFrame = async function(message, tabId) {
if(Debug.debug)
console.log("[Comms::_com_sendToEveryFrame] sending message to every frames of currenntly active tab");
if(tabId === undefined){
var tabs = await browser.tabs.query({currentWindow: true, active: true});
tabId = tabs[0].id;
}
var frames = await browser.webNavigation.getAllFrames({tabId: tabId});
if(Debug.debug)
console.log("[Comms::_com_sendToEveryFrame] we have this many frames:", frames.length, "||| tabId:", tabId ,"frames:",frames);
// pošlji sporočilce vsakemu okvirju, potisni obljubo v tabelo
// send message to every frame, push promise to array
var promises = [];
for(var frame of frames){
if(Debug.debug)
console.log("[Comms:_com_sendToEachFrame] we sending message to tab with id", tabId, ", frame with id", frame.frameId);
try{
promises.push(browser.tabs.sendMessage(tabId, message, {frameId: frame.frameId}));
}
catch(e){
if(Debug.debug)
console.log("[Comms:_com_sendToEachFrame] we sending message to tab with id", tabId, ", frame with id", frame.frameId);
}
}
// počakajmo, da so obljube izpolnjene.
// wait for all promises to be kept
var responses = [];
for(var promise of promises){
var response = await promise;
if(response !== undefined)
responses.push(response);
}
if(Debug.debug)
console.log("[Comms::_com_sendToEveryFrame] we received responses from all frames", responses);
return responses;
}
// var _com_getActiveTab = async function(tabInfo){
// if(BrowserDetect.firefox){
// return await browser.tabs.query({currentWindow: true, active: true});
// }
// return _com_chrome_tabquery_wrapper({currentWindow: true, active: true});
// }
var _com_sendToMainFrame = async function(message, tabId){
if(Debug.debug)
console.log("[Comms::_com_sendToMainFrame] sending message to every frames of currenntly active tab");
// var _com_chrome_tabs_sendmsg_wrapper = async function(tab, message, options){
// return new Promise(function (resolve, reject){
// try{
// browser.tabs.sendMessage(tab, message, /*options, */function(response){
// console.log("TESTING what is this owo? (response)", response);
// // Chrome/js shittiness mitigation — remove this line and an empty array will be returned
// var r = response;
// resolve(r);
// });
// }
// catch(e){
// reject(e);
// }
// });
// }
// var _com_sendMessage = async function(tab, message, options){
// if(BrowserDetect.usebrowser != "firefox"){
// var r = await _com_chrome_tabs_sendmsg_wrapper(tab, message, options);
// console.log("TESTING what is this owo? (should be a promise)", r);
// return r;
// }
// else{
// return browser.tabs.sendMessage(tab, message, options);
// }
// }
// var _com_chrome_tabs_sendmsgrt_wrapper = async function(message){
// return new Promise(function (resolve, reject){
// try{
// browser.runtime.sendMessage(message, function(response){
// // Chrome/js shittiness mitigation — remove this line and an empty array will be returned
// var r = response;
// resolve(r);
// });
// }
// catch(e){
// reject(e);
// }
// });
// }
// var _com_sendMessageRuntime = async function(message){
// if(BrowserDetect.usebrowser != "firefox"){
// return _com_chrome_tabs_sendmsgrt_wrapper(message);
// }
// else{
// return browser.runtime.sendMessage(message);
// }
// }
// // pošlje sporočilce vsem okvirjem v trenutno odprtem zavihku. Vrne tisti odgovor od tistega okvira, ki prispe prvi.
// // sends a message to all frames in the currently opened tab. Returns the response of a frame that replied first
// var _com_sendToAllFrames = async function(message) {
// if(Debug.debug)
// console.log("[Comms::_com_sendToAllFrames] sending message to all frames of currenntly active tab");
if(tabId === undefined){
var tabs = await browser.tabs.query({currentWindow: true, active: true});
tabId = tabs[0].id;
}
// var tabs = await browser.tabs.query({currentWindow: true, active: true});
// pošlji sporočilce glavnemu okvirju. Glavni okvir ima id=0
// send message to the main frame. Main frame has id=0
try{
var response = await browser.tabs.sendMessage(tabId, message, {frameId: 0});
console.log("[Comms::_com_sendToMainFrame] response is this:",response);
// if(Debug.debug)
// console.log("[Comms::_com_sendToAllFrames] trying to send message", message, " to tab ", tabs[0], ". (all tabs:", tabs,")");
// var response = await browser.tabs.sendMessage(tabs[0].id, message);
// console.log("[Comms::_com_sendToAllFrames] response is this:",response);
// return response;
// // if(BrowserDetect.firefox){
// // return
// // }
// }
// // pošlje sporočilce vsem okvirjem v trenutno odprtem zavihku in vrne _vse_ odgovore
// // sends a message to all frames in currently opened tab and returns all responses
// var _com_sendToEachFrame = async function(message, tabId) {
// if(Debug.debug)
// console.log("[Comms::_com_sendToEveryFrame] sending message to every frames of currenntly active tab");
// if(tabId === undefined){
// var tabs = await browser.tabs.query({currentWindow: true, active: true});
// tabId = tabs[0].id;
// }
// var frames = await browser.webNavigation.getAllFrames({tabId: tabId});
// if(Debug.debug)
// console.log("[Comms::_com_sendToEveryFrame] we have this many frames:", frames.length, "||| tabId:", tabId ,"frames:",frames);
// // pošlji sporočilce vsakemu okvirju, potisni obljubo v tabelo
// // send message to every frame, push promise to array
// var promises = [];
// for(var frame of frames){
// if(Debug.debug)
// console.log("[Comms:_com_sendToEachFrame] we sending message to tab with id", tabId, ", frame with id", frame.frameId);
// try{
// promises.push(browser.tabs.sendMessage(tabId, message, {frameId: frame.frameId}));
// }
// catch(e){
// if(Debug.debug)
// console.log("[Comms:_com_sendToEachFrame] we sending message to tab with id", tabId, ", frame with id", frame.frameId);
// }
// }
// // počakajmo, da so obljube izpolnjene.
// // wait for all promises to be kept
// var responses = [];
// for(var promise of promises){
// var response = await promise;
// if(response !== undefined)
// responses.push(response);
// }
// if(Debug.debug)
// console.log("[Comms::_com_sendToEveryFrame] we received responses from all frames", responses);
// return responses;
// }
// var _com_sendToMainFrame = async function(message, tabId){
// if(Debug.debug)
// console.log("[Comms::_com_sendToMainFrame] sending message to every frames of currenntly active tab");
// if(tabId === undefined){
// var tabs = await browser.tabs.query({currentWindow: true, active: true});
// tabId = tabs[0].id;
// }
// // pošlji sporočilce glavnemu okvirju. Glavni okvir ima id=0
// // send message to the main frame. Main frame has id=0
// try{
// var response = await browser.tabs.sendMessage(tabId, message, {frameId: 0});
// console.log("[Comms::_com_sendToMainFrame] response is this:",response);
}
catch(e){
console.log("[Comms:_com_sendToEachFrame] failed sending message to tab with id", tabId, ", frame with id", 0, "\nerror:",e);
}
return response;
}
// }
// catch(e){
// console.log("[Comms:_com_sendToEachFrame] failed sending message to tab with id", tabId, ", frame with id", 0, "\nerror:",e);
// }
// return response;
// }
// var Comms = {
// getActiveTab: _com_getActiveTab,

View File

@ -11,7 +11,6 @@ class VideoData {
this.resizer = new Resizer(this);
this.arDetector = new ArDetector(this); // this starts Ar detection. needs optional parameter that prevets ardetdctor from starting
// player dimensions need to be in:
// this.player.dimensions
}

View File

@ -22,6 +22,14 @@ class PageInfo {
}
}
reset(){
for(video of this.videos) {
video.destroy();
}
this.rescan(RescanReason.MANUAL);
}
rescan(rescanReason){
try{
var vids = document.getElementsByTagName('video');

View File

@ -84,6 +84,9 @@ class Resizer {
}
} else if (this.stretcher.mode === StretchMode.HYBRID) {
var stretchFactors = this.stretcher.calculateStretch(ar);
} else if (this.stretcher.mode === StretchMode.BASIC) {
console.log("basic stretch mode")
var stretchFactors = this.stretcher.calculateBasicStretch();
}
this.zoom.applyZoom(stretchFactors);
@ -92,6 +95,8 @@ class Resizer {
var translate = this.computeOffsets(stretchFactors);
this.applyCss(stretchFactors, translate);
console.log("applied css")
// if(! this.destroyed)
// this.startCssWatcher();
}
@ -105,6 +110,7 @@ class Resizer {
}
setStretchMode(stretchMode){
console.log("setting stretch mode:", stretchMode)
this.stretcher.mode = stretchMode;
this.restore();
}
@ -130,13 +136,13 @@ class Resizer {
}
}
stopCssWatcher(){
stopCssWatcher() {
if(Debug.debug) console.log("[Resizer.js] STOPPING CSS WATCHER!")
clearInterval(this.cssWatcherTimeout);
}
restore(){
restore() {
if(Debug.debug){
console.log("[Resizer::restore] attempting to restore aspect ratio. this & settings:", {'this': this, "settings": Settings} );
}

View File

@ -50,6 +50,18 @@ class Stretcher {
}
}
calculateBasicStretch() {
console.log("calculating basic stretch - -- stretcher")
// var videoAr = this.conf.video.videoWidth / this.conf.video.videoHeight;
// var playerAr = this.conf.player.dimensions.width / this.conf.player.dimensions.height;
return {
xFactor: this.conf.player.dimensions.width / this.conf.video.videoWidth,
yFactor: this.conf.player.dimensions.height / this.conf.video.videoHeight
};
// return this.calculateStretch(actualAr);
}
calculateStretch(actualAr) {
var playerAr = this.conf.player.dimensions.width / this.conf.player.dimensions.height;
var videoAr = this.conf.video.videoWidth / this.conf.video.videoHeight;
@ -93,7 +105,7 @@ class Stretcher {
} else {
// NEEDS CHECKING
// player > video > actual — double pillarbox
stretchFactors.xFactor = actualAr / playerAr;
stretchFactors.xFactor = playerAr / actualAr;
stretchFactors.yFactor = 1;
if(Debug.debug){

View File

@ -19,258 +19,258 @@ class UWServer {
var server = new UWServer();
function extractHostname(url){
// extract hostname
if (url.indexOf("://") > -1) { //find & remove protocol (http, ftp, etc.) and get hostname
hostname = url.split('/')[2];
}
else {
hostname = url.split('/')[0];
}
// function extractHostname(url){
// // extract hostname
// if (url.indexOf("://") > -1) { //find & remove protocol (http, ftp, etc.) and get hostname
// hostname = url.split('/')[2];
// }
// else {
// hostname = url.split('/')[0];
// }
hostname = hostname.split(':')[0]; //find & remove port number
hostname = hostname.split('?')[0]; //find & remove "?"
// hostname = hostname.split(':')[0]; //find & remove port number
// hostname = hostname.split('?')[0]; //find & remove "?"
return hostname;
}
// return hostname;
// }
async function main(){
if(Debug.debug)
console.log("[uw-bg::main] setting up background script");
// async function main(){
// if(Debug.debug)
// console.log("[uw-bg::main] setting up background script");
Keybinds.keybinds = await Keybinds.fetch();
// Keybinds.keybinds = await Keybinds.fetch();
// Poslušalci za dogodke | event listeners here
// {===]///[-------------------------------------]\\\[===}
// // Poslušalci za dogodke | event listeners here
// // {===]///[-------------------------------------]\\\[===}
browser.runtime.onMessage.addListener(_uwbg_rcvmsg);
browser.tabs.onActivated.addListener(_uwbg_onTabSwitched);
// browser.runtime.onMessage.addListener(_uwbg_rcvmsg);
// browser.tabs.onActivated.addListener(_uwbg_onTabSwitched);
if(Debug.debug)
console.log("[uw-bg::main] listeners registered");
// if(Debug.debug)
// console.log("[uw-bg::main] listeners registered");
// add currentSite
var tabs = await Comms.getActiveTab();
BgVars.currentSite = extractHostname(tabs[0].url);
// // add currentSite
// var tabs = await Comms.getActiveTab();
// BgVars.currentSite = extractHostname(tabs[0].url);
//
setInterval(_uwbg_check4videos, 5000);
}
// //
// setInterval(_uwbg_check4videos, 5000);
// }
async function _uwbg_onTabSwitched(activeInfo){
BgVars.hasVideos = false;
if(Debug.debug)
console.log("[uw-bg::onTabSwitched] TAB CHANGED, GETTING INFO FROM MAIN TAB");
// async function _uwbg_onTabSwitched(activeInfo){
// BgVars.hasVideos = false;
// if(Debug.debug)
// console.log("[uw-bg::onTabSwitched] TAB CHANGED, GETTING INFO FROM MAIN TAB");
var tabId = activeInfo.tabId; // just for readability
// var tabId = activeInfo.tabId; // just for readability
var tab = await browser.tabs.get(tabId);
// var tab = await browser.tabs.get(tabId);
BgVars.currentSite = extractHostname(tab.url);
// BgVars.currentSite = extractHostname(tab.url);
// this can fail. This might also not return a promise? Check that.
var videoFrameList = await Comms.sendToEach({"cmd":"has-videos"}, tabId);
// // this can fail. This might also not return a promise? Check that.
// var videoFrameList = await Comms.sendToEach({"cmd":"has-videos"}, tabId);
if(Debug.debug)
console.log("[uw-bg::onTabSwitched] got list of frames and whether they have videos", videoFrameList);
// if(Debug.debug)
// console.log("[uw-bg::onTabSwitched] got list of frames and whether they have videos", videoFrameList);
// Pogledamo, če kateri od okvirjev vsebuje video. Da omogočimo pojavno okno je zadosti že
// en okvir z videom.
// <===[///]----------------------------[\\\]===>
// Check if any frame has a video in it. To enable the popup there only needs to be at least one,
// but the popup controls all frames.
// // Pogledamo, če kateri od okvirjev vsebuje video. Da omogočimo pojavno okno je zadosti že
// // en okvir z videom.
// // <===[///]----------------------------[\\\]===>
// // Check if any frame has a video in it. To enable the popup there only needs to be at least one,
// // but the popup controls all frames.
var hasVideos = false;
for(frame of videoFrameList){
hasVideos |= frame.response.hasVideos;
}
// var hasVideos = false;
// for(frame of videoFrameList){
// hasVideos |= frame.response.hasVideos;
// }
BgVars.hasVideos = hasVideos;
// BgVars.hasVideos = hasVideos;
Settings.reload();
// todo: change extension icon depending on whether there's a video on the page or not
}
// Settings.reload();
// // todo: change extension icon depending on whether there's a video on the page or not
// }
async function _uwbg_check4videos(){
if(BgVars.hasVideos)
return;
// async function _uwbg_check4videos(){
// if(BgVars.hasVideos)
// return;
var videoFrameList = Comms.sendToEach({"cmd":"has-videos"});
// var videoFrameList = Comms.sendToEach({"cmd":"has-videos"});
if(Debug.debug)
console.log("[uw-bg::check4videos] got updated list of frames and whether they have videos", videoFrameList);
// if(Debug.debug)
// console.log("[uw-bg::check4videos] got updated list of frames and whether they have videos", videoFrameList);
var hasVideos = false;
for(frame of videoFrameList){
hasVideos |= frame.response.hasVideos;
}
// var hasVideos = false;
// for(frame of videoFrameList){
// hasVideos |= frame.response.hasVideos;
// }
BgVars.hasVideos = hasVideos;
}
// BgVars.hasVideos = hasVideos;
// }
async function _uwbg_registerVideo(tabId){
var tabs = await Comms.getActiveTab();
// async function _uwbg_registerVideo(tabId){
// var tabs = await Comms.getActiveTab();
// če ukaz pride iz zavihka, na katerem se trenunto ne nahajamo, potem se za zahtevo ne brigamo
// if command originated from a tab that's _not_ currently active, we ignore the request
if(tabId != tabs[0].id){
if(Debug.debug){
console.log("[uw-bg::_uwbg_registerVideo] request didn't come from currently active tab, ignoring");
}
return;
}
if(Debug.debug){
console.log("%c[uw-bg::_uwbg_registerVideo] request came from currently active tab!", "color: #afd, background: #000");
}
BgVars.hasVideos = true;
// // če ukaz pride iz zavihka, na katerem se trenunto ne nahajamo, potem se za zahtevo ne brigamo
// // if command originated from a tab that's _not_ currently active, we ignore the request
// if(tabId != tabs[0].id){
// if(Debug.debug){
// console.log("[uw-bg::_uwbg_registerVideo] request didn't come from currently active tab, ignoring");
// }
// return;
// }
// if(Debug.debug){
// console.log("%c[uw-bg::_uwbg_registerVideo] request came from currently active tab!", "color: #afd, background: #000");
// }
// BgVars.hasVideos = true;
// todo: change extension icon depending on whether there's a video on the page or not
}
// // todo: change extension icon depending on whether there's a video on the page or not
// }
function _uwbg_rcvmsg(message, sender, sendResponse){
if(Debug.debug){
console.log("[uw-bg::_uwbg_rcvmsg] received message", message, "from sender", sender);
}
// function _uwbg_rcvmsg(message, sender, sendResponse){
// if(Debug.debug){
// console.log("[uw-bg::_uwbg_rcvmsg] received message", message, "from sender", sender);
// }
message.sender = "uwbg";
message.receiver = "uw";
// message.sender = "uwbg";
// message.receiver = "uw";
if(message.cmd == "has-videos"){
if(Debug.debug){
console.log("[uw-bg::_uwbg_rcvmsg] does this tab or any of its subframes have videos?", BgVars.hasVideos );
}
// if(message.cmd == "has-videos"){
// if(Debug.debug){
// console.log("[uw-bg::_uwbg_rcvmsg] does this tab or any of its subframes have videos?", BgVars.hasVideos );
// }
var res = {response: {hasVideos: BgVars.hasVideos}};
if(BrowserDetect.firefox){
return Promise.resolve(res);
}
sendResponse(res);
return true;
}
// var res = {response: {hasVideos: BgVars.hasVideos}};
// if(BrowserDetect.firefox){
// return Promise.resolve(res);
// }
// sendResponse(res);
// return true;
// }
if(message.cmd == "get-config"){
var config = {};
config.videoAlignment = ExtensionConf.miscFullscreenSettings.videoFloat;
config.arConf = {};
config.arConf.enabled_global = ExtensionConf.arDetect.enabled == "blacklist";
// if(message.cmd == "get-config"){
// var config = {};
// config.videoAlignment = ExtensionConf.miscFullscreenSettings.videoFloat;
// config.arConf = {};
// config.arConf.enabled_global = ExtensionConf.arDetect.enabled == "blacklist";
config.site = {};
config.site.status = SitesConf.getSiteStatus(BgVars.currentSite);
config.site.arStatus = SitesConf.getArStatus(BgVars.currentSite);
// config.site = {};
// config.site.status = SitesConf.getSiteStatus(BgVars.currentSite);
// config.site.arStatus = SitesConf.getArStatus(BgVars.currentSite);
config.mode = ExtensionConf.extensionMode;
config.arMode = ExtensionConf.arDetect.mode;
config.arDisabledReason = ExtensionConf.arDetect.disabledReason;
config.arTimerPlaying = ExtensionConf.arDetect.timer_playing;
// config.mode = ExtensionConf.extensionMode;
// config.arMode = ExtensionConf.arDetect.mode;
// config.arDisabledReason = ExtensionConf.arDetect.disabledReason;
// config.arTimerPlaying = ExtensionConf.arDetect.timer_playing;
if(Debug.debug)
console.log("[uw-bg::_uwbg_rcvmsg] Keybinds.getKeybinds() returned this:", Keybinds.getKeybinds());
// if(Debug.debug)
// console.log("[uw-bg::_uwbg_rcvmsg] Keybinds.getKeybinds() returned this:", Keybinds.getKeybinds());
config.keyboardShortcuts = Keybinds.getKeybinds();
// config.keyboardShortcuts = Keybinds.getKeybinds();
// predvidevajmo, da je enako. Če je drugače, bomo popravili ko dobimo odgovor
// assume current is same as global & change that when you get response from content script
config.arConf.enabled_current = ExtensionConf.arDetect.enabled == "blacklist";
// // predvidevajmo, da je enako. Če je drugače, bomo popravili ko dobimo odgovor
// // assume current is same as global & change that when you get response from content script
// config.arConf.enabled_current = ExtensionConf.arDetect.enabled == "blacklist";
var res = {response: config}
// var res = {response: config}
if(Debug.debug){
console.log("[uw-bg::_uwbg_rcvmsg] get-config: returning this to popup script:", res);
}
// if(Debug.debug){
// console.log("[uw-bg::_uwbg_rcvmsg] get-config: returning this to popup script:", res);
// }
if(BrowserDetect.firefox){
return Promise.resolve(res);
}
sendResponse(res);
return true;
}
// if(BrowserDetect.firefox){
// return Promise.resolve(res);
// }
// sendResponse(res);
// return true;
// }
if(message.cmd == "register-video"){
// dobili smo sporočilce, ki pravi: "hej jaz imam video, naredi cahen" — ampak preden naredimo cahen,
// se je potrebno prepričati, da je sporočilce prišlo iz pravilnega zavihka. Trenutno odprt zavihek
// lahko dobimo to. ID zavihka, iz katerega je prišlo sporočilo, se skriva v sender.tab.id
// ~<><\\\][=================][///><>~
// we got a message that says: "hey I have a video, make a mark or something" — but before we do the
// mark, we should check if the message has truly arrived from currently active tab. We can get the
// id of currently active tab here. ID of the sender tab is hidden in sender.tab.id.
// if(message.cmd == "register-video"){
// // dobili smo sporočilce, ki pravi: "hej jaz imam video, naredi cahen" — ampak preden naredimo cahen,
// // se je potrebno prepričati, da je sporočilce prišlo iz pravilnega zavihka. Trenutno odprt zavihek
// // lahko dobimo to. ID zavihka, iz katerega je prišlo sporočilo, se skriva v sender.tab.id
// // ~<><\\\][=================][///><>~
// // we got a message that says: "hey I have a video, make a mark or something" — but before we do the
// // mark, we should check if the message has truly arrived from currently active tab. We can get the
// // id of currently active tab here. ID of the sender tab is hidden in sender.tab.id.
_uwbg_registerVideo(sender.tab.id);
}
// _uwbg_registerVideo(sender.tab.id);
// }
else if(message.cmd == "uw-enabled-for-site"){
// else if(message.cmd == "uw-enabled-for-site"){
var mode = SitesConf.getSiteStatus(BgVars.currentSite);
// var mode = SitesConf.getSiteStatus(BgVars.currentSite);
if(BrowserDetect.usebrowser == "firefox")
return Promise.resolve({response: mode});
// if(BrowserDetect.usebrowser == "firefox")
// return Promise.resolve({response: mode});
try{
sendResponse({response: mode});
}
catch(chromeIsShitError){};
// try{
// sendResponse({response: mode});
// }
// catch(chromeIsShitError){};
return true;
}
else if(message.cmd == "enable-for-site"){
SitesConf.updateSite(BgVars.currentSite, {status: message.option, statusEmbedded: message.option});
}
else if(message.cmd == "enable-autoar"){
ExtensionConf.arDetect.mode = "blacklist";
Settings.save(ExtensionConf);
// return true;
// }
// else if(message.cmd == "enable-for-site"){
// SitesConf.updateSite(BgVars.currentSite, {status: message.option, statusEmbedded: message.option});
// }
// else if(message.cmd == "enable-autoar"){
// ExtensionConf.arDetect.mode = "blacklist";
// Settings.save(ExtensionConf);
// Comms.sendToAll({cmd: "reload-settings", sender: "uwbg"})
if(Debug.debug){
console.log("[uw-bg] autoar set to enabled (blacklist). evidenz:", ExtensionConf);
}
}
else if(message.cmd == "disable-autoar"){
ExtensionConf.arDetect.mode = "disabled";
if(message.reason){
ExtensionConf.arDetect.disabledReason = message.reason;
} else {
ExtensionConf.arDetect.disabledReason = '';
}
Settings.save(ExtensionConf);
// Comms.sendToAll({cmd: "reload-settings", sender: "uwbg"});
if(Debug.debug){
console.log("[uw-bg] autoar set to disabled. evidenz:", ExtensionConf);
}
}
else if(message.cmd == "gib-settings"){
if(Debug.debug)
console.log("[uw-bg] we got asked for settings. Returning this:", ExtensionConf);
// if(Debug.debug){
// console.log("[uw-bg] autoar set to enabled (blacklist). evidenz:", ExtensionConf);
// }
// }
// else if(message.cmd == "disable-autoar"){
// ExtensionConf.arDetect.mode = "disabled";
// if(message.reason){
// ExtensionConf.arDetect.disabledReason = message.reason;
// } else {
// ExtensionConf.arDetect.disabledReason = '';
// }
// Settings.save(ExtensionConf);
// // Comms.sendToAll({cmd: "reload-settings", sender: "uwbg"});
// if(Debug.debug){
// console.log("[uw-bg] autoar set to disabled. evidenz:", ExtensionConf);
// }
// }
// else if(message.cmd == "gib-settings"){
// if(Debug.debug)
// console.log("[uw-bg] we got asked for settings. Returning this:", ExtensionConf);
if(BrowserDetect.usebrowser == "firefox")
return Promise.resolve({response: ExtensionConf});
// if(BrowserDetect.usebrowser == "firefox")
// return Promise.resolve({response: ExtensionConf});
try{
sendResponse({response: ExtensionConf});
}
catch(chromeIsShitError){};
// try{
// sendResponse({response: ExtensionConf});
// }
// catch(chromeIsShitError){};
return true;
}
else if(message.cmd = "autoar-set-timer-playing"){
// return true;
// }
// else if(message.cmd = "autoar-set-timer-playing"){
if(Debug.debug)
console.log("[uw-bg] trying to set new interval for autoAr. New interval is",message.timeout,"ms");
// if(Debug.debug)
// console.log("[uw-bg] trying to set new interval for autoAr. New interval is",message.timeout,"ms");
var timeout = message.timeout;
// var timeout = message.timeout;
if(timeout < 1)
timeout = 1;
if(timeout > 999)
timeout = 999;
// if(timeout < 1)
// timeout = 1;
// if(timeout > 999)
// timeout = 999;
ExtensionConf.arDetect.timer_playing = timeout;
Settings.save(ExtensionConf);
Comms.sendToAll({cmd: "update-settings", sender: "uwbg", newConf: ExtensionConf});
}
// ExtensionConf.arDetect.timer_playing = timeout;
// Settings.save(ExtensionConf);
// Comms.sendToAll({cmd: "update-settings", sender: "uwbg", newConf: ExtensionConf});
// }
}
// }
// main();

View File

@ -273,7 +273,7 @@ document.addEventListener("click", (e) => {
if(e.target.classList.contains("_changeAr")){
if(e.target.classList.contains("_ar_auto")){
command.cmd = "autoar-enable";
command.cmd = "autoar-start";
command.enabled = true;
return command;
}
@ -352,18 +352,11 @@ document.addEventListener("click", (e) => {
// this event fires before the checkbox is checked, therefore arStatus is opposite of what it should be
if(! arStatus){
Comms.sendToBackgroundScript({cmd: "disable-autoar", sender: "popup", receiver: "uwbg"});
Comms.sendToAll({cmd: "disable-autoar", sender: "popup", receiver: "uwbg"});
Comms.sendToAll({cmd: "stop-autoar", sender: "popup", receiver: "uwbg"});
return {cmd: "autoar-disable", sender: "popup", receiver: "uwbg"};
} else {
return {cmd: "autoar-enable", sender: "popup", receiver: "uwbg"};
}
else{
Comms.sendToAll({cmd: "enable-autoar", sender: "popup", receiver: "uwbg"});
Comms.sendToBackgroundScript({cmd: "enable-autoar", sender: "popup", receiver: "uwbg"});
Comms.sendToAll({cmd: "force-ar", newAr: "auto", arType: "legacy", sender: "popup", receiver: "uwbg"});
}
return;
}
else if(e.target.classList.contains("_save_autoAr_frequency")){
} else if(e.target.classList.contains("_save_autoAr_frequency")) {
var value = parseInt(document.getElementById("_input_autoAr_frequency").value.trim());
if(! isNaN(value)){