client: remove some URL tracking parameters
Some checks failed
ci/woodpecker/push/lint-backend Pipeline failed
ci/woodpecker/push/lint-foundkey-js Pipeline was successful
ci/woodpecker/push/lint-sw Pipeline failed
ci/woodpecker/push/lint-client Pipeline failed
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/test Pipeline failed
Some checks failed
ci/woodpecker/push/lint-backend Pipeline failed
ci/woodpecker/push/lint-foundkey-js Pipeline was successful
ci/woodpecker/push/lint-sw Pipeline failed
ci/woodpecker/push/lint-client Pipeline failed
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/test Pipeline failed
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:
parent
0bcbb38ecc
commit
a6c5e9f358
3 changed files with 32 additions and 6 deletions
|
@ -1,6 +1,6 @@
|
||||||
<template>
|
<template>
|
||||||
<component
|
<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="() => {}"
|
@contextmenu.stop="() => {}"
|
||||||
>
|
>
|
||||||
<template v-if="!self">
|
<template v-if="!self">
|
||||||
|
@ -21,6 +21,7 @@
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { defineAsyncComponent } from 'vue';
|
import { defineAsyncComponent } from 'vue';
|
||||||
import { toUnicode as decodePunycode } from 'punycode/';
|
import { toUnicode as decodePunycode } from 'punycode/';
|
||||||
|
import { removeTracking } from '@/filters/url';
|
||||||
import { url as local } from '@/config';
|
import { url as local } from '@/config';
|
||||||
import * as os from '@/os';
|
import * as os from '@/os';
|
||||||
import { useTooltip } from '@/scripts/use-tooltip';
|
import { useTooltip } from '@/scripts/use-tooltip';
|
||||||
|
@ -34,7 +35,7 @@ const props = withDefaults(defineProps<{
|
||||||
});
|
});
|
||||||
|
|
||||||
const self = props.url.startsWith(local);
|
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');
|
if (!['http:', 'https:'].includes(uri.protocol)) throw new Error('invalid url');
|
||||||
let el: HTMLElement | null = $ref(null);
|
let el: HTMLElement | null = $ref(null);
|
||||||
|
|
||||||
|
@ -50,7 +51,7 @@ let target = $ref(self ? null : '_blank');
|
||||||
useTooltip($$(el), (showing) => {
|
useTooltip($$(el), (showing) => {
|
||||||
os.popup(defineAsyncComponent(() => import('@/components/url-preview-popup.vue')), {
|
os.popup(defineAsyncComponent(() => import('@/components/url-preview-popup.vue')), {
|
||||||
showing,
|
showing,
|
||||||
url: props.url,
|
url: uri.href,
|
||||||
source: el,
|
source: el,
|
||||||
}, {}, 'closed');
|
}, {}, 'closed');
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<template>
|
<template>
|
||||||
<component
|
<component
|
||||||
:is="self ? 'MkA' : 'a'" ref="el" class="xlcxczvw _link" :[attr]="self ? url.substr(local.length) : url" :rel="rel" :target="target"
|
:is="self ? 'MkA' : 'a'" ref="el" class="xlcxczvw _link" :[attr]="self ? url.substr(local.length) : cleanUrl" :rel="rel" :target="target"
|
||||||
:title="url"
|
:title="cleanUrl"
|
||||||
>
|
>
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
<i v-if="target === '_blank'" class="fas fa-external-link-square-alt icon"></i>
|
<i v-if="target === '_blank'" class="fas fa-external-link-square-alt icon"></i>
|
||||||
|
@ -11,6 +11,7 @@
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { defineAsyncComponent } from 'vue';
|
import { defineAsyncComponent } from 'vue';
|
||||||
import { url as local } from '@/config';
|
import { url as local } from '@/config';
|
||||||
|
import { removeTracking } from '@/filters/url';
|
||||||
import { useTooltip } from '@/scripts/use-tooltip';
|
import { useTooltip } from '@/scripts/use-tooltip';
|
||||||
import * as os from '@/os';
|
import * as os from '@/os';
|
||||||
|
|
||||||
|
@ -23,13 +24,14 @@ const props = withDefaults(defineProps<{
|
||||||
const self = props.url.startsWith(local);
|
const self = props.url.startsWith(local);
|
||||||
const attr = self ? 'to' : 'href';
|
const attr = self ? 'to' : 'href';
|
||||||
const target = self ? null : '_blank';
|
const target = self ? null : '_blank';
|
||||||
|
const cleanUrl = self ? props.url : removeTracking(props.url);
|
||||||
|
|
||||||
const el = $ref();
|
const el = $ref();
|
||||||
|
|
||||||
useTooltip($$(el), (showing) => {
|
useTooltip($$(el), (showing) => {
|
||||||
os.popup(defineAsyncComponent(() => import('@/components/url-preview-popup.vue')), {
|
os.popup(defineAsyncComponent(() => import('@/components/url-preview-popup.vue')), {
|
||||||
showing,
|
showing,
|
||||||
url: props.url,
|
url: cleanUrl,
|
||||||
source: el,
|
source: el,
|
||||||
}, {}, 'closed');
|
}, {}, 'closed');
|
||||||
});
|
});
|
||||||
|
|
23
packages/client/src/filters/url.ts
Normal file
23
packages/client/src/filters/url.ts
Normal 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;
|
||||||
|
}
|
Loading…
Reference in a new issue