2023-07-27 07:31:52 +02:00
|
|
|
<!--
|
|
|
|
SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2020-01-29 20:37:25 +01:00
|
|
|
<template>
|
2023-05-19 09:20:53 +02:00
|
|
|
<MkContainer :showHeader="widgetProps.showHeader" data-cy-mkw-rss class="mkw-rss">
|
2023-01-15 00:30:29 +01:00
|
|
|
<template #icon><i class="ti ti-rss"></i></template>
|
|
|
|
<template #header>RSS</template>
|
2023-09-30 21:53:52 +02:00
|
|
|
<template #func="{ buttonStyleClass }"><button class="_button" :class="buttonStyleClass" @click="configure"><i class="ph-gear ph-bold pg-lg"></i></button></template>
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2020-07-11 03:13:11 +02:00
|
|
|
<div class="ekmkgxbj">
|
2020-10-17 13:12:00 +02:00
|
|
|
<MkLoading v-if="fetching"/>
|
2023-01-15 00:30:29 +01:00
|
|
|
<div v-else-if="(!items || items.length === 0) && widgetProps.showHeader" class="_fullinfo">
|
2023-06-09 07:00:53 +02:00
|
|
|
<img :src="infoImageUrl" class="_ghost"/>
|
2023-01-04 19:28:25 +01:00
|
|
|
<div>{{ i18n.ts.nothing }}</div>
|
|
|
|
</div>
|
|
|
|
<div v-else :class="$style.feed">
|
2023-01-15 00:30:29 +01:00
|
|
|
<a v-for="item in items" :key="item.link" :class="$style.item" :href="item.link" rel="nofollow noopener" target="_blank" :title="item.title">{{ item.title }}</a>
|
2020-01-29 20:37:25 +01:00
|
|
|
</div>
|
2020-07-11 03:13:11 +02:00
|
|
|
</div>
|
2020-10-17 13:12:00 +02:00
|
|
|
</MkContainer>
|
2020-01-29 20:37:25 +01:00
|
|
|
</template>
|
|
|
|
|
2022-01-08 12:30:01 +01:00
|
|
|
<script lang="ts" setup>
|
2023-01-04 19:28:25 +01:00
|
|
|
import { ref, watch, computed } from 'vue';
|
2023-05-19 09:20:53 +02:00
|
|
|
import { useWidgetPropsManager, Widget, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from './widget';
|
2023-09-19 09:37:43 +02:00
|
|
|
import { GetFormResultType } from '@/scripts/form.js';
|
2022-09-06 11:21:49 +02:00
|
|
|
import MkContainer from '@/components/MkContainer.vue';
|
2023-09-19 09:37:43 +02:00
|
|
|
import { url as base } from '@/config.js';
|
|
|
|
import { i18n } from '@/i18n.js';
|
|
|
|
import { useInterval } from '@/scripts/use-interval.js';
|
|
|
|
import { infoImageUrl } from '@/instance.js';
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2022-01-08 12:30:01 +01:00
|
|
|
const name = 'rss';
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2022-01-08 12:30:01 +01:00
|
|
|
const widgetPropsDef = {
|
|
|
|
url: {
|
|
|
|
type: 'string' as const,
|
|
|
|
default: 'http://feeds.afpbb.com/rss/afpbb/afpbbnews',
|
2020-01-29 20:37:25 +01:00
|
|
|
},
|
2023-01-04 19:28:25 +01:00
|
|
|
refreshIntervalSec: {
|
|
|
|
type: 'number' as const,
|
|
|
|
default: 60,
|
|
|
|
},
|
|
|
|
maxEntries: {
|
|
|
|
type: 'number' as const,
|
|
|
|
default: 15,
|
|
|
|
},
|
2022-06-30 16:45:11 +02:00
|
|
|
showHeader: {
|
|
|
|
type: 'boolean' as const,
|
|
|
|
default: true,
|
|
|
|
},
|
2022-01-08 12:30:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
type WidgetProps = GetFormResultType<typeof widgetPropsDef>;
|
|
|
|
|
2023-05-19 09:20:53 +02:00
|
|
|
const props = defineProps<WidgetComponentProps<WidgetProps>>();
|
|
|
|
const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
|
2022-01-08 12:30:01 +01:00
|
|
|
|
|
|
|
const { widgetProps, configure } = useWidgetPropsManager(name,
|
|
|
|
widgetPropsDef,
|
|
|
|
props,
|
|
|
|
emit,
|
|
|
|
);
|
|
|
|
|
2023-01-04 19:28:25 +01:00
|
|
|
const rawItems = ref([]);
|
|
|
|
const items = computed(() => rawItems.value.slice(0, widgetProps.maxEntries));
|
2022-01-08 12:30:01 +01:00
|
|
|
const fetching = ref(true);
|
2023-01-04 19:28:25 +01:00
|
|
|
const fetchEndpoint = computed(() => {
|
|
|
|
const url = new URL('/api/fetch-rss', base);
|
|
|
|
url.searchParams.set('url', widgetProps.url);
|
|
|
|
return url;
|
|
|
|
});
|
|
|
|
let intervalClear = $ref<(() => void) | undefined>();
|
2022-01-08 12:30:01 +01:00
|
|
|
|
|
|
|
const tick = () => {
|
2023-01-04 19:28:25 +01:00
|
|
|
if (document.visibilityState === 'hidden' && rawItems.value.length !== 0) return;
|
|
|
|
|
|
|
|
window.fetch(fetchEndpoint.value, {})
|
2023-01-15 00:30:29 +01:00
|
|
|
.then(res => res.json())
|
|
|
|
.then(feed => {
|
|
|
|
rawItems.value = feed.items ?? [];
|
|
|
|
fetching.value = false;
|
|
|
|
});
|
2022-01-08 12:30:01 +01:00
|
|
|
};
|
|
|
|
|
2023-01-04 19:28:25 +01:00
|
|
|
watch(() => fetchEndpoint, tick);
|
|
|
|
watch(() => widgetProps.refreshIntervalSec, () => {
|
|
|
|
if (intervalClear) {
|
|
|
|
intervalClear();
|
|
|
|
}
|
|
|
|
intervalClear = useInterval(tick, Math.max(10000, widgetProps.refreshIntervalSec * 1000), {
|
|
|
|
immediate: true,
|
|
|
|
afterMounted: true,
|
|
|
|
});
|
|
|
|
}, { immediate: true });
|
2022-01-08 12:30:01 +01:00
|
|
|
|
|
|
|
defineExpose<WidgetComponentExpose>({
|
|
|
|
name,
|
|
|
|
configure,
|
|
|
|
id: props.widget ? props.widget.id : null,
|
2020-01-29 20:37:25 +01:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2023-01-04 19:28:25 +01:00
|
|
|
<style lang="scss" module>
|
|
|
|
.feed {
|
|
|
|
padding: 0;
|
|
|
|
font-size: 0.9em;
|
|
|
|
}
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2023-01-04 19:28:25 +01:00
|
|
|
.item {
|
|
|
|
display: block;
|
|
|
|
padding: 8px 16px;
|
|
|
|
color: var(--fg);
|
|
|
|
white-space: nowrap;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
overflow: hidden;
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2023-01-04 19:28:25 +01:00
|
|
|
&:nth-child(even) {
|
|
|
|
background: rgba(#000, 0.05);
|
2020-01-29 20:37:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|