client: remove some URL tracking parameters
ci/woodpecker/push/lint-backend Pipeline failed Details
ci/woodpecker/push/lint-foundkey-js Pipeline was successful Details
ci/woodpecker/push/lint-sw Pipeline failed Details
ci/woodpecker/push/lint-client Pipeline failed Details
ci/woodpecker/push/build Pipeline was successful Details
ci/woodpecker/push/test Pipeline failed Details

This removes some tracking parameters from URLs that are
rendered as MFM. There are probably many more parameters
to be filtered.

Changelog: Added
This commit is contained in:
Johann150 2023-10-05 20:11:09 +02:00
parent 0bcbb38ecc
commit a6c5e9f358
Signed by: Johann150
GPG Key ID: 9EE6577A2A06F8F1
3 changed files with 32 additions and 6 deletions

View File

@ -1,6 +1,6 @@
<template>
<component
:is="self ? 'MkA' : 'a'" ref="el" class="ieqqeuvs _link" :[attr]="self ? url.slice(local.length) : url" :rel="rel" :target="target"
:is="self ? 'MkA' : 'a'" ref="el" class="ieqqeuvs _link" :[attr]="self ? url.slice(local.length) : uri.href" :rel="rel" :target="target"
@contextmenu.stop="() => {}"
>
<template v-if="!self">
@ -21,6 +21,7 @@
<script lang="ts" setup>
import { defineAsyncComponent } from 'vue';
import { toUnicode as decodePunycode } from 'punycode/';
import { removeTracking } from '@/filters/url';
import { url as local } from '@/config';
import * as os from '@/os';
import { useTooltip } from '@/scripts/use-tooltip';
@ -34,7 +35,7 @@ const props = withDefaults(defineProps<{
});
const self = props.url.startsWith(local);
const uri = new URL(props.url);
const uri = new URL(removeTracking(props.url));
if (!['http:', 'https:'].includes(uri.protocol)) throw new Error('invalid url');
let el: HTMLElement | null = $ref(null);
@ -50,7 +51,7 @@ let target = $ref(self ? null : '_blank');
useTooltip($$(el), (showing) => {
os.popup(defineAsyncComponent(() => import('@/components/url-preview-popup.vue')), {
showing,
url: props.url,
url: uri.href,
source: el,
}, {}, 'closed');
});

View File

@ -1,7 +1,7 @@
<template>
<component
:is="self ? 'MkA' : 'a'" ref="el" class="xlcxczvw _link" :[attr]="self ? url.substr(local.length) : url" :rel="rel" :target="target"
:title="url"
:is="self ? 'MkA' : 'a'" ref="el" class="xlcxczvw _link" :[attr]="self ? url.substr(local.length) : cleanUrl" :rel="rel" :target="target"
:title="cleanUrl"
>
<slot></slot>
<i v-if="target === '_blank'" class="fas fa-external-link-square-alt icon"></i>
@ -11,6 +11,7 @@
<script lang="ts" setup>
import { defineAsyncComponent } from 'vue';
import { url as local } from '@/config';
import { removeTracking } from '@/filters/url';
import { useTooltip } from '@/scripts/use-tooltip';
import * as os from '@/os';
@ -23,13 +24,14 @@ const props = withDefaults(defineProps<{
const self = props.url.startsWith(local);
const attr = self ? 'to' : 'href';
const target = self ? null : '_blank';
const cleanUrl = self ? props.url : removeTracking(props.url);
const el = $ref();
useTooltip($$(el), (showing) => {
os.popup(defineAsyncComponent(() => import('@/components/url-preview-popup.vue')), {
showing,
url: props.url,
url: cleanUrl,
source: el,
}, {}, 'closed');
});

View File

@ -0,0 +1,23 @@
export function removeTracking(url: string): string {
let parsed;
try {
parsed = new URL(url);
} catch {
// parsing the URL failed, can't clean this
return url;
}
if (['youtu.be', 'youtube.com', 'www.youtube.com'].includes(parsed.host)) {
parsed.searchParams.delete('si'); // source identifier
} else if (['heise.de', 'www.heise.de'].includes(parsed.host)) {
parsed.searchParams.delete('wt_mc');
} else {
parsed.searchParams.delete('utm_source');
parsed.searchParams.delete('utm_medium');
parsed.searchParams.delete('utm_campaign');
parsed.searchParams.delete('utm_term');
parsed.searchParams.delete('utm_content');
}
return parsed.href;
}