mirror of
https://gitlab.com/PronounsPage/PronounsPage.git
synced 2025-08-05 03:57:03 -04:00
61 lines
1.6 KiB
Vue
61 lines
1.6 KiB
Vue
<template>
|
|
<span>
|
|
<!-- eslint-disable-next-line -->
|
|
<span v-show="!$isGranted('users') && !$isGranted('community') || !hasSus" ref="original">
|
|
<slot ref="original"></slot>
|
|
</span>
|
|
<span v-show="($isGranted('users') || $isGranted('community')) && hasSus" ref="marked"></span>
|
|
</span>
|
|
</template>
|
|
|
|
<script>
|
|
export default {
|
|
emits: ['hasSus'],
|
|
data() {
|
|
return {
|
|
moderation: null,
|
|
hasSus: false,
|
|
};
|
|
},
|
|
async mounted() {
|
|
if (!this.$isGranted('users') && !this.$isGranted('community')) {
|
|
return;
|
|
}
|
|
this.moderation = await $fetch('/api/admin/moderation');
|
|
|
|
this.update();
|
|
|
|
const observer = new MutationObserver(this.update);
|
|
observer.observe(this.$refs.original, {
|
|
childList: true,
|
|
subtree: true,
|
|
});
|
|
this.observer = observer;
|
|
},
|
|
beforeUnmount() {
|
|
this.observer.disconnect();
|
|
},
|
|
methods: {
|
|
update() {
|
|
if (!this.moderation) {
|
|
return;
|
|
}
|
|
|
|
let html = this.$refs.original.innerHTML;
|
|
for (const sus of this.moderation.susRegexes) {
|
|
html = html.replace(new RegExp(sus, 'gi'), (m) => {
|
|
if (m === 'map') {
|
|
// most probably an icon, skip
|
|
return m;
|
|
}
|
|
this.hasSus = true;
|
|
this.$emit('hasSus');
|
|
return `<mark>${m}</mark>`;
|
|
});
|
|
}
|
|
this.$refs.marked.innerHTML = html;
|
|
},
|
|
},
|
|
};
|
|
</script>
|