Fixes for reddit
This commit is contained in:
parent
7b73a42e5c
commit
46bc4bfd8d
@ -83,23 +83,23 @@ const ExtensionConfPatch = [
|
|||||||
type: 'testing',
|
type: 'testing',
|
||||||
DOM: {
|
DOM: {
|
||||||
player: {
|
player: {
|
||||||
manual: true,
|
manual: false,
|
||||||
useRelativeAncestor: 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" : {
|
"www.reddit.com" : {
|
||||||
type: 'testing',
|
type: 'testing',
|
||||||
DOM: {
|
DOM: {
|
||||||
player: {
|
player: {
|
||||||
manual: true,
|
manual: false,
|
||||||
useRelativeAncestor: 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,
|
keyboardShortcutsEnabled: ExtensionMode.Default,
|
||||||
DOM: {
|
DOM: {
|
||||||
player: {
|
player: {
|
||||||
manual: true,
|
manual: false,
|
||||||
useRelativeAncestor: false,
|
useRelativeAncestor: false,
|
||||||
querySelectors: '.reddit-video-player-root, .media-preview-content'
|
querySelectors: '.reddit-video-player-root, .media-preview-content'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
css: '',
|
css: 'video {\n width: 100% !important;\n height: 100% !important;\n}',
|
||||||
},
|
},
|
||||||
"www.reddit.com" : {
|
"www.reddit.com" : {
|
||||||
mode: ExtensionMode.Enabled,
|
mode: ExtensionMode.Enabled,
|
||||||
@ -991,12 +991,12 @@ whatsNewChecked: true,
|
|||||||
keyboardShortcutsEnabled: ExtensionMode.Default,
|
keyboardShortcutsEnabled: ExtensionMode.Default,
|
||||||
DOM: {
|
DOM: {
|
||||||
player: {
|
player: {
|
||||||
manual: true,
|
manual: false,
|
||||||
useRelativeAncestor: false,
|
useRelativeAncestor: false,
|
||||||
querySelectors: '.reddit-video-player-root, .media-preview-content'
|
querySelectors: '.reddit-video-player-root, .media-preview-content'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
css: '',
|
css: 'video {\n width: 100% !important;\n height: 100% !important;\n}',
|
||||||
},
|
},
|
||||||
"imgur.com": {
|
"imgur.com": {
|
||||||
mode: -1,
|
mode: -1,
|
||||||
|
@ -34,28 +34,38 @@ if(Debug.debug)
|
|||||||
|
|
||||||
class PlayerData {
|
class PlayerData {
|
||||||
constructor(videoData) {
|
constructor(videoData) {
|
||||||
this.logger = videoData.logger;
|
try {
|
||||||
this.videoData = videoData;
|
this.logger = videoData.logger;
|
||||||
this.video = videoData.video;
|
this.videoData = videoData;
|
||||||
this.settings = videoData.settings;
|
this.video = videoData.video;
|
||||||
this.extensionMode = videoData.extensionMode;
|
this.settings = videoData.settings;
|
||||||
this.invalid = false;
|
this.extensionMode = videoData.extensionMode;
|
||||||
this.element = this.getPlayer();
|
this.invalid = false;
|
||||||
this.dimensions = undefined;
|
this.element = this.getPlayer();
|
||||||
this.overlayNode = undefined;
|
this.dimensions = undefined;
|
||||||
|
this.overlayNode = undefined;
|
||||||
|
|
||||||
// this happens when we don't find a matching player element
|
// this happens when we don't find a matching player element
|
||||||
if (!this.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;
|
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(){
|
static isFullScreen(){
|
||||||
return ( window.innerHeight == window.screen.height && window.innerWidth == window.screen.width);
|
return ( window.innerHeight == window.screen.height && window.innerWidth == window.screen.width);
|
||||||
}
|
}
|
||||||
@ -87,6 +97,7 @@ class PlayerData {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
const ths = this;
|
const ths = this;
|
||||||
this.observer = new MutationObserver((m,o) => this.onPlayerDimensionsChanged(m,o,ths));
|
this.observer = new MutationObserver((m,o) => this.onPlayerDimensionsChanged(m,o,ths));
|
||||||
|
|
||||||
@ -97,19 +108,28 @@ class PlayerData {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.observer.observe(this.element, observerConf);
|
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
|
// legacy mode still exists, but acts as a fallback for observers and is triggered less
|
||||||
// frequently in order to avoid too many pointless checks
|
// frequently in order to avoid too many pointless checks
|
||||||
this.legacyChangeDetection();
|
this.legacyChangeDetection();
|
||||||
}
|
}
|
||||||
|
|
||||||
async legacyChangeDetection() {
|
async legacyChangeDetection() {
|
||||||
|
console.log("starting legacy cd")
|
||||||
while (!this.halted) {
|
while (!this.halted) {
|
||||||
|
console.log("loop")
|
||||||
await this.sleep(1000);
|
await this.sleep(1000);
|
||||||
if (this.checkPlayerSizeChange()) {
|
try {
|
||||||
this.videoData.restore();
|
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(){
|
stopChangeDetection(){
|
||||||
@ -266,9 +286,14 @@ class PlayerData {
|
|||||||
|
|
||||||
score = 100;
|
score = 100;
|
||||||
|
|
||||||
|
|
||||||
if (element.id.indexOf('player') !== -1) { // prefer elements with 'player' in id
|
if (element.id.indexOf('player') !== -1) { // prefer elements with 'player' in id
|
||||||
score += 75;
|
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
|
if (element.classList.toString().indexOf('player') !== -1) { // prefer elements with 'player' in classlist, but a bit less than id
|
||||||
score += 50;
|
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);
|
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 size doesn't match, update & return true
|
||||||
if (!this.dimensions
|
if (!this.dimensions
|
||||||
|| this.dimensions.width != this.element.offsetWidth
|
|| this.dimensions.width != this.element.offsetWidth
|
||||||
@ -351,7 +377,6 @@ class PlayerData {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,9 +24,7 @@ class VideoData {
|
|||||||
attributeOldValue: true,
|
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)
|
// 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 +34,10 @@ class VideoData {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ths = this;
|
||||||
|
this.observer = new MutationObserver( (m, o) => this.onVideoDimensionsChanged(m, o, ths));
|
||||||
|
this.observer.observe(video, observerConf);
|
||||||
|
|
||||||
this.dimensions = {
|
this.dimensions = {
|
||||||
width: this.video.offsetWidth,
|
width: this.video.offsetWidth,
|
||||||
height: this.video.offsetHeight,
|
height: this.video.offsetHeight,
|
||||||
@ -107,6 +109,16 @@ class VideoData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
validateVideoOffsets() {
|
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
|
// THIS BREAKS PANNING
|
||||||
const cs = window.getComputedStyle(this.video);
|
const cs = window.getComputedStyle(this.video);
|
||||||
const pcs = window.getComputedStyle(this.player.element);
|
const pcs = window.getComputedStyle(this.player.element);
|
||||||
@ -190,33 +202,27 @@ class VideoData {
|
|||||||
destroy() {
|
destroy() {
|
||||||
this.logger.log('info', ['debug', 'init'], `[VideoData::destroy] <vdid:${this.vdid}> received destroy command`);
|
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.pause();
|
||||||
this.destroyed = true;
|
this.destroyed = true;
|
||||||
if (this.arDetector){
|
try {
|
||||||
try {
|
this.arDetector.stop();
|
||||||
this.arDetector.stop();
|
this.arDetector.destroy();
|
||||||
this.arDetector.destroy();
|
} catch (e) {}
|
||||||
} catch (e) {}
|
|
||||||
}
|
|
||||||
this.arDetector = undefined;
|
this.arDetector = undefined;
|
||||||
if (this.resizer){
|
try {
|
||||||
try {
|
this.resizer.destroy();
|
||||||
this.resizer.destroy();
|
} catch (e) {}
|
||||||
} catch (e) {}
|
|
||||||
}
|
|
||||||
this.resizer = undefined;
|
this.resizer = undefined;
|
||||||
if (this.player){
|
try {
|
||||||
try {
|
this.player.destroy();
|
||||||
this.player.destroy();
|
} catch (e) {}
|
||||||
} catch (e) {}
|
try {
|
||||||
}
|
this.observer.disconnect();
|
||||||
if (this.observer) {
|
} catch (e) {}
|
||||||
try {
|
|
||||||
this.observer.disconnect();
|
|
||||||
} catch (e) {}
|
|
||||||
}
|
|
||||||
this.player = undefined;
|
this.player = undefined;
|
||||||
this.video = undefined;
|
this.video = undefined;
|
||||||
}
|
}
|
||||||
|
@ -314,7 +314,9 @@ class Resizer {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (this.lastAr && this.lastAr.ratio === null) {
|
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)
|
this.setAr(this.lastAr, this.lastAr)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user