From abbcc6fcbf474e444bdc23e9dd4c5de3350a1325 Mon Sep 17 00:00:00 2001 From: "Mr. Stallion" Date: Sat, 11 Sep 2021 15:43:33 -0500 Subject: [PATCH] Fix missing ad buttons --- CHANGELOG.md | 3 + README.md | 6 +- chat/preview/CharacterPreview.vue | 17 ++-- chat/preview/ImagePreview.vue | 1 + chat/preview/integration/pornhub.ts | 13 --- docs/_config.yml | 2 +- docs/macos-install.md | 5 +- electron/Index.vue | 1 - electron/Window.vue | 3 +- electron/blocker/blocker.ts | 118 ++++++++++++++++++++++++++++ electron/chat.ts | 5 +- electron/language.ts | 11 ++- electron/main.ts | 99 +---------------------- electron/package.json | 2 +- learn/dictionary/WordDefinition.vue | 1 + package.json | 2 +- site/utils.ts | 6 +- 17 files changed, 163 insertions(+), 132 deletions(-) delete mode 100644 chat/preview/integration/pornhub.ts create mode 100644 electron/blocker/blocker.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index db64346..6213bf4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## 1.15.1 +* Fixed missing ad buttons + ## 1.15.0 * Upgraded to Electron 13.x * Fixed cache bugs that slowed down the client diff --git a/README.md b/README.md index 59ea25c..e003699 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Download -[Windows](https://github.com/mrstallion/fchat-rising/releases/download/v1.15.0/F-Chat-Rising-1.15.0-win.exe) (75 MB) -| [MacOS](https://github.com/mrstallion/fchat-rising/releases/download/v1.15.0/F-Chat-Rising-1.15.0-macos.dmg) (76 MB) -| [Linux](https://github.com/mrstallion/fchat-rising/releases/download/v1.15.0/F-Chat-Rising-1.15.0-linux.AppImage) (76 MB) +[Windows](https://github.com/mrstallion/fchat-rising/releases/download/v1.15.1/F-Chat-Rising-1.15.1-win.exe) (75 MB) +| [MacOS](https://github.com/mrstallion/fchat-rising/releases/download/v1.15.1/F-Chat-Rising-1.15.1-macos.dmg) (76 MB) +| [Linux](https://github.com/mrstallion/fchat-rising/releases/download/v1.15.1/F-Chat-Rising-1.15.1-linux.AppImage) (76 MB) # F-Chat Rising diff --git a/chat/preview/CharacterPreview.vue b/chat/preview/CharacterPreview.vue index 1d23ef4..9b18322 100644 --- a/chat/preview/CharacterPreview.vue +++ b/chat/preview/CharacterPreview.vue @@ -117,7 +117,7 @@ export default class CharacterPreview extends Vue { @Hook('mounted') mounted(): void { // tslint:disable-next-line no-unsafe-any no-any - this.scoreWatcher = async(event: {character: Character, score: number}): Promise => { + this.scoreWatcher = (event: {character: Character, score: number}): void => { // console.log('scoreWatcher', event); if ( @@ -125,7 +125,7 @@ export default class CharacterPreview extends Vue { && (this.characterName) && (event.character.name === this.characterName) ) { - await this.load(this.characterName, true); + this.load(this.characterName, true); } }; @@ -149,7 +149,7 @@ export default class CharacterPreview extends Vue { } - async load(characterName: string, force: boolean = false): Promise { + load(characterName: string, force: boolean = false): void { if ( (this.characterName === characterName) && (!force) @@ -173,14 +173,15 @@ export default class CharacterPreview extends Vue { this.updateOnlineStatus(); this.updateAdStatus(); - this.character = await this.getCharacterData(characterName); - this.match = Matcher.identifyBestMatchReport(this.ownCharacter.character, this.character.character); + setTimeout(async () => { + this.character = await this.getCharacterData(characterName); + this.match = Matcher.identifyBestMatchReport(this.ownCharacter!.character, this.character!.character); - this.updateCustoms(); - this.updateDetails(); + this.updateCustoms(); + this.updateDetails(); + }, 0); } - updateOnlineStatus(): void { this.onlineCharacter = core.characters.get(this.characterName!); diff --git a/chat/preview/ImagePreview.vue b/chat/preview/ImagePreview.vue index 386f3f9..5f78229 100644 --- a/chat/preview/ImagePreview.vue +++ b/chat/preview/ImagePreview.vue @@ -17,6 +17,7 @@ enableremotemodule="false" allowpopups="false" nodeIntegration="false" + partition="persist:adblocked" id="image-preview-ext" ref="imagePreviewExt" diff --git a/chat/preview/integration/pornhub.ts b/chat/preview/integration/pornhub.ts deleted file mode 100644 index 6230d6c..0000000 --- a/chat/preview/integration/pornhub.ts +++ /dev/null @@ -1,13 +0,0 @@ - -// tslint:disable-next-line -export class PornhubIntegration { - - static preprocess(): string { - return ``; - } - - - static postprocess(): string { - return ``; - } -} diff --git a/docs/_config.yml b/docs/_config.yml index fe58e4b..5742837 100644 --- a/docs/_config.yml +++ b/docs/_config.yml @@ -50,7 +50,7 @@ theme: jekyll-theme-slate changelog: https://github.com/mrstallion/fchat-rising/blob/master/CHANGELOG.md download: - version: 1.15.0 + version: 1.15.1 url: https://github.com/mrstallion/fchat-rising/releases/download/v%VERSION%/F-Chat-Rising-%VERSION%-%PLATFORM_TAIL% diff --git a/docs/macos-install.md b/docs/macos-install.md index 350b5f7..4bf62c6 100644 --- a/docs/macos-install.md +++ b/docs/macos-install.md @@ -14,7 +14,10 @@ layout: rising > Consider these alternatives to increase your safety: > > 1) Compile F-Chat Rising yourself from the [source](https://github.com/mrstallion/fchat-rising); or -> 2) Donate a code signing certificate so we can sign the client. +> +> 2) Run F-Chat Rising in a [virtual machine](https://www.parallels.com/); or +> +> 3) Donate a code signing certificate, so we can sign the client. > > F-Chat Rising is not malware. > No reason not to trust what the internet says, _right?_ diff --git a/electron/Index.vue b/electron/Index.vue index bc917e3..e6720dd 100644 --- a/electron/Index.vue +++ b/electron/Index.vue @@ -166,7 +166,6 @@ } ); - log.info('init.chat.keytar.load.start'); /* tslint:disable: no-any no-unsafe-any */ //because this is hacky diff --git a/electron/Window.vue b/electron/Window.vue index 0456a86..3f167e5 100644 --- a/electron/Window.vue +++ b/electron/Window.vue @@ -301,7 +301,8 @@ nodeIntegrationInWorker: true, spellcheck: true, enableRemoteModule: true, - contextIsolation: false + contextIsolation: false, + partition: 'persist:fchat' } } ); diff --git a/electron/blocker/blocker.ts b/electron/blocker/blocker.ts new file mode 100644 index 0000000..f5cdd68 --- /dev/null +++ b/electron/blocker/blocker.ts @@ -0,0 +1,118 @@ +import log from 'electron-log'; +import { ElectronBlocker } from '@cliqz/adblocker-electron'; +import fetch from 'node-fetch'; +import path from 'path'; +import fs from 'fs'; +import * as _ from 'lodash'; +import * as electron from 'electron'; + +export class BlockerIntegration { + protected static readonly adBlockerLists = [ + 'https://easylist.to/easylist/easylist.txt', + 'https://easylist.to/easylist/easyprivacy.txt', // EasyPrivacy + 'https://easylist-downloads.adblockplus.org/easylist-cookie.txt', // Easy Cookies + 'https://easylist.to/easylist/fanboy-social.txt', // Fanboy Social + 'https://easylist.to/easylist/fanboy-annoyance.txt', // Fanboy Annoyances + 'https://filters.adtidy.org/extension/chromium/filters/2.txt', // AdGuard Base + 'https://filters.adtidy.org/extension/chromium/filters/11.txt', // AdGuard Mobile Ads + 'https://filters.adtidy.org/extension/chromium/filters/4.txt', // AdGuard Social Media + 'https://filters.adtidy.org/extension/chromium/filters/14.txt', // AdGuard Annoyances + 'https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/annoyances.txt', // uBlock Origin Annoyances + 'https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/filters.txt', // uBlock Origin Filters + 'https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/privacy.txt', // uBlock Origin Privacy + 'https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/badware.txt', // uBlock Origin Badware + 'https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/resource-abuse.txt', // uBlock Origin Resource Abuse + 'https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/unbreak.txt' // uBlock Origin Unbreak + ]; + + // tslint:disable-next-line:max-line-length + constructor(protected readonly baseDir: string, protected readonly blocker?: ElectronBlocker, protected readonly session?: electron.Session) { + // nothing yet + } + + static async factory(baseDir: string): Promise { + log.debug('adblock.init'); + + try { + const blocker = await ElectronBlocker.fromLists( + fetch, + BlockerIntegration.adBlockerLists, + { + enableCompression: true + }, + { + path: path.join(baseDir, 'adblocker.bin'), + read: fs.promises.readFile, + write: fs.promises.writeFile + } + ); + + log.debug('adblock.load.complete'); + + BlockerIntegration.configureBlocker(blocker); + + log.debug('adblock.session.create'); + + const session = electron.session.fromPartition('persist:adblocked', { cache: true }); + + log.debug('adblock.session.attach'); + blocker.enableBlockingInSession(session); + + return new BlockerIntegration(baseDir, blocker, session); + } catch (err) { + log.warn('adblock.init.error', 'Adblocker failed to initialize.' + + 'This does not break F-Chat Rising, but may produce slower image previews', err); + + return new BlockerIntegration(baseDir); + } + } + + protected static configureBlocker(blocker: ElectronBlocker): void { + // 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'); + const preloadScript = path.join(electron.app.getAppPath(), './preview/assets/adblocker/preload.cjs.js'); + + // const originPath = require.resolve('@cliqz/adblocker-electron-preload'); + // const preloadScript = path.resolve(path.dirname(originPath), 'preload.cjs.js'); + log.debug('adblock.preload.path', { finalPath: preloadScript /*, originPath */ }); + + electron.session.defaultSession.setPreloads( + _.concat( + _.filter( + electron.session.defaultSession.getPreloads(), + (p) => (p.indexOf('adblocker-electron-preload') < 0) + ), + [preloadScript] + ) + ); + + blocker.blockFonts(); + + log.debug('adblock.preloaders', { loaders: electron.session.defaultSession.getPreloads() }); + + blocker.on('request-blocked', (request: Request) => { + log.debug('adblock.request.blocked', { url: request.url }); + }); + + blocker.on('request-redirected', (request: Request) => { + log.debug('adblock.request.redirected', { url: request.url }); + }); + + blocker.on('request-whitelisted', (request: Request) => { + log.debug('adblock.request.whitelisted', { url: request.url }); + }); + + blocker.on('csp-injected', (request: Request) => { + log.debug('adblock.inject.csp', { url: request.url }); + }); + + blocker.on('script-injected', (script: string, url: string) => { + log.debug('adblock.inject.script', { length: script.length, url }); + }); + + blocker.on('style-injected', (style: string, url: string) => { + log.debug('adblock.inject.style', { length: style.length, url }); + }); + } +} diff --git a/electron/chat.ts b/electron/chat.ts index c9e3aa6..c86af3c 100644 --- a/electron/chat.ts +++ b/electron/chat.ts @@ -203,7 +203,10 @@ webContents.on('context-menu', (_, props) => { if(menuTemplate.length > 0) remote.Menu.buildFromTemplate(menuTemplate).popup({}); - log.debug('context.text', { linkText: props.linkText, misspelledWord: props.misspelledWord, selectionText: props.selectionText, titleText: props.titleText }); + log.debug( + 'context.text', + { linkText: props.linkText, misspelledWord: props.misspelledWord, selectionText: props.selectionText, titleText: props.titleText } + ); }); let dictDir = path.join(remote.app.getPath('userData'), 'spellchecker'); diff --git a/electron/language.ts b/electron/language.ts index 191bf5f..5ad9743 100644 --- a/electron/language.ts +++ b/electron/language.ts @@ -32,12 +32,14 @@ export const knownLanguageNames = { cs: 'Czech', cy: 'Welsh', da: 'Danish', - de: 'German', + de: 'German, Generic', + 'de-DE': 'German', el: 'Greek', 'en-AU': 'English, Australian', 'en-CA': 'English, Canadian', 'en-GB': 'English, British', + 'en-GB-oxendict': 'English, British, Oxford Spelling', 'en-US': 'English, American', es: 'Spanish', @@ -50,14 +52,16 @@ export const knownLanguageNames = { et: 'Estonian', fa: 'Persian', fo: 'Faroese', - fr: 'French', + fr: 'French, Generic', + 'fr-FR': 'French', he: 'Hebrew', hi: 'Hindi', hr: 'Croatian', hu: 'Hungarian', hy: 'Armenian', id: 'Indonesian', - it: 'Italian', + it: 'Italian, Generic', + 'it-IT': 'Italian', ko: 'Korean', lt: 'Lithuanian', lv: 'Latvian', @@ -67,6 +71,7 @@ export const knownLanguageNames = { 'pt-BR': 'Portuguese, Brazilian', 'pt-PT': 'Portuguese, European', + pt: 'Portuguese, Generic', ro: 'Romanian', ru: 'Russian', diff --git a/electron/main.ts b/electron/main.ts index 084aaa1..82bb370 100644 --- a/electron/main.ts +++ b/electron/main.ts @@ -47,13 +47,12 @@ import { getSafeLanguages, knownLanguageNames, updateSupportedLanguages } from ' import * as windowState from './window_state'; // import BrowserWindow = electron.BrowserWindow; import MenuItem = electron.MenuItem; -import { ElectronBlocker } from '@cliqz/adblocker-electron'; -import fetch from 'node-fetch'; import MenuItemConstructorOptions = electron.MenuItemConstructorOptions; import * as _ from 'lodash'; import DownloadItem = electron.DownloadItem; import { AdCoordinatorHost } from '../chat/ads/ad-coordinator-host'; import { IpcMainEvent } from 'electron'; +import { BlockerIntegration } from './blocker/blocker'; //tslint:disable-next-line:no-require-imports const pck = require('./package.json'); @@ -191,7 +190,7 @@ function createWindow(): electron.BrowserWindow | undefined { ...lastState, center: lastState.x === undefined, show: false, webPreferences: { webviewTag: true, nodeIntegration: true, nodeIntegrationInWorker: true, spellcheck: true, - enableRemoteModule: true, contextIsolation: false + enableRemoteModule: true, contextIsolation: false, partition: 'persist:fchat' } as any }; @@ -213,98 +212,8 @@ function createWindow(): electron.BrowserWindow | undefined { electron.session.defaultSession.setSpellCheckerLanguages(safeLanguages); window.webContents.session.setSpellCheckerLanguages(safeLanguages); - log.debug('adblock.init'); - - // tslint:disable-next-line:no-floating-promises - ElectronBlocker.fromLists( - fetch, - [ - 'https://easylist.to/easylist/easylist.txt', - 'https://easylist.to/easylist/easyprivacy.txt', // EasyPrivacy - 'https://easylist-downloads.adblockplus.org/easylist-cookie.txt', // Easy Cookies - 'https://easylist.to/easylist/fanboy-social.txt', // Fanboy Social - 'https://easylist.to/easylist/fanboy-annoyance.txt', // Fanboy Annoyances - 'https://filters.adtidy.org/extension/chromium/filters/2.txt', // AdGuard Base - 'https://filters.adtidy.org/extension/chromium/filters/11.txt', // AdGuard Mobile Ads - 'https://filters.adtidy.org/extension/chromium/filters/4.txt', // AdGuard Social Media - 'https://filters.adtidy.org/extension/chromium/filters/14.txt', // AdGuard Annoyances - 'https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/annoyances.txt', // uBlock Origin Annoyances - 'https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/filters.txt', // uBlock Origin Filters - 'https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/privacy.txt', // uBlock Origin Privacy - 'https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/badware.txt', // uBlock Origin Badware - 'https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/resource-abuse.txt', // uBlock Origin Resource Abuse - 'https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/unbreak.txt' // uBlock Origin Unbreak - ], - { - enableCompression: true - }, - { - path: path.join(baseDir, 'adblocker.bin'), - read: fs.promises.readFile, - write: fs.promises.writeFile - } - ).then( - (blocker) => { - log.debug('adblock.load.complete'); - - 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'); - const preloadScript = path.join(electron.app.getAppPath(), './preview/assets/adblocker/preload.cjs.js'); - - // const originPath = require.resolve('@cliqz/adblocker-electron-preload'); - // const preloadScript = path.resolve(path.dirname(originPath), 'preload.cjs.js'); - log.debug('adblock.preload.path', { finalPath: preloadScript /*, originPath */ }); - - electron.session.defaultSession.setPreloads( - _.concat( - _.filter( - electron.session.defaultSession.getPreloads(), - (p) => (p.indexOf('adblocker-electron-preload') < 0) - ), - [preloadScript] - ) - ); - - log.debug('adblock.preloaders', { loaders: electron.session.defaultSession.getPreloads() }); - - blocker.on('request-blocked', (request: Request) => { - log.debug('adblock.request.blocked', { url: request.url }); - }); - - blocker.on('request-redirected', (request: Request) => { - log.debug('adblock.request.redirected', { url: request.url }); - }); - - blocker.on('request-whitelisted', (request: Request) => { - log.debug('adblock.request.whitelisted', { url: request.url }); - }); - - blocker.on('csp-injected', (request: Request) => { - log.debug('adblock.inject.csp', { url: request.url }); - }); - - blocker.on('script-injected', (script: string, url: string) => { - log.debug('adblock.inject.script', { length: script.length, url }); - }); - - blocker.on('style-injected', (style: string, url: string) => { - log.debug('adblock.inject.style', { length: style.length, url }); - }); - } - ).catch( - (err) => { - log.warn('adblock.init.error', 'Adblocker failed to initialize.' - + 'This does not break F-Chat Rising, but may produce slower image previews', err); - } - ); - + // Set up ad blocker + BlockerIntegration.factory(baseDir); // This prevents automatic download prompts on certain webview URLs without // stopping conversation logs from being downloaded diff --git a/electron/package.json b/electron/package.json index 64f3542..690535c 100644 --- a/electron/package.json +++ b/electron/package.json @@ -1,6 +1,6 @@ { "name": "fchat", - "version": "1.15.0", + "version": "1.15.1", "author": "The F-List Team and Mister Stallion (Esq.)", "description": "F-List.net Chat Client", "main": "main.js", diff --git a/learn/dictionary/WordDefinition.vue b/learn/dictionary/WordDefinition.vue index b9d3686..637c55a 100644 --- a/learn/dictionary/WordDefinition.vue +++ b/learn/dictionary/WordDefinition.vue @@ -6,6 +6,7 @@ enableremotemodule="false" allowpopups="false" nodeIntegration="false" + partition="persist:adblocked" id="defintion-preview" ref="definitionPreview" diff --git a/package.json b/package.json index 8568210..2311d4c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "f-list-rising", - "version": "1.15.0", + "version": "1.15.1", "author": "The F-List Team and and Mister Stallion (Esq.)", "description": "A heavily modded F-Chat 3.0 client for F-List", "license": "MIT", diff --git a/site/utils.ts b/site/utils.ts index 8d1183e..bf4d313 100644 --- a/site/utils.ts +++ b/site/utils.ts @@ -1,4 +1,4 @@ -import Axios, {AxiosError, AxiosResponse} from 'axios'; +import axios, {AxiosError, AxiosResponse} from 'axios'; import {InlineDisplayMode, Settings, SimpleCharacter} from '../interfaces'; type FlashMessageType = 'info' | 'success' | 'warning' | 'danger'; @@ -32,7 +32,7 @@ export function isJSONError(error: any): error is Error & {response: AxiosRespon export function ajaxError(error: any, prefix: string, showFlashMessage: boolean = true): void { //tslint:disable-line:no-any let message: string | undefined; if(error instanceof Error) { - if(Axios.isCancel(error)) return; + if(axios.isCancel(error)) return; if(isJSONError(error)) { const data = <{error?: string | string[]}>error.response.data; @@ -81,4 +81,4 @@ export function setDomains(site: string, stat: string): void { export function init(s: Settings, c: SimpleCharacter[]): void { settings = s; characters = c; -} \ No newline at end of file +}