Fixes for reddit
This commit is contained in:
parent
7b73a42e5c
commit
46bc4bfd8d
@ -83,23 +83,23 @@ const ExtensionConfPatch = [
|
||||
type: 'testing',
|
||||
DOM: {
|
||||
player: {
|
||||
manual: true,
|
||||
manual: false,
|
||||
useRelativeAncestor: false,
|
||||
querySelectors: '.reddit-video-player-root'
|
||||
querySelectors: '.reddit-video-player-root, .media-preview-content'
|
||||
}
|
||||
},
|
||||
css: '',
|
||||
css: 'video {\n width: 100% !important;\n height: 100% !important;\n}',
|
||||
},
|
||||
"www.reddit.com" : {
|
||||
type: 'testing',
|
||||
DOM: {
|
||||
player: {
|
||||
manual: true,
|
||||
manual: false,
|
||||
useRelativeAncestor: false,
|
||||
querySelectors: '.reddit-video-player-root'
|
||||
querySelectors: '.reddit-video-player-root, .media-preview-content'
|
||||
}
|
||||
},
|
||||
css: '',
|
||||
css: 'video {\n width: 100% !important;\n height: 100% !important;\n}',
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -974,12 +974,12 @@ whatsNewChecked: true,
|
||||
keyboardShortcutsEnabled: ExtensionMode.Default,
|
||||
DOM: {
|
||||
player: {
|
||||
manual: true,
|
||||
manual: false,
|
||||
useRelativeAncestor: false,
|
||||
querySelectors: '.reddit-video-player-root, .media-preview-content'
|
||||
}
|
||||
},
|
||||
css: '',
|
||||
css: 'video {\n width: 100% !important;\n height: 100% !important;\n}',
|
||||
},
|
||||
"www.reddit.com" : {
|
||||
mode: ExtensionMode.Enabled,
|
||||
@ -991,12 +991,12 @@ whatsNewChecked: true,
|
||||
keyboardShortcutsEnabled: ExtensionMode.Default,
|
||||
DOM: {
|
||||
player: {
|
||||
manual: true,
|
||||
manual: false,
|
||||
useRelativeAncestor: false,
|
||||
querySelectors: '.reddit-video-player-root, .media-preview-content'
|
||||
}
|
||||
},
|
||||
css: '',
|
||||
css: 'video {\n width: 100% !important;\n height: 100% !important;\n}',
|
||||
},
|
||||
"imgur.com": {
|
||||
mode: -1,
|
||||
|
@ -34,28 +34,38 @@ if(Debug.debug)
|
||||
|
||||
class PlayerData {
|
||||
constructor(videoData) {
|
||||
this.logger = videoData.logger;
|
||||
this.videoData = videoData;
|
||||
this.video = videoData.video;
|
||||
this.settings = videoData.settings;
|
||||
this.extensionMode = videoData.extensionMode;
|
||||
this.invalid = false;
|
||||
this.element = this.getPlayer();
|
||||
this.dimensions = undefined;
|
||||
this.overlayNode = undefined;
|
||||
try {
|
||||
this.logger = videoData.logger;
|
||||
this.videoData = videoData;
|
||||
this.video = videoData.video;
|
||||
this.settings = videoData.settings;
|
||||
this.extensionMode = videoData.extensionMode;
|
||||
this.invalid = false;
|
||||
this.element = this.getPlayer();
|
||||
this.dimensions = undefined;
|
||||
this.overlayNode = undefined;
|
||||
|
||||
// this happens when we don't find a matching player element
|
||||
if (!this.element) {
|
||||
// this happens when we don't find a matching player element
|
||||
if (!this.element) {
|
||||
this.invalid = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.extensionMode === ExtensionMode.Enabled) {
|
||||
this.checkPlayerSizeChange();
|
||||
}
|
||||
this.startChangeDetection();
|
||||
} catch (e) {
|
||||
console.error('[Ultrawidify::PlayerData::ctor] There was an error setting up player data. You should be never seeing this message. Error:', e);
|
||||
this.invalid = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.extensionMode === ExtensionMode.Enabled) {
|
||||
this.checkPlayerSizeChange();
|
||||
}
|
||||
this.startChangeDetection();
|
||||
}
|
||||
|
||||
async sleep(timeout) {
|
||||
return new Promise( (resolve, reject) => setTimeout(() => resolve(), timeout));
|
||||
}
|
||||
|
||||
|
||||
static isFullScreen(){
|
||||
return ( window.innerHeight == window.screen.height && window.innerWidth == window.screen.width);
|
||||
}
|
||||
@ -87,6 +97,7 @@ class PlayerData {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const ths = this;
|
||||
this.observer = new MutationObserver((m,o) => this.onPlayerDimensionsChanged(m,o,ths));
|
||||
|
||||
@ -97,19 +108,28 @@ class PlayerData {
|
||||
};
|
||||
|
||||
this.observer.observe(this.element, observerConf);
|
||||
|
||||
} catch (e) {
|
||||
console.error("failed to set observer",e )
|
||||
}
|
||||
// legacy mode still exists, but acts as a fallback for observers and is triggered less
|
||||
// frequently in order to avoid too many pointless checks
|
||||
this.legacyChangeDetection();
|
||||
}
|
||||
|
||||
async legacyChangeDetection() {
|
||||
console.log("starting legacy cd")
|
||||
while (!this.halted) {
|
||||
console.log("loop")
|
||||
await this.sleep(1000);
|
||||
if (this.checkPlayerSizeChange()) {
|
||||
this.videoData.restore();
|
||||
try {
|
||||
if (this.checkPlayerSizeChange()) {
|
||||
this.videoData.resizer.restore();
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('[playerdata::legacycd] this message is pretty high on the list of messages you shouldnt see', e);
|
||||
}
|
||||
}
|
||||
console.log("HALTED - STOPPING CHANGE DETECTION FOR", this.element)
|
||||
}
|
||||
|
||||
stopChangeDetection(){
|
||||
@ -266,9 +286,14 @@ class PlayerData {
|
||||
|
||||
score = 100;
|
||||
|
||||
|
||||
if (element.id.indexOf('player') !== -1) { // prefer elements with 'player' in id
|
||||
score += 75;
|
||||
}
|
||||
// this has only been observed on steam
|
||||
if (element.id.indexOf('movie') !== -1) {
|
||||
score += 75;
|
||||
}
|
||||
if (element.classList.toString().indexOf('player') !== -1) { // prefer elements with 'player' in classlist, but a bit less than id
|
||||
score += 50;
|
||||
}
|
||||
@ -328,7 +353,8 @@ class PlayerData {
|
||||
this.logger.log('info', 'debug', "[PlayerDetect] player size changed. reason: dimension change. Old dimensions?", this.dimensions.width, this.dimensions.height, "new dimensions:", this.element.offsetWidth, this.element.offsetHeight);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// if size doesn't match, update & return true
|
||||
if (!this.dimensions
|
||||
|| this.dimensions.width != this.element.offsetWidth
|
||||
@ -351,7 +377,6 @@ class PlayerData {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -24,9 +24,7 @@ class VideoData {
|
||||
attributeOldValue: true,
|
||||
};
|
||||
|
||||
const ths = this;
|
||||
this.observer = new MutationObserver( (m, o) => this.onVideoDimensionsChanged(m, o, ths));
|
||||
this.observer.observe(video, observerConf);
|
||||
|
||||
|
||||
// POZOR: VRSTNI RED JE POMEMBEN (arDetect mora bit zadnji)
|
||||
// NOTE: ORDERING OF OBJ INITIALIZATIONS IS IMPORTANT (arDetect needs to go last)
|
||||
@ -36,6 +34,10 @@ class VideoData {
|
||||
return;
|
||||
}
|
||||
|
||||
const ths = this;
|
||||
this.observer = new MutationObserver( (m, o) => this.onVideoDimensionsChanged(m, o, ths));
|
||||
this.observer.observe(video, observerConf);
|
||||
|
||||
this.dimensions = {
|
||||
width: this.video.offsetWidth,
|
||||
height: this.video.offsetHeight,
|
||||
@ -107,6 +109,16 @@ class VideoData {
|
||||
}
|
||||
|
||||
validateVideoOffsets() {
|
||||
// validate if current video still exists. If not, we destroy current object
|
||||
try {
|
||||
if (! document.body.contains(this.video)) {
|
||||
console.log("this video is having a bit of a hiatus:", this.video)
|
||||
this.destroy();
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("e", e)
|
||||
}
|
||||
// THIS BREAKS PANNING
|
||||
const cs = window.getComputedStyle(this.video);
|
||||
const pcs = window.getComputedStyle(this.player.element);
|
||||
@ -190,33 +202,27 @@ class VideoData {
|
||||
destroy() {
|
||||
this.logger.log('info', ['debug', 'init'], `[VideoData::destroy] <vdid:${this.vdid}> received destroy command`);
|
||||
|
||||
this.video.classList.remove(this.userCssClassName);
|
||||
if (this.video) {
|
||||
this.video.classList.remove(this.userCssClassName);
|
||||
}
|
||||
|
||||
this.pause();
|
||||
this.destroyed = true;
|
||||
if (this.arDetector){
|
||||
try {
|
||||
this.arDetector.stop();
|
||||
this.arDetector.destroy();
|
||||
} catch (e) {}
|
||||
}
|
||||
try {
|
||||
this.arDetector.stop();
|
||||
this.arDetector.destroy();
|
||||
} catch (e) {}
|
||||
this.arDetector = undefined;
|
||||
if (this.resizer){
|
||||
try {
|
||||
this.resizer.destroy();
|
||||
} catch (e) {}
|
||||
}
|
||||
try {
|
||||
this.resizer.destroy();
|
||||
} catch (e) {}
|
||||
this.resizer = undefined;
|
||||
if (this.player){
|
||||
try {
|
||||
this.player.destroy();
|
||||
} catch (e) {}
|
||||
}
|
||||
if (this.observer) {
|
||||
try {
|
||||
this.observer.disconnect();
|
||||
} catch (e) {}
|
||||
}
|
||||
try {
|
||||
this.player.destroy();
|
||||
} catch (e) {}
|
||||
try {
|
||||
this.observer.disconnect();
|
||||
} catch (e) {}
|
||||
this.player = undefined;
|
||||
this.video = undefined;
|
||||
}
|
||||
|
@ -314,7 +314,9 @@ class Resizer {
|
||||
}
|
||||
else {
|
||||
if (this.lastAr && this.lastAr.ratio === null) {
|
||||
throw "Last ar is null!"
|
||||
// if this is the case, we do nothing as we have the correct aspect ratio
|
||||
// throw "Last ar is null!"
|
||||
return;
|
||||
}
|
||||
this.setAr(this.lastAr, this.lastAr)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user