From 8ca9fc17d20b15645798ef1dc6bbec7f2c619d5e Mon Sep 17 00:00:00 2001 From: Florian Date: Wed, 6 Nov 2019 19:19:44 -0600 Subject: [PATCH 1/4] Remove Facebook tracking from copied links --- source/index.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/source/index.ts b/source/index.ts index eafc76ca0..7626df5ba 100644 --- a/source/index.ts +++ b/source/index.ts @@ -43,7 +43,27 @@ electronDebug({ }); electronDl(); -electronContextMenu(); +electronContextMenu({ + prepend: defaultActions => { + /* + * TODO: Use menu option or use replacement of options (https://github.com/sindresorhus/electron-context-menu/issues/70) + * This is a bit hacky, but we cannot import menuTemplate directly to populate the menu. + * If we use prepend and return a MenuItem, we will get a duplicate menu item. + * The cast below is because the type definition of Actions has no copyLink. + */ + (defaultActions as any).copyLink({ + transform: (content: any) => { + if (content.startsWith('https://l.messenger.com/l.php')) { + content = new URL(content).searchParams.get('u'); + } + + return content; + } + }); + + return []; + } +}); const domain = config.get('useWorkChat') ? 'facebook.com' : 'messenger.com'; From 244a3f8e22e729f022accc86ea8a6ae7ed887689 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sat, 9 Nov 2019 01:26:03 +0700 Subject: [PATCH 2/4] Update index.ts --- source/index.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/index.ts b/source/index.ts index 7626df5ba..627041444 100644 --- a/source/index.ts +++ b/source/index.ts @@ -46,11 +46,11 @@ electronDl(); electronContextMenu({ prepend: defaultActions => { /* - * TODO: Use menu option or use replacement of options (https://github.com/sindresorhus/electron-context-menu/issues/70) - * This is a bit hacky, but we cannot import menuTemplate directly to populate the menu. - * If we use prepend and return a MenuItem, we will get a duplicate menu item. - * The cast below is because the type definition of Actions has no copyLink. - */ + TODO: Use menu option or use replacement of options (https://github.com/sindresorhus/electron-context-menu/issues/70) + This is a bit hacky, but we cannot import menuTemplate directly to populate the menu. + If we use prepend and return a MenuItem, we will get a duplicate menu item. + The cast below is because the type definition of Actions has no copyLink. + */ (defaultActions as any).copyLink({ transform: (content: any) => { if (content.startsWith('https://l.messenger.com/l.php')) { From ceed63debda47b039d800e92d08fe84d8da4d88b Mon Sep 17 00:00:00 2001 From: Florian Date: Fri, 8 Nov 2019 15:34:23 -0600 Subject: [PATCH 3/4] Isolate cleaning function into util, use more specific type than any --- source/index.ts | 26 +++++--------------------- source/util.ts | 12 ++++++++++++ 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/source/index.ts b/source/index.ts index b2e40180f..cbf36373b 100644 --- a/source/index.ts +++ b/source/index.ts @@ -28,7 +28,7 @@ import doNotDisturb = require('@sindresorhus/do-not-disturb'); import updateAppMenu from './menu'; import config from './config'; import tray from './tray'; -import {sendAction, sendBackgroundAction} from './util'; +import {sendAction, sendBackgroundAction, domain, getUntrackedURL} from './util'; import {process as processEmojiUrl} from './emoji'; import ensureOnline from './ensure-online'; import './touch-bar'; // eslint-disable-line import/no-unassigned-import @@ -47,26 +47,16 @@ electronContextMenu({ prepend: defaultActions => { /* TODO: Use menu option or use replacement of options (https://github.com/sindresorhus/electron-context-menu/issues/70) - This is a bit hacky, but we cannot import menuTemplate directly to populate the menu. - If we use prepend and return a MenuItem, we will get a duplicate menu item. - The cast below is because the type definition of Actions has no copyLink. + See explanation for this hacky solution here: https://github.com/sindresorhus/caprine/pull/1169 */ - (defaultActions as any).copyLink({ - transform: (content: any) => { - if (content.startsWith('https://l.messenger.com/l.php')) { - content = new URL(content).searchParams.get('u'); - } - - return content; - } + defaultActions.copyLink({ + transform: getUntrackedURL }); return []; } }); -const domain = config.get('useWorkChat') ? 'facebook.com' : 'messenger.com'; - app.setAppUserModelId('com.sindresorhus.caprine'); if (!config.get('hardwareAcceleration')) { @@ -351,9 +341,6 @@ function createMainWindow(): BrowserWindow { (async () => { await Promise.all([ensureOnline(), app.whenReady()]); - - const trackingUrlPrefix = `https://l.${domain}/l.php`; - await updateAppMenu(); mainWindow = createMainWindow(); @@ -479,10 +466,7 @@ function createMainWindow(): BrowserWindow { (event as any).newGuest = new BrowserWindow(options); } } else { - if (url.startsWith(trackingUrlPrefix)) { - url = new URL(url).searchParams.get('u')!; - } - + url = getUntrackedURL(url); shell.openExternalSync(url); } }); diff --git a/source/util.ts b/source/util.ts index 6407a9561..70a8a8b33 100644 --- a/source/util.ts +++ b/source/util.ts @@ -1,5 +1,6 @@ import {app, BrowserWindow, dialog} from 'electron'; import {is} from 'electron-util'; +import config from './config'; export function getWindow(): BrowserWindow { const [win] = BrowserWindow.getAllWindows(); @@ -37,3 +38,14 @@ export function showRestartDialog(message: string): void { app.quit(); } } + +export const domain = config.get('useWorkChat') ? 'facebook.com' : 'messenger.com'; + +export function getUntrackedURL(url: string): string { + const trackingUrlPrefix = `https://l.${domain}/l.php`; + if (url.startsWith(trackingUrlPrefix)) { + url = new URL(url).searchParams.get('u')!; + } + + return url; +} From 0c5e5cd478f69c6522cb08701a3d008be024ed63 Mon Sep 17 00:00:00 2001 From: Florian Date: Mon, 11 Nov 2019 11:27:04 -0600 Subject: [PATCH 4/4] Renamed variables for tracking and domain --- source/index.ts | 16 ++++++++-------- source/util.ts | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/source/index.ts b/source/index.ts index cbf36373b..5802ed524 100644 --- a/source/index.ts +++ b/source/index.ts @@ -28,7 +28,7 @@ import doNotDisturb = require('@sindresorhus/do-not-disturb'); import updateAppMenu from './menu'; import config from './config'; import tray from './tray'; -import {sendAction, sendBackgroundAction, domain, getUntrackedURL} from './util'; +import {sendAction, sendBackgroundAction, messengerDomain, stripTrackingFromUrl} from './util'; import {process as processEmojiUrl} from './emoji'; import ensureOnline from './ensure-online'; import './touch-bar'; // eslint-disable-line import/no-unassigned-import @@ -50,7 +50,7 @@ electronContextMenu({ See explanation for this hacky solution here: https://github.com/sindresorhus/caprine/pull/1169 */ defaultActions.copyLink({ - transform: getUntrackedURL + transform: stripTrackingFromUrl }); return []; @@ -178,7 +178,7 @@ function enableHiresResources(): void { return; } - const filter = {urls: [`*://*.${domain}/`]}; + const filter = {urls: [`*://*.${messengerDomain}/`]}; session.defaultSession!.webRequest.onBeforeSendHeaders( filter, @@ -206,10 +206,10 @@ function enableHiresResources(): void { function initRequestsFiltering(): void { const filter = { urls: [ - `*://*.${domain}/*typ.php*`, // Type indicator blocker - `*://*.${domain}/*change_read_status.php*`, // Seen indicator blocker - `*://*.${domain}/*delivery_receipts*`, // Delivery receipts indicator blocker - `*://*.${domain}/*unread_threads*`, // Delivery receipts indicator blocker + `*://*.${messengerDomain}/*typ.php*`, // Type indicator blocker + `*://*.${messengerDomain}/*change_read_status.php*`, // Seen indicator blocker + `*://*.${messengerDomain}/*delivery_receipts*`, // Delivery receipts indicator blocker + `*://*.${messengerDomain}/*unread_threads*`, // Delivery receipts indicator blocker '*://*.fbcdn.net/images/emoji.php/v9/*', // Emoji '*://*.facebook.com/images/emoji.php/v9/*' // Emoji ] @@ -466,7 +466,7 @@ function createMainWindow(): BrowserWindow { (event as any).newGuest = new BrowserWindow(options); } } else { - url = getUntrackedURL(url); + url = stripTrackingFromUrl(url); shell.openExternalSync(url); } }); diff --git a/source/util.ts b/source/util.ts index 70a8a8b33..13cc31eba 100644 --- a/source/util.ts +++ b/source/util.ts @@ -39,10 +39,10 @@ export function showRestartDialog(message: string): void { } } -export const domain = config.get('useWorkChat') ? 'facebook.com' : 'messenger.com'; +export const messengerDomain = config.get('useWorkChat') ? 'facebook.com' : 'messenger.com'; -export function getUntrackedURL(url: string): string { - const trackingUrlPrefix = `https://l.${domain}/l.php`; +export function stripTrackingFromUrl(url: string): string { + const trackingUrlPrefix = `https://l.${messengerDomain}/l.php`; if (url.startsWith(trackingUrlPrefix)) { url = new URL(url).searchParams.get('u')!; }