From 4d1f2fd0d671781c71d32870c1aa5f99b9daf034 Mon Sep 17 00:00:00 2001 From: "Mr. Stallion" Date: Tue, 7 Sep 2021 20:33:01 -0500 Subject: [PATCH] Image preview fixes --- chat/preview/assets/browser.pre.js | 4 ++ chat/preview/assets/browser.processor.raw.js | 49 +++++++++++++++++++- chat/preview/image-dom-mutator.ts | 5 +- chat/preview/image-url-mutator.ts | 10 ++++ chat/preview/test-urls.txt | 3 ++ electron/main.ts | 4 ++ 6 files changed, 71 insertions(+), 4 deletions(-) diff --git a/chat/preview/assets/browser.pre.js b/chat/preview/assets/browser.pre.js index f165ba9..0976a86 100644 --- a/chat/preview/assets/browser.pre.js +++ b/chat/preview/assets/browser.pre.js @@ -54,6 +54,10 @@ const previewInitiationTime = Date.now(); (() => { try { const clear = () => { + if (window.location.href.match(/^https?:\/\/(www\.)?redgifs\.com/)) { + return; + } + if (window.location.href.match(/^https?:\/\/[a-zA-Z0-9-]+\.tumblr\.com/)) { // Because Tumblr sucks with their iframes const og = document.querySelectorAll('meta[property="og:image"]:not([content=""])'); diff --git a/chat/preview/assets/browser.processor.raw.js b/chat/preview/assets/browser.processor.raw.js index 6e32d42..0ea5aff 100644 --- a/chat/preview/assets/browser.processor.raw.js +++ b/chat/preview/assets/browser.processor.raw.js @@ -24,7 +24,8 @@ class FListImagePreviewDomMutator { skipElementRemove: false, safeTags: [], injectStyle: false, - delayPreprocess: false + delayPreprocess: false, + schedule: false }; /* ## SETTINGS_END ## */ @@ -113,6 +114,8 @@ class FListImagePreviewDomMutator { this.updateImgSizeTimer(this.img); this.cleanDom(this.body); + + this.finalize(); } @@ -396,9 +399,51 @@ class FListImagePreviewDomMutator { error(...args) { console.error('DOM Mutator:', ...args, `${(Date.now() - this.startTime)/1000}s`); } + + finalize(counter) { + if (counter <= 0) { + return; + } + + setTimeout( + () => { + if (this.img) { + this.attemptPlay(this.img); + } + + this.finalize(counter - 1); + }, + 100 + ); + } + + scheduler() { + setTimeout( + () => { + this.img = this.detectImage(this.selectors, this.body); + + if (!this.img) { + this.scheduler(); + return; + } + + this.run(); + }, + 200 + ); + } + + execute() { + if (this.settings.schedule) { + this.scheduler(); + return; + } + + this.run(); + } } /* ## EXECUTION_START ## */ const flistImagePreviewMutator = new FListImagePreviewDomMutator(); -flistImagePreviewMutator.run(); +flistImagePreviewMutator.execute(); /* ## EXECUTION_END ## */ diff --git a/chat/preview/image-dom-mutator.ts b/chat/preview/image-dom-mutator.ts index 59aeba1..066da02 100644 --- a/chat/preview/image-dom-mutator.ts +++ b/chat/preview/image-dom-mutator.ts @@ -168,7 +168,7 @@ export class ImageDomMutator { this.add('sexbot.gallery', this.getBaseJsMutatorScript(['video.hero', 'video'])); this.add('imagefap.com', this.getBaseJsMutatorScript(['.image-wrapper img', 'video', 'img'])); this.add('myhentaicomics.com', this.getBaseJsMutatorScript(['#entire_image img', 'video', 'img'])); - this.add('redgifs.com', this.getBaseJsMutatorScript(['video'])); + this.add('redgifs.com', this.getBaseJsMutatorScript(['video'], true, [], false, true)); this.add('furaffinity.net', this.getBaseJsMutatorScript(['#submissionImg', 'video', 'img'])); this.add('rule34.paheal.net', this.getBaseJsMutatorScript(['#main_image', 'video', 'img'])); this.add('xhamster.com', this.getBaseJsMutatorScript(['#photo_slider video', '#photo_slider img', 'video', 'img'])); @@ -316,7 +316,7 @@ export class ImageDomMutator { } - protected getBaseJsMutatorScript(elSelector: string[], skipElementRemove: boolean = false, safeTags: string[] = [], delayPreprocess = false): string { + protected getBaseJsMutatorScript(elSelector: string[], skipElementRemove: boolean = false, safeTags: string[] = [], delayPreprocess: boolean = false, scheduled: boolean = false): string { const js = this.scripts.processor; // ./assets/browser.processor.raw.js const settings = { @@ -324,6 +324,7 @@ export class ImageDomMutator { safeTags, delayPreprocess, selectors: elSelector, + schedule: scheduled, debug: this.debug }; diff --git a/chat/preview/image-url-mutator.ts b/chat/preview/image-url-mutator.ts index 02dda78..6726b8c 100644 --- a/chat/preview/image-url-mutator.ts +++ b/chat/preview/image-url-mutator.ts @@ -68,6 +68,15 @@ export class ImageUrlMutator { } ); + this.add( + /^https?:\/\/media[0-9]?.giphy.com\/media\/(.+)$/, + async(_url: string, match: RegExpMatchArray): Promise => { + const giphyUri = match[1]; + + return `https://i.giphy.com/media/${giphyUri}`; + } + ); + this.add( /^https?:\/\/(www.)?gfycat.com\/([a-z0-9A-Z\-]+)\/?$/, async(_url: string, match: RegExpMatchArray): Promise => { @@ -77,6 +86,7 @@ export class ImageUrlMutator { } ); + this.add( /^https?:\/\/e621.net\/(posts|post\/show)\/([0-9]+)/, async(url: string, match: RegExpMatchArray): Promise => { diff --git a/chat/preview/test-urls.txt b/chat/preview/test-urls.txt index 58e3d43..bbd987f 100644 --- a/chat/preview/test-urls.txt +++ b/chat/preview/test-urls.txt @@ -127,3 +127,6 @@ [url=https://www.hentai-foundry.com/pictures/user/LeraPI/879374/PDQ-style-my-OC-Violette]Hentai-foundry.com[/url] + [url=https://www.redgifs.com/watch/blissfulhandywhoopingcrane]Redgifs.com[/url] + + [url=https://media.giphy.com/media/P7hen0jkFBud3EZ6ez/giphy.gif]Giphy[/url] diff --git a/electron/main.ts b/electron/main.ts index 23c0411..459e7aa 100644 --- a/electron/main.ts +++ b/electron/main.ts @@ -239,6 +239,10 @@ function createWindow(): Electron.BrowserWindow | undefined { blocker.enableBlockingInSession(electron.session.defaultSession); + // blocker.blockStyles(); + blocker.blockFonts(); + // blocker.blockScripts(); + // Temp fix -- manually override adblocker's preload script // to point to CJS that has been copied over with config in webpack.config.js // require.resolve('@cliqz/adblocker-electron-preload');