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