register-video in ghettoOnChange didn't always work. background script now polls content script of current tab every 5 or so seconds. Popup script polls for has-video changes once every two seconds or so. 5s and 2s seem reasonable.

This commit is contained in:
Tamius Han 2018-02-06 00:36:48 +01:00
parent fc4f073e5d
commit d78fa346ce
4 changed files with 15 additions and 3 deletions

View File

@ -374,7 +374,7 @@ var _res_antiCssOverride = function(){
stuffChecked++; stuffChecked++;
} }
if(stuffChecked == stufTToCheck){ if(stuffChecked == stuffToCheck){
if(Debug.debug){ if(Debug.debug){
console.log("[Resizer::_res_antiCssOverride] My spaghett rests untouched. (nobody overrode our CSS, doing nothing)"); console.log("[Resizer::_res_antiCssOverride] My spaghett rests untouched. (nobody overrode our CSS, doing nothing)");
} }

View File

@ -41,6 +41,8 @@ async function main(){
var tabs = await Comms.getActiveTab(); var tabs = await Comms.getActiveTab();
BgVars.currentSite = extractHostname(tabs[0].url); BgVars.currentSite = extractHostname(tabs[0].url);
//
setInterval(_uwbg_check4videos, 5000);
} }
async function _uwbg_onTabSwitched(activeInfo){ async function _uwbg_onTabSwitched(activeInfo){
@ -105,7 +107,9 @@ async function _uwbg_registerVideo(tabId){
} }
return; return;
} }
if(Debug.debug){
console.log("%c[uw-bg::_uwbg_registerVideo] request came from currently active tab!", "color: #afd, background: #000");
}
BgVars.hasVideos = true; 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

View File

@ -102,6 +102,10 @@ function ghettoOnChange(){
video !== null && video !== null &&
video.videoWidth > 0 && video.videoWidth > 0 &&
video.videoHeight > 0 ){ video.videoHeight > 0 ){
if(Debug.debug){
console.log("%c[uw::ghettoOnChange] detected video. registering!", "color: #99f, background: #000");
}
GlobalVars.video = video; GlobalVars.video = video;
Comms.sendToBackgroundScript({"cmd":"register-video"}); Comms.sendToBackgroundScript({"cmd":"register-video"});
} }

View File

@ -75,13 +75,17 @@ function check4videos(){
Comms.sendToBackgroundScript({cmd: "has-videos"}) Comms.sendToBackgroundScript({cmd: "has-videos"})
.then(response => { .then(response => {
if(Debug.debug){ if(Debug.debug){
console.log("[popup.js::check4videos] received response:",response, "has video?", response.response); console.log("[popup.js::check4videos] received response:",response, "has video?", response.response.hasVideos);
} }
if(response.response.hasVideos){ if(response.response.hasVideos){
hasVideos = true; hasVideos = true;
// openMenu(selectedMenu); // openMenu(selectedMenu);
hideWarning("no-videos-warning"); hideWarning("no-videos-warning");
} }
else{
// brute force error mitigation.
setTimeout(check4videos, 2000);
}
}) })
.catch(error => { .catch(error => {
if(Debug.debug) if(Debug.debug)