天气模板

天气模板

日志模板

//!js
return (async () => {
    // 获取天气
    getWeather();
    async function getWeather () {
        // 天气api
        const weather = await fetch('https://wttr.in/?format=1');
        const text = await weather.text();

        // 显示当时的天气
        render(text);

        // 始终显示今天的天气
        //render(text, 2);
    };
    // 渲染结果
    // type 1: 显示当时的天气,2:始终显示今天的天气
    async function render(text, type = 1) {
        if(type === 1) {
            await fetchSyncPost('/api/block/updateBlock', {
                "dataType": "markdown",
                "data": text,
                "id": item.dataset.nodeId
            });
        } else {
            item.innerHTML = Lute.New().Md2BlockDOM(text);
            item.style.backgroundColor = 'transparent';
            item.style.borderLeft = 'none';
            item.style.cursor = 'text';
            item.querySelector('[contenteditable="true"]').setAttribute('contenteditable', false);
        }
    }
    // 渲染时显示正在加载
    whenRender().then(el => {
        el.outerHTML = 'loading...';
    });
    function whenRender(selector = '.b3-form__space--small') {
        return new Promise(resolve => {
            const check = () => {
                let el = item.querySelector(selector);
                if (el) resolve(el); else requestAnimationFrame(check);
            };
            check();
        });
    }
    return [];
})();

数据库模板

<img src="" onerror="
    // 天气api
    (async () => {
        const weather = await fetch('https://wttr.in/?format=1');
        const text = await weather.text();
        this.outerHTML = text;
    })();
" />

image.png

留下你的脚步
推荐阅读