Fix missing ad buttons

This commit is contained in:
Mr. Stallion 2021-09-11 15:43:33 -05:00
parent 350aed373b
commit abbcc6fcbf
17 changed files with 163 additions and 132 deletions

View File

@ -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

View File

@ -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

View File

@ -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<void> => {
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<void> {
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!);

View File

@ -17,6 +17,7 @@
enableremotemodule="false"
allowpopups="false"
nodeIntegration="false"
partition="persist:adblocked"
id="image-preview-ext"
ref="imagePreviewExt"

View File

@ -1,13 +0,0 @@
// tslint:disable-next-line
export class PornhubIntegration {
static preprocess(): string {
return ``;
}
static postprocess(): string {
return ``;
}
}

View File

@ -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%

View File

@ -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?_

View File

@ -166,7 +166,6 @@
}
);
log.info('init.chat.keytar.load.start');
/* tslint:disable: no-any no-unsafe-any */ //because this is hacky

View File

@ -301,7 +301,8 @@
nodeIntegrationInWorker: true,
spellcheck: true,
enableRemoteModule: true,
contextIsolation: false
contextIsolation: false,
partition: 'persist:fchat'
}
}
);

118
electron/blocker/blocker.ts Normal file
View File

@ -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<BlockerIntegration> {
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 });
});
}
}

View File

@ -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');

View File

@ -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',

View File

@ -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

View File

@ -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",

View File

@ -6,6 +6,7 @@
enableremotemodule="false"
allowpopups="false"
nodeIntegration="false"
partition="persist:adblocked"
id="defintion-preview"
ref="definitionPreview"

View File

@ -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",

View File

@ -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;
}
}