Skip to content

Commit

Permalink
feat: implemented nsfw settings
Browse files Browse the repository at this point in the history
  • Loading branch information
enpitsuLin committed Mar 26, 2023
1 parent 6e9b68c commit 9f06815
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
);
const [showTable, toggleShowTable] = useToggle(false);
const { isFetching, error, data } = useGreasyfork();
const data = useDataList();
const pagePsl = computed(() => {
return psl.get(window.location.hostname);
Expand Down
19 changes: 11 additions & 8 deletions src/components/DataTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,18 @@
daily: '' as '' | 'desc' | 'asc'
});
const sortedData = useSorted(props.data, (a, b) => {
if (sort.updated !== '') {
if (sort.updated === 'asc')
return +new Date(a.code_updated_at) - +new Date(b.code_updated_at);
return +new Date(b.code_updated_at) - +new Date(a.code_updated_at);
const sortedData = useSorted(
computed(() => props.data),
(a, b) => {
if (sort.updated !== '') {
if (sort.updated === 'asc')
return +new Date(a.code_updated_at) - +new Date(b.code_updated_at);
return +new Date(b.code_updated_at) - +new Date(a.code_updated_at);
}
if (sort.daily === 'asc') return a.daily_installs - b.daily_installs;
return b.daily_installs - a.daily_installs;
}
if (sort.daily === 'asc') return a.daily_installs - b.daily_installs;
return b.daily_installs - a.daily_installs;
});
);
const sortIcon = (sort: '' | 'desc' | 'asc') => {
if (sort === '') return 'i-carbon-caret-sort';
Expand Down
35 changes: 33 additions & 2 deletions src/composables/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,41 @@ export type GreasyforkScript = {
version: string;
};

export function useGreasyfork(site = 'https://greasyfork.org') {
export function useGreasyfork(
site = 'https://greasyfork.org',
immediate = true
) {
const host = psl.get(window.location.hostname);
const apiEndpoint = `${site}/en/scripts/by-site/${host}.json`;
return useFetch(apiEndpoint, { fetch: unsafeWindow.fetch }).json<
return useFetch(apiEndpoint, { fetch: unsafeWindow.fetch, immediate }).json<
GreasyforkScript[]
>();
}

export function useDataList() {
const settings = useUserjsDiggerSettings();
const { data: greasyfork } = useGreasyfork();
const { data: sleazyfork, execute } = useGreasyfork(
'https://sleazyfork.org',
false
);
watch(
() => settings.value.nsfw,
(val) => {
if (val) {
if (!sleazyfork.value) execute();
}
},
{ immediate: true }
);

const data = computed(() => {
return (
greasyfork.value?.concat(
settings.value.nsfw ? sleazyfork.value ?? [] : []
) ?? []
);
});

return data;
}

0 comments on commit 9f06815

Please sign in to comment.