实现功能
通过油猴插件添加脚本,访问语雀时,自动插入按键,可以导出带锚点和语雀换行的MarkDown文件。
*用油猴是因为不想再装其他插件了,浏览器放不下了
新建一个油猴脚本
脚本编写界面
新建
完成
JavaScript脚本
- 获取当前文档原URL
- 给原URL添加参数“
/markdown?attachment=true&latexcode=false&anchor=true&linebreak=true”构造下载URL - 通过访问下载URL,下载MarkDown文件 ```javascript // ==UserScript== // @name 😎建瓯最坏🐷导出MarkDown文件 // @namespace https://www.yuque.com/jianouzuihuai // @version 22.03.28 // @description 通过油猴脚本导出带锚点和语雀换行的MarkDown文件 // @author 😎建瓯最坏🐷 // @match .yuque.com/// // @exclude .yuque.com/jianouzuihuai // @exclude *virus-analysis.yuque.com/lwb6kc/report-collection // @icon https://cdn.nlark.com/yuque/0/2021/png/1632223/1635923818567-7f54e0a1-144e-4fd0-9856-a24e5b2664c5.png // ==/UserScript==
(function() { “use strict”;
setTimeout(function(){//alert("设置按键")var buttonExport = document.createElement("button"); //创建一个按钮buttonExport.textContent = "导出"; //按钮内容buttonExport.style.width = '66px'; //按钮宽度buttonExport.style.height = '32px'; //按钮高度buttonExport.style.marginLeft = '16px'; // 距离左边12pxbuttonExport.style.color = '#BA7CFF'; // 按钮文字颜色buttonExport.style.border = '2px #BA7CFF solid'; // 边框buttonExport.style.font = 'bold'; // 文字加粗buttonExport.style.background = '#EEC6FF'; // 按钮底色buttonExport.style.borderRadius = '4px'; // 按钮四个角弧度// 获取当前URLvar strURL = window.location.href;// 获取页面的元素名var strClassNameInView = "header-action-item header-action-item-more";//var strClassNameInEdit = "lark-editor-header-more";if (strURL.indexOf("/edit") != -1){//alert("编辑页面");//strURL = strURL.replace("/edit", "");//eleButton = document.getElementsByClassName(strClassNameInEdit)[0];}else{//alert("浏览页面")var arrElementsByClassName = document.getElementsByClassName(strClassNameInView);if (arrElementsByClassName.length){var eleButton = arrElementsByClassName[0];eleButton.appendChild(buttonExport);//alert("已添加按键");}else{alert("未找到指定类名,请检查类名是否正确");//eleButton = document.getElementsByClassName("header-action-item header-action-item-more")[0];}}buttonExport.onclick = function (){//检测到有锚点就删除if (strURL.indexOf("#") != -1){var arrSplitPound = strURL.split("#");//alert("编辑页面")strURL = arrSplitPound[0];//eleButton = document.getElementsByClassName(strClassNameInEdit)[0];}//alert("绑定按键点击功能")var strURL_Export = strURL + "/markdown?attachment=true&latexcode=false&anchor=true&linebreak=true"window.open(strURL_Export);};},2000)//2秒后执行
显示效果
油猴插件
浏览状态
编辑状态
编辑状态导出的MarkDown并不是实时保存的,还是服务器上未更新的资源,已删除:
希望增加的功能
在浏览状态导出后,自动跳转至下一篇文章。
