feat: add media bias fact check support

This commit is contained in:
Xylight committed 2024-07-16 12:53:05 -07:00
1 parent b97ebffc08
commit d2748faacf
9 files changed
+249 -14

No files matched your search

+1 -1
View File
@@ -154,7 +154,7 @@
<PostBody body={post.post.body} {view} style="grid-area: body" />
{/if}
{#if actions}
<PostActions on:hide bind:post style="grid-area: actions;" />
<PostActions on:hide bind:post {type} style="grid-area: actions;" />
{:else if view == 'compact'}
<div class="flex flex-row items-center gap-2 text-sm">
<Badge>
@@ -9,6 +9,7 @@
BugAnt,
ChatBubbleOvalLeft,
ChatBubbleOvalLeftEllipsis,
CheckBadge,
EllipsisHorizontal,
Eye,
EyeSlash,
@@ -19,6 +20,7 @@
Language,
Newspaper,
PencilSquare,
Scale,
ServerStack,
Share,
Trash,
@@ -57,18 +59,19 @@
import { t } from '$lib/translations'
import { text } from '$lib/components/translate/translation'
import Translation from '$lib/components/translate/Translation.svelte'
import { hidePost, postLink } from './helpers'
import { hidePost, postLink, type MediaType } from './helpers'
import { feature } from '$lib/version'
import Switch from '$lib/components/input/Switch.svelte'
import { instanceToURL } from '$lib/util'
export let post: PostView
export let type: MediaType | undefined = undefined
export let debug: boolean = false
const dispatcher = createEventDispatcher<{ edit: PostView; hide: boolean }>()
let editing = false
let saving = false
export let debug: boolean = false
let fediseerOpen = false
let fediseerData: Data | null = null
@@ -77,6 +80,11 @@
let translating = false
let localShare = false
let mediaBias = false
const stripSubdomain = (url: string) =>
new URL(url).hostname.split('.').slice(-2).join('.')
</script>
{#if fediseerData}
@@ -110,7 +118,15 @@
{/if}
{#if translating}
<Translation bind:open={translating} />
{#await import('$lib/components/translate/Translation.svelte') then { default: Translation }}
<Translation bind:open={translating} />
{/await}
{/if}
{#if mediaBias && post.post.url}
{#await import('$lib/components/mbfc/MBFCModal.svelte') then { default: MbfcModal }}
<MbfcModal domain={stripSubdomain(post.post.url)} bind:open={mediaBias} />
{/await}
{/if}
<div
@@ -179,6 +195,16 @@
</Button>
{/if}
{#if post.post.url && type == 'embed'}
<Button
size="square-md"
color="ghost"
on:click={() => (mediaBias = !mediaBias)}
title={$t('post.actions.more.mediaBias')}
>
<Icon src={CheckBadge} micro size="16" />
</Button>
{/if}
<Menu
placement="bottom-end"
containerClass="overflow-auto max-h-[400px]"
@@ -217,7 +243,7 @@
fediseerLoading = true
const data = await fediseer.getInstanceInfo(
new URL(post.community.actor_id).hostname
new URL(post.community.actor_id).hostname,
)
fediseerData = data
fediseerOpen = true
@@ -266,7 +292,7 @@
navigator.clipboard.writeText(
localShare
? `${instanceToURL(getInstance())}/post/${post.post.id}`
: post.post.ap_id
: post.post.ap_id,
)
toast({ content: $t('toast.copied') })
}}
@@ -333,7 +359,7 @@
post.post.deleted = await deleteItem(
post,
!post.post.deleted,
$profile.jwt
$profile.jwt,
)
}}
color="danger-subtle"
@@ -352,7 +378,7 @@
const hidden = await hidePost(
post.post.id,
!post.hidden,
$profile?.jwt
$profile?.jwt,
)
post.hidden = hidden
if (hidden) {
@@ -67,17 +67,19 @@
<Button
href={url}
target="_blank"
class="text-slate-700 dark:text-zinc-300 inline-flex items-center gap-1 text-xs overflow-hidden w-max max-w-full"
class="text-slate-900 dark:text-zinc-300 inline-flex items-center gap-1 text-xs overflow-hidden w-max max-w-full"
size="sm"
color="ghost"
rounding="pill"
>
<Icon src={LinkIcon} size="14" mini slot="prefix" class="flex-shrink-0" />
{#if richURL}
<div class="flex max-w-full overflow-hidden">
<div class="flex max-w-full overflow-hidden font-medium">
{richURL.hostname}
{#if richURL.pathname != '/'}
<span class="text-slate-500 dark:text-zinc-500 whitespace-nowrap">
<span
class="text-slate-500 dark:text-zinc-500 whitespace-nowrap font-normal"
>
{richURL.pathname}
</span>
{/if}
+134
View File
@@ -0,0 +1,134 @@
<script lang="ts" context="module">
// Courtesy of https://github.com/asimons04
export interface MBFCReport {
bias: string
credibility: string
domain: string
facebook?: string
twitter?: string
name: string
popularity?: number
questionable: string[]
reporting: string
url: string
// biases?: MBFCBiases
score?: number
}
export const findSource = async (
target: string,
dataset: any,
): Promise<MBFCReport | undefined> => {
if (!target) return undefined
let left = 0
let right = dataset.length
while (left <= right) {
const middle = Math.floor((left + right) / 2)
const foundDomain = dataset[middle].domain
if (foundDomain == target) return dataset[middle]
else if (foundDomain < target) left = middle + 1
else if (foundDomain > target) right = middle - 1
}
return undefined
}
</script>
<script lang="ts">
import { t } from '$lib/translations'
import { Badge, Modal, Spinner } from 'mono-svelte'
import Placeholder from '../ui/Placeholder.svelte'
import { Icon, QuestionMarkCircle, Link as Chain } from 'svelte-hero-icons'
import Link from '../input/Link.svelte'
import Expandable from '../ui/Expandable.svelte'
import Visualization from './Visualization.svelte'
export let open: boolean = false
export let domain: string = ''
let ratings = ['left', 'left-center', 'center', 'right-center', 'right']
let altRatings = [
'conspiracy-pseudoscience',
'pro-science',
'satire',
'fake-news',
]
let reporting = [
'very-low',
'low',
'mixed',
'mostly-factual',
'high',
'Very-high',
]
</script>
<Modal title={$t('post.actions.more.mediaBias')} {...$$restProps} bind:open>
{#await import('./data.json')}
<div class="w-full h-64 flex justify-center items-center">
<Spinner width={32} />
<span>{$t('post.actions.mediaBias.downloading')}</span>
</div>
{:then json}
{#await findSource(domain, json.sources)}
<span>{$t('post.actions.mediaBias.loading')}</span>
{:then data}
{#if data}
<h2 class="font-semibold text-xl">{data.name}</h2>
<Visualization
data={ratings.includes(data.bias) ? ratings : altRatings}
alt={!ratings.includes(data.bias)}
selected={data.bias}
name={json.biases.find((b) => b.bias == data.bias)?.name ?? data.bias}
/>
<Expandable open>
<span slot="title">{$t('post.actions.mediaBias.description')}</span>
<p class="text-sm">
{json.biases.find((b) => b.bias == data.bias)?.description}
</p>
</Expandable>
{#if data.questionable?.length > 0}
<div class="flex items-center flex-wrap gap-2">
{#each data.questionable as questionable}
<Badge color="red-subtle">
<span>
{json.questionable.find((q) => q.questionable == questionable)
?.name}
</span>
</Badge>
{/each}
</div>
{/if}
<h3 class="font-semibold text-lg">
{$t('post.actions.mediaBias.reporting')}
</h3>
<Visualization
data={reporting}
alt
width={24}
selected={data.reporting}
name={json.reporting.find((b) => b.reporting == data.reporting)
?.name ?? data.reporting}
/>
{:else}
<Placeholder
icon={QuestionMarkCircle}
title={$t('post.actions.mediaBias.noData.title')}
description={$t('post.actions.mediaBias.noData.description')}
/>
{/if}
<Link
href="https://mediabiasfactcheck.com/"
class="text-sm text-slate-700 dark:text-zinc-300"
>
<Icon src={Chain} micro size="14" />
mediabiasfactcheck.com
</Link>
{/await}
{/await}
</Modal>
@@ -0,0 +1,55 @@
<script lang="ts">
type T = $$Generic
export let data: T[]
export let selected: T
export let name: string
export let alt: boolean = false
export let width: number = 48
</script>
<div class="flex items-start gap-4 mx-auto mb-6">
{#each data as rating, index}
<div
class="flex flex-col gap-2 items-center relative"
style=" width: {width}px; height: {width}px;"
>
<div
class="w-12 h-12 {alt
? 'bg-red-500'
: 'bg-blue-500 border-blue-700'} opacity-50 transition-all cursor-pointer duration-100 {rating ==
selected
? 'current-bias'
: 'hover:opacity-100 rounded-full'}"
style="filter: hue-rotate({index *
30}deg); width: {width}px; height: {width}px;"
></div>
{#if rating == selected}
<span
class="capitalize font-medium whitespace-nowrap max-w-max absolute -bottom-8 left-1/2 -translate-x-1/2"
>
{name}
</span>
{/if}
</div>
{/each}
</div>
<style>
@keyframes spin {
0% {
transform: rotate(-180deg);
opacity: 0.5;
border-radius: 64px;
}
100% {
transform: rotate(45deg);
opacity: 1;
border-radius: 12px;
}
}
.current-bias {
animation: spin 1s forwards cubic-bezier(0.075, 0.82, 0.165, 1);
}
</style>
+1
View File
@@ -0,0 +1 @@
{"aliases":{"politi.co":"politico.com","bbc.co.uk":"bbc.com","cbs.com":"cbsnews.com","moveon.org":"front.moveon.org"},"biases":[{"bias":"left","code":"L","description":"These media sources are moderately to strongly biased toward liberal causes through story selection and/or political affiliation.  They may utilize strong loaded words (wording that attempts to influence an audience by using appeal to emotion or stereotypes), publish misleading reports and omit reporting of information that may damage liberal causes. Some sources in this category may be untrustworthy.","name":"Left Bias","pretty":"Left","url":"https://mediabiasfactcheck.com/left/"},{"bias":"left-center","code":"LC","description":"These media sources have a slight to moderate liberal bias.  They often publish factual information that utilizes loaded words (wording that attempts to influence an audience by using appeal to emotion or stereotypes) to favor liberal causes.  These sources are generally trustworthy for information, but may require further investigation.  ","name":"Left-Center Bias","pretty":"Left-Center","url":"https://mediabiasfactcheck.com/leftcenter/"},{"bias":"center","code":"C","description":"These sources have minimal bias and use very few loaded words (wording that attempts to influence an audience by using appeal to emotion or stereotypes).  The reporting is factual and usually sourced.  These are the most credible media sources.  ","name":"Least Biased","pretty":"Center","url":"https://mediabiasfactcheck.com/center/"},{"bias":"right-center","code":"RC","description":"These media sources are slightly to moderately conservative in bias. They often publish factual information that utilizes loaded words (wording that attempts to influence an audience by using appeal to emotion or stereotypes) to favor conservative causes. These sources are generally trustworthy for information, but may require further investigation.  ","name":"Right-Center Bias","pretty":"Right-Center","url":"https://mediabiasfactcheck.com/right-center/"},{"bias":"right","code":"R","description":"These media sources are moderately to strongly biased toward conservative causes through story selection and/or political affiliation. They may utilize strong loaded words (wording that attempts to influence an audience by using appeal to emotion or stereotypes), publish misleading reports and omit reporting of information that may damage conservative causes. Some sources in this category may be untrustworthy.","name":"Right Bias","pretty":"Right","url":"https://mediabiasfactcheck.com/right/"},{"bias":"pro-science","code":"PS","description":"These sources consist of legitimate science or are evidence based through the use of credible scientific sourcing.  Legitimate science follows the scientific method, is unbiased and does not use emotional words.  These sources also respect the consensus of experts in the given scientific field and strive to publish peer reviewed science. Some sources in this category may have a slight political bias, but adhere to scientific principles.","name":"Pro-Science","pretty":"Pro-Science","url":"https://mediabiasfactcheck.com/pro-science/"},{"bias":"conspiracy-pseudoscience","code":"CP","description":"Sources in the Conspiracy-Pseudoscience category may publish unverifiable information that is not always supported by evidence. These sources may be untrustworthy for credible/verifiable information, therefore fact checking and further investigation is recommended on a per article basis when obtaining information from these sources. ","name":"Conspiracy-Pseudoscience","pretty":"Conspiracy-Pseudoscience","url":"https://mediabiasfactcheck.com/conspiracy/"},{"bias":"satire","code":"S","description":"These sources exclusively use humor, irony, exaggeration, or ridicule to expose and criticize people’s stupidity or vices, particularly in the context of contemporary politics and other topical issues. Primarily these sources are clear that they are satire and do not attempt to deceive.","name":"Satire","pretty":"Satire","url":"https://mediabiasfactcheck.com/satire/"},{"bias":"fake-news","code":"FN","description":"A questionable source exhibits one or more of the following: extreme bias, overt propaganda, poor or no sourcing to credible information and/or is fake news. Fake News is the deliberate attempt to publish hoaxes and/or disinformation for the purpose of profit or influence (Learn More). Sources listed in the Questionable Category may be very untrustworthy and should be fact checked on a per article basis. Please note sources on this list are not considered fake news unless specifically written in the notes section for that source.","name":"Questionable Sources","pretty":"Fake-News","url":"https://mediabiasfactcheck.com/fake-news/"}],"credibility":[{"code":"H","credibility":"high-credibility","name":"High Credibility","pretty":"High Credibility"},{"code":"M","credibility":"medium-credibility","name":"Medium CredibLine truncated