PageInfo: rescan doesn't compare found <video> elements to elements in destroyed VideoData objects, fixing the issue where autodetection broke upon visiting youtube's search page
This commit is contained in:
parent
42cf4d91e7
commit
69d665f6fd
@ -99,6 +99,12 @@ var ExtensionConf = {
|
|||||||
retryTimeout: 200
|
retryTimeout: 200
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
pageInfo: {
|
||||||
|
timeouts: {
|
||||||
|
urlCheck: 200,
|
||||||
|
rescan: 1500
|
||||||
|
}
|
||||||
|
},
|
||||||
colors:{
|
colors:{
|
||||||
// criticalFail: "background: #fa2; color: #000"
|
// criticalFail: "background: #fa2; color: #000"
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ class VideoData {
|
|||||||
constructor(video){
|
constructor(video){
|
||||||
this.arSetupComplete = false;
|
this.arSetupComplete = false;
|
||||||
this.video = video;
|
this.video = video;
|
||||||
|
this.destroyed = false;
|
||||||
|
|
||||||
// POZOR: VRSTNI RED JE POMEMBEN (arDetect mora bit zadnji)
|
// POZOR: VRSTNI RED JE POMEMBEN (arDetect mora bit zadnji)
|
||||||
// NOTE: ORDERING OF OBJ INITIALIZATIONS IS IMPORTANT (arDetect needs to go last)
|
// NOTE: ORDERING OF OBJ INITIALIZATIONS IS IMPORTANT (arDetect needs to go last)
|
||||||
@ -36,6 +37,7 @@ class VideoData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
|
this.destroyed = true;
|
||||||
if(this.arDetector){
|
if(this.arDetector){
|
||||||
this.arDetector.stop();
|
this.arDetector.stop();
|
||||||
this.arDetector.destroy();
|
this.arDetector.destroy();
|
||||||
|
@ -7,93 +7,136 @@ class PageInfo {
|
|||||||
this.siteDisabled = false;
|
this.siteDisabled = false;
|
||||||
this.videos = [];
|
this.videos = [];
|
||||||
|
|
||||||
|
this.lastUrl = window.location.href;
|
||||||
|
|
||||||
this.rescan();
|
this.rescan(RescanReason.PERIODIC);
|
||||||
|
this.scheduleUrlCheck();
|
||||||
}
|
}
|
||||||
|
|
||||||
rescan(count){
|
rescan(rescanReason){
|
||||||
try{
|
try{
|
||||||
var vids = document.getElementsByTagName('video');
|
var vids = document.getElementsByTagName('video');
|
||||||
|
|
||||||
if(!vids || vids.length == 0){
|
if(!vids || vids.length == 0){
|
||||||
this.hasVideos = false;
|
this.hasVideos = false;
|
||||||
|
|
||||||
this.scheduleRescan();
|
if(rescanReason == RescanReason.PERIODIC){
|
||||||
|
this.scheduleRescan(RescanReason.PERIODIC);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// debugger;
|
|
||||||
|
|
||||||
// add new videos
|
// add new videos
|
||||||
// for(var video of vids){
|
this.hasVideos = false;
|
||||||
// var existing = this.videos.find( (x) => {
|
var videoExists = false;
|
||||||
// if (video && x == video.video)
|
var video, v;
|
||||||
// return x;
|
|
||||||
// if (video && x.currentSrc == video.video.currentSrc){
|
|
||||||
// return x;
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
|
|
||||||
// if(existing){
|
|
||||||
// video.video = existing;
|
|
||||||
// } else {
|
|
||||||
// this.videos.push(
|
|
||||||
// new VideoData(video)
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
if(! vids[0].offsetWidth || ! vids[0].offsetHeight){
|
|
||||||
this.hasVideos = false;
|
|
||||||
|
|
||||||
if(Debug.debug){
|
for (video of vids) {
|
||||||
console.log("[PageInfo::rescan] video lacks offsetwidth or offsetheight, doing nothing")
|
// če najdemo samo en video z višino in širino, to pomeni, da imamo na strani veljavne videe
|
||||||
}
|
// če trenutni video nima definiranih teh vrednostih, preskočimo vse nadaljnja preverjanja
|
||||||
|
// <===[:::::::]===>
|
||||||
this.scheduleRescan();
|
// if we find even a single video with width and height, that means the page has valid videos
|
||||||
return;
|
// if video lacks either of the two properties, we skip all further checks cos pointless
|
||||||
}
|
if(video.offsetWidth && video.offsetHeight){
|
||||||
|
this.hasVideos = true;
|
||||||
if(this.videos.length > 0){
|
|
||||||
if(vids[0] == this.videos[0].video){
|
|
||||||
console.log("[PageInfo::rescan] videos are equal, doing nothing")
|
|
||||||
// do nothing
|
|
||||||
} else {
|
} else {
|
||||||
console.log("videos not equal!", vids[0], this.videos[0].video)
|
continue;
|
||||||
this.videos[0].destroy();
|
|
||||||
this.videos[0] = new VideoData(vids[0]);
|
|
||||||
this.videos[0].initArDetection();
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
|
|
||||||
if(Debug.debug)
|
videoExists = false;
|
||||||
console.log("[PageInfo::rescan] Adding new video!", vids[0], ";", vids[0].offsetWidth, "×", vids[0].offsetHeight);
|
|
||||||
|
|
||||||
this.videos.push(new VideoData(vids[0]));
|
for (v of this.videos) {
|
||||||
this.videos[0].initArDetection();
|
if (v.destroyed) {
|
||||||
|
continue; //TODO: if destroyed video is same as current video, copy aspect ratio settings to current video
|
||||||
|
}
|
||||||
|
|
||||||
|
if (v.video == video) {
|
||||||
|
videoExists = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (videoExists) {
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
v = new VideoData(video);
|
||||||
|
v.initArDetection();
|
||||||
|
this.videos.push(v);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.removeDestroyed();
|
||||||
|
|
||||||
// console.log("Rescan complete. Total videos?", this.videos.length)
|
// console.log("Rescan complete. Total videos?", this.videos.length)
|
||||||
}catch(e){
|
}catch(e){
|
||||||
console.log("rescan error:",e)
|
console.log("rescan error:",e)
|
||||||
}
|
}
|
||||||
this.scheduleRescan();
|
|
||||||
|
if(rescanReason == RescanReason.PERIODIC){
|
||||||
|
this.scheduleRescan(RescanReason.PERIODIC);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
scheduleRescan(){
|
removeDestroyed(){
|
||||||
|
this.videos = this.videos.filter( vid => vid.destroyed === false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
scheduleRescan(rescanReason){
|
||||||
|
if(rescanReason != RescanReason.PERIODIC){
|
||||||
|
this.rescan(rescanReason);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try{
|
try{
|
||||||
if(this.rescanTimer){
|
if(this.rescanTimer){
|
||||||
clearTimeout(this.rescanTimer);
|
clearTimeout(this.rescanTimer);
|
||||||
|
}
|
||||||
|
|
||||||
|
var ths = this;
|
||||||
|
|
||||||
|
|
||||||
|
this.rescanTimer = setTimeout(function(rr){
|
||||||
|
ths.rescanTimer = null;
|
||||||
|
ths.rescan(rr);
|
||||||
|
ths = null;
|
||||||
|
}, rescanReason === ExtensionConf.pageInfo.timeouts.rescan, RescanReason.PERIODIC)
|
||||||
|
} catch(e) {
|
||||||
|
if(Debug.debug){
|
||||||
|
console.log("[PageInfo::scheduleRescan] scheduling rescan failed. Here's why:",e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
scheduleUrlCheck() {
|
||||||
|
try{
|
||||||
|
if(this.urlCheckTimer){
|
||||||
|
clearTimeout(this.urlCheckTimer);
|
||||||
}
|
}
|
||||||
|
|
||||||
var ths = this;
|
var ths = this;
|
||||||
|
|
||||||
|
|
||||||
this.rescanTimer = setTimeout(function(){
|
this.rescanTimer = setTimeout(function(){
|
||||||
ths.rescanTimer = null;
|
ths.rescanTimer = null;
|
||||||
ths.rescan();
|
ths.ghettoUrlCheck();
|
||||||
ths = null;
|
ths = null;
|
||||||
}, 1000)
|
}, ExtensionConf.pageInfo.timeouts.urlCheck)
|
||||||
}catch(e){console.log("eee",e)}
|
}catch(e){
|
||||||
|
if(Debug.debug){
|
||||||
|
console.log("[PageInfo::scheduleUrlCheck] scheduling URL check failed. Here's why:",e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ghettoUrlCheck() {
|
||||||
|
if (this.lastUrl != window.location.href){
|
||||||
|
if(Debug.debug){
|
||||||
|
console.log("[PageInfo::ghettoUrlCheck] URL has changed. Triggering a rescan!");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.rescan(RescanReason.URL_CHANGE);
|
||||||
|
this.lastUrl = window.location.href;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
initArDetection(){
|
initArDetection(){
|
||||||
@ -116,3 +159,9 @@ class PageInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var RescanReason = {
|
||||||
|
PERIODIC: 0,
|
||||||
|
URL_CHANGE: 1,
|
||||||
|
MANUAL: 2
|
||||||
|
}
|
94
js/uw.js
94
js/uw.js
@ -77,65 +77,65 @@ async function setup(){
|
|||||||
// tukaj gledamo, ali se je velikost predvajalnika spremenila. Če se je, ponovno prožimo resizer
|
// tukaj gledamo, ali se je velikost predvajalnika spremenila. Če se je, ponovno prožimo resizer
|
||||||
// here we check (in the most ghetto way) whether player size has changed. If it has, we retrigger resizer.
|
// here we check (in the most ghetto way) whether player size has changed. If it has, we retrigger resizer.
|
||||||
|
|
||||||
var _video_recheck_counter = 5;
|
// var _video_recheck_counter = 5;
|
||||||
var _video_recheck_period = 1; // on this many retries
|
// var _video_recheck_period = 1; // on this many retries
|
||||||
|
|
||||||
function ghettoOnChange(){
|
// function ghettoOnChange(){
|
||||||
|
|
||||||
if(_video_recheck_counter++ > _video_recheck_period){
|
// if(_video_recheck_counter++ > _video_recheck_period){
|
||||||
_video_recheck_counter = 0;
|
// _video_recheck_counter = 0;
|
||||||
|
|
||||||
if ( GlobalVars.video == null ||
|
// if ( GlobalVars.video == null ||
|
||||||
GlobalVars.video == undefined ||
|
// GlobalVars.video == undefined ||
|
||||||
GlobalVars.video.videoWidth == 0 ||
|
// GlobalVars.video.videoWidth == 0 ||
|
||||||
GlobalVars.video.videoHeight == 0 ){
|
// GlobalVars.video.videoHeight == 0 ){
|
||||||
|
|
||||||
var video = document.getElementsByTagName("video")[0];
|
// var video = document.getElementsByTagName("video")[0];
|
||||||
if ( video !== undefined &&
|
// if ( video !== undefined &&
|
||||||
video !== null &&
|
// video !== null &&
|
||||||
video.videoWidth > 0 &&
|
// video.videoWidth > 0 &&
|
||||||
video.videoHeight > 0 ){
|
// video.videoHeight > 0 ){
|
||||||
if(Debug.debug){
|
// if(Debug.debug){
|
||||||
console.log("%c[uw::ghettoOnChange] detected video. registering!", "color: #99f, background: #000");
|
// console.log("%c[uw::ghettoOnChange] detected video. registering!", "color: #99f, background: #000");
|
||||||
console.log("[uw::ghettoOnChange] just for shits and giggles, let's see what's happened with GlobalVars.playerDimensions:", GlobalVars.playerDimensions)
|
// console.log("[uw::ghettoOnChange] just for shits and giggles, let's see what's happened with GlobalVars.playerDimensions:", GlobalVars.playerDimensions)
|
||||||
}
|
// }
|
||||||
|
|
||||||
// zaznali smo novo <video> značko. Zaradi tega bomo resetirali GlobalVars.playerDimensions
|
// // zaznali smo novo <video> značko. Zaradi tega bomo resetirali GlobalVars.playerDimensions
|
||||||
// a new <video> has been detected. We'll be resetting GlobalVars.playerDimensions
|
// // a new <video> has been detected. We'll be resetting GlobalVars.playerDimensions
|
||||||
GlobalVars.playerDimensions = PlayerDetect.getPlayerDimensions(video);
|
// GlobalVars.playerDimensions = PlayerDetect.getPlayerDimensions(video);
|
||||||
|
|
||||||
GlobalVars.video = video;
|
// GlobalVars.video = video;
|
||||||
Comms.sendToBackgroundScript({"cmd":"register-video"});
|
// Comms.sendToBackgroundScript({"cmd":"register-video"});
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
if(! GlobalVars.video)
|
// if(! GlobalVars.video)
|
||||||
return;
|
// return;
|
||||||
|
|
||||||
if(GlobalVars.playerDimensions == null){
|
// if(GlobalVars.playerDimensions == null){
|
||||||
GlobalVars.playerDimensions = PlayerDetect.getPlayerDimensions( GlobalVars.video );
|
// GlobalVars.playerDimensions = PlayerDetect.getPlayerDimensions( GlobalVars.video );
|
||||||
|
|
||||||
|
|
||||||
if(GlobalVars.playerDimensions == undefined){
|
// if(GlobalVars.playerDimensions == undefined){
|
||||||
GlobalVars.playerDimensions = null;
|
// GlobalVars.playerDimensions = null;
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
function ghettoUrlWatcher(){
|
// function ghettoUrlWatcher(){
|
||||||
if (GlobalVars.lastUrl != window.location.href){
|
// if (GlobalVars.lastUrl != window.location.href){
|
||||||
if(Debug.debug){
|
// if(Debug.debug){
|
||||||
console.log("[uw::ghettoUrlWatcher] URL has changed. Trying to retrigger autoAr");
|
// console.log("[uw::ghettoUrlWatcher] URL has changed. Trying to retrigger autoAr");
|
||||||
}
|
// }
|
||||||
|
|
||||||
GlobalVars.video = null;
|
// GlobalVars.video = null;
|
||||||
GlobalVars.lastUrl = window.location.href;
|
// GlobalVars.lastUrl = window.location.href;
|
||||||
// Resizer.reset();
|
// // Resizer.reset();
|
||||||
main();
|
// main();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user