扇贝

扇贝单词下载导出

< Părere la script-ul 扇贝

Recenzie: Bun, script-ul merge

§
Postat în: 26-06-2021
Editat în: 26-06-2021

单词书下单单词过多时(超过5000个)下载后,无法弹出新标签页。

出错控制台输出:
userscript.html?name=%E6%89%87%E8%B4%9D.user.js&id=6e7d1ed5-2a84-4502-b9b5-62086fbb467e:123 Uncaught (in promise) TypeError: Cannot read property 'document' of null
at popup_result (userscript.html?name=%E6%89%87%E8%B4%9D.user.js&id=6e7d1ed5-2a84-4502-b9b5-62086fbb467e:123)
at HTMLButtonElement.eval (userscript.html?name=%E6%89%87%E8%B4%9D.user.js&id=6e7d1ed5-2a84-4502-b9b5-62086fbb467e:179)

错误原因:下载时间过长,被当成广告弹窗拦截

修改以下函数,改成直接下载JSON就可以了。

    function popup_result(res){
        var element = document.createElement('a');
        element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(JSON.stringify(res,null,2)));
        element.setAttribute('download', 'export.json');

        element.style.display = 'none';
        document.body.appendChild(element);

        element.click();

        document.body.removeChild(element);
    }

Postează un raspuns

Autentifică-te pentru a posta un răspuns.