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