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++;
}
if(stuffChecked == stufTToCheck){
if(stuffChecked == stuffToCheck){
if(Debug.debug){
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();
BgVars.currentSite = extractHostname(tabs[0].url);
//
setInterval(_uwbg_check4videos, 5000);
}
async function _uwbg_onTabSwitched(activeInfo){
@ -105,7 +107,9 @@ async function _uwbg_registerVideo(tabId){
}
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

View File

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

View File

@ -75,13 +75,17 @@ function check4videos(){
Comms.sendToBackgroundScript({cmd: "has-videos"})
.then(response => {
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){
hasVideos = true;
// openMenu(selectedMenu);
hideWarning("no-videos-warning");
}
else{
// brute force error mitigation.
setTimeout(check4videos, 2000);
}
})
.catch(error => {
if(Debug.debug)