@nuxt/scripts
Version:
Load third-party scripts with better performance, privacy and DX in Nuxt Apps.
23 lines (22 loc) • 582 B
JavaScript
import { tryOnScopeDispose } from "@vueuse/shared";
import { useTimeoutFn } from "@vueuse/core";
import { onNuxtReady } from "nuxt/app";
export function useScriptTriggerIdleTimeout(options) {
if (import.meta.server) {
return new Promise(() => {
});
}
const { timeout } = options;
return new Promise((resolve) => {
onNuxtReady(() => {
const { start, stop } = useTimeoutFn(() => {
resolve(true);
}, timeout, { immediate: false });
start();
tryOnScopeDispose(() => {
stop();
resolve(false);
});
});
});
}