Greasy Fork

Greasy Fork is available in English.

网页里面将文本保存成文件并直接下载

网页下载文本

当前为 2023-08-29 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.greasyfork.icu/scripts/474124/1242477/%E7%BD%91%E9%A1%B5%E9%87%8C%E9%9D%A2%E5%B0%86%E6%96%87%E6%9C%AC%E4%BF%9D%E5%AD%98%E6%88%90%E6%96%87%E4%BB%B6%E5%B9%B6%E7%9B%B4%E6%8E%A5%E4%B8%8B%E8%BD%BD.js

// ==UserScript==
// @name         网页里面将文本保存成文件并直接下载
// @namespace    https://leochan.me
// @version      1.0.0
// @description  网页下载文本
// @author       Leo
// @license      GPLv2
// @match        *://*/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=leochan.me
// @grant        none
// ==/UserScript==

function webPageDownloadTextFile(text, fileName) {
    let element = document.createElement('a');
    element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
    element.setAttribute('download', fileName);
    element.style.display = 'none';
    document.body.appendChild(element);
    element.click();
    document.body.removeChild(element);
}