// ==UserScript== // @name 下载当前网页的快捷链接文件 // @namespace https://github.com/AliubYiero/TamperMonkeyScripts // @version 1.0.0 // @description 下载一个 html 文件, 快速链接到当前网页, 让本地可以快速打开网页 // @author Yiero // @match *://*/* // @grant GM_registerMenuCommand // ==/UserScript== /** * 下载文件 */ const downloadFile = (blob, filename) => { const node = document.createElement('a'); node.download = filename; node.href = URL.createObjectURL(blob); node.click(); } (function () { 'use strict'; // Your code here... // 声明注册菜单 GM_registerMenuCommand('download', () => { const filename = `${document.title}.html` // 创建 Blob const htmlBlob = new File( [`${document.title}`], filename, { type: 'text/html' }, ); // 下载文件 downloadFile(htmlBlob, filename); }) })();