From 760885946f9ec1c70514f0fe16fbf518e7ad5457 Mon Sep 17 00:00:00 2001 From: "Mr. Stallion" Date: Sat, 2 Dec 2023 16:41:17 -0800 Subject: [PATCH] fixed tiktok previews --- CHANGELOG.md | 3 ++- chat/ChatView.vue | 4 ++-- chat/ads/ad-manager.ts | 4 ++-- chat/preview/ImagePreview.vue | 2 ++ chat/preview/assets/browser.processor.raw.js | 2 +- chat/preview/helper/external.ts | 7 +++++-- chat/preview/image-dom-mutator.ts | 5 +++++ chat/preview/image-url-mutator.ts | 18 ++++++++++++++++++ electron/filesystem.ts | 5 +++++ 9 files changed, 42 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 178c2cf..a4b593f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,11 +6,12 @@ * Profile Helper now only shows up if you have anything to fix; otherwise the profile helper can be found in the Settings menu ## 1.25.0 +* Added option for switching browsers (Credit: [@greyhoof](https://github.com/greyhoof)) * Fixed broken adblocker * Fixed incorrect BBCode rendering of `[collapse=[hr]test[hr]]` (Credit: [@Abeehiltz](https://github.com/Abeehiltz)) -* Added option for switching browsers (Credit: [@greyhoof](https://github.com/greyhoof)) * Switched `node-sass` to `sass` for ARM64 compatibility (Credit: [@WhiteHusky](https://github.com/WhiteHusky)) + ## 1.24.2 * Hotfix to address connectivity issues diff --git a/chat/ChatView.vue b/chat/ChatView.vue index 7dcec56..b3ba665 100644 --- a/chat/ChatView.vue +++ b/chat/ChatView.vue @@ -2,8 +2,8 @@
- - {{ownCharacter.name}} + + {{ownCharacter.name}} {{l('chat.logout')}}
{{l('chat.status')}} diff --git a/chat/ads/ad-manager.ts b/chat/ads/ad-manager.ts index 423865b..06c9e23 100644 --- a/chat/ads/ad-manager.ts +++ b/chat/ads/ad-manager.ts @@ -90,7 +90,7 @@ export class AdManager { } private determineNextAdDelayMs(chanConv: Conversation.ChannelConversation): number { - const match = chanConv.channel.description.toLowerCase().match(/\[\s*ads:\s*([0-9.]+)\s*(m|min|minutes?|h|hr|hours?|s|secs?|seconds?)\s*]/); + const match = chanConv.channel.description.toLowerCase().match(/\[\s*ads:\s*([0-9.]+)\s*(m|mins?|minutes?|h|hrs?|hours?|s|secs?|seconds?)\.?\s*]/); if (!match) { return AdManager.POST_DELAY; @@ -105,7 +105,7 @@ export class AdManager { mul = 60 * 1000; // minutes } - return Math.max((n * mul) - (Date.now() - chanConv.nextAd), AdManager.POST_DELAY); + return Math.max((n * mul) - Math.max(Date.now() - chanConv.nextAd, 0), AdManager.POST_DELAY); } private async sendNextPost(): Promise { diff --git a/chat/preview/ImagePreview.vue b/chat/preview/ImagePreview.vue index 642d373..f53f63c 100644 --- a/chat/preview/ImagePreview.vue +++ b/chat/preview/ImagePreview.vue @@ -560,6 +560,8 @@ async executeJavaScript(js: string | undefined, context: string = 'unknown', logDetails?: any): Promise { + console.log('EXECUTE JS', js); + if (!this.runJs) return; const webview = this.getWebview(); diff --git a/chat/preview/assets/browser.processor.raw.js b/chat/preview/assets/browser.processor.raw.js index 0ea5aff..d939e32 100644 --- a/chat/preview/assets/browser.processor.raw.js +++ b/chat/preview/assets/browser.processor.raw.js @@ -80,7 +80,7 @@ class FListImagePreviewDomMutator { const img = selected.filter(el => (el !== body)).shift(); - this.debug('detectImage.found', !!img, img); + this.debug('detectImage.found', !!img, img, body); return img; } diff --git a/chat/preview/helper/external.ts b/chat/preview/helper/external.ts index 065ac1c..cada32f 100644 --- a/chat/preview/helper/external.ts +++ b/chat/preview/helper/external.ts @@ -110,10 +110,11 @@ export class ExternalImagePreviewHelper extends ImagePreviewHelper { this.ratio = null; webview.stop(); + webview.setAudioMuted(true); // Broken promise chain on purpose // tslint:disable-next-line:no-floating-promises - this.urlMutator.resolve(url) + void this.urlMutator.resolve(url) .then( async(finalUrl: string) => { if (this.debug) @@ -121,7 +122,9 @@ export class ExternalImagePreviewHelper extends ImagePreviewHelper { webview.stop(); - return webview.loadURL(finalUrl); + await webview.loadURL(finalUrl); + + webview.setAudioMuted(true); } ) .catch( diff --git a/chat/preview/image-dom-mutator.ts b/chat/preview/image-dom-mutator.ts index b3f0a5a..2a3e87b 100644 --- a/chat/preview/image-dom-mutator.ts +++ b/chat/preview/image-dom-mutator.ts @@ -181,6 +181,11 @@ export class ImageDomMutator { this.getBaseJsMutatorScript([/*'#__flistCore', '#player', */ '#photoImageSection img', 'video', 'img', '#player'], false) ); + this.add( + 'tiktokstalk.com', + this.getBaseJsMutatorScript(['video'], false, [], true, true) + ); + this.add( 'gifmixxx.com', diff --git a/chat/preview/image-url-mutator.ts b/chat/preview/image-url-mutator.ts index 2ab0ab3..63a6f7e 100644 --- a/chat/preview/image-url-mutator.ts +++ b/chat/preview/image-url-mutator.ts @@ -33,6 +33,23 @@ export class ImageUrlMutator { } protected init(): void { + this.add( + /^https?:\/\/(www\.)?tiktok\.com\//, + async(url: string, _match: RegExpMatchArray): Promise => { + const result = await Axios.get( + `https://www.tiktok.com/oembed?url=${encodeURIComponent(url)}`, + { + responseType: 'json' + } + ); + + const userId = result.data.author_unique_id; + const videoId = result.data.embed_product_id; + + return `https://www.tiktokstalk.com/user/${userId}/${videoId}/`; + } + ); + this.add( /^http(?:s?):\/\/(?:www\.)?youtu(?:be\.com\/watch\?v=|\.be\/)([\w\-\_]*)(&(amp;)?[\w\?=]*)?/, async(_url: string, match: RegExpMatchArray): Promise => { @@ -40,6 +57,7 @@ export class ImageUrlMutator { return `https://yewtu.be/embed/${videoId}?autoplay=1` } ); + this.add( /^https?:\/\/.*twitter.com\/(.*)/, async(url: string, match: RegExpMatchArray): Promise => { diff --git a/electron/filesystem.ts b/electron/filesystem.ts index 9a21384..1da7247 100644 --- a/electron/filesystem.ts +++ b/electron/filesystem.ts @@ -303,6 +303,11 @@ export class SettingsStore implements Settings.Store { async get(key: K, character?: string): Promise { try { const file = path.join(getSettingsDir(character), key); + + if (!fs.existsSync(file)) { + return undefined; + } + return JSON.parse(fs.readFileSync(file, 'utf8')); } catch(e) { console.error('READ KEY FAILURE', e, key, character);