From 66bc222fbe07d9101ddabe91199e7bc7c0099158 Mon Sep 17 00:00:00 2001 From: scoful <1269717999@qq.com> Date: Sun, 22 Mar 2020 13:34:15 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E6=96=B0=E5=A2=9EMarkdown=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E7=94=9F=E6=88=90=E5=99=A8=EF=BC=9B2.=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E5=87=A0=E4=B8=AA=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _locales/en/messages.json | 3 ++ _locales/zh_CN/messages.json | 3 ++ js/funcScripts.js | 82 +++++++++++++++++++++++++++++++ js/markdownToc.js | 85 ++++++++++++++++++++++++++++++++ js/workbench.js | 22 +++++++++ markdownToc.html | 94 ++++++++++++++++++++++++++++++++++++ 6 files changed, 289 insertions(+) create mode 100644 js/funcScripts.js create mode 100644 js/markdownToc.js create mode 100644 markdownToc.html diff --git a/_locales/en/messages.json b/_locales/en/messages.json index b3191f2..bbb8568 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -433,5 +433,8 @@ }, "remindMenu": { "message": "remind menu" + }, + "markdownToc": { + "message": "Markdown Toc Generator" } } \ No newline at end of file diff --git a/_locales/zh_CN/messages.json b/_locales/zh_CN/messages.json index c8ac632..da43abf 100644 --- a/_locales/zh_CN/messages.json +++ b/_locales/zh_CN/messages.json @@ -433,5 +433,8 @@ }, "remindMenu": { "message": "定时功能菜单" + }, + "markdownToc": { + "message": "Markdown目录生成器" } } \ No newline at end of file diff --git a/js/funcScripts.js b/js/funcScripts.js new file mode 100644 index 0000000..b77972e --- /dev/null +++ b/js/funcScripts.js @@ -0,0 +1,82 @@ +// 定时任务平台可用的脚本 + +// 网易云音乐签到 +async function signIn163Music() { + try { + console.log("signIn163Music") + // 手机签到 + var { data } = await axios.get('http://music.163.com/api/point/dailyTask?type=0'); + if (data.code != 200 && data.code != -2) throw data.msg; + // 电脑签到 + var { data } = await axios.get('http://music.163.com/api/point/dailyTask?type=1'); + if (data.code == -2) throw '重复签到'; + if (data.code != 200) throw data.msg; + } catch (error) { + chrome.storage.local.set({ "signIn163Music": { "feedback": error, "lastRun": moment().format('YYYY-MM-DD HH:mm:ss') } }); + } +}; + +// v2ex签到 +async function signInV2ex() { + try { + console.log("signInV2ex") + var ret = await axios.get('https://www.v2ex.com/mission/daily'); + if (/登录"] }, + ["blocking", "requestHeaders"]); + + +// 京东签到 +async function signInJd() { + try { + console.log("signInJd") + var { data } = await axios.get('https://vip.jd.com/sign/index'); + if (/签到成功/.test(data)) throw '签到成功'; + if (/请明日再来/.test(data)) throw '请明日再来'; + throw '失败'; + } catch (error) { + chrome.storage.local.set({ "signInJd": { "feedback": error, "lastRun": moment().format('YYYY-MM-DD HH:mm:ss') } }); + } +}; + +// csdn刷访问量 +async function refreshCsdn() { + try { + console.log("refreshCsdn") + var { data } = await axios.get('https://blog.csdn.net/Scoful/article/details/104352581'); + throw '失败'; + } catch (error) { + chrome.storage.local.set({ "refreshCsdn": { "feedback": error, "lastRun": moment().format('YYYY-MM-DD HH:mm:ss') } }); + } +}; \ No newline at end of file diff --git a/js/markdownToc.js b/js/markdownToc.js new file mode 100644 index 0000000..be9df7c --- /dev/null +++ b/js/markdownToc.js @@ -0,0 +1,85 @@ +var select_all_on_click = function (textBox) { + textBox.onfocus = function () { + textBox.select(); + textBox.onmouseup = function () { + textBox.onmouseup = null; + return false; + }; + }; +}; + +select_all_on_click(document.getElementById('md')); +select_all_on_click(document.getElementById('toc')); + +document.getElementById('generate').addEventListener('click', function () { + $('#toc').val("") + var mdTextarea = $('#md').val(); + if (!mdTextarea) { + alert(`${chrome.i18n.getMessage("importTextareaTip")}`) + return; + } + var content = mdTextarea.split("\n"); + let result = "**目录**\n----\n" + var flag = false; + for (let i = 0; i < content.length; i++) { + if (content[i].indexOf("```") != -1) { + let a = content[i].split("```")[0]; + if (a.length <= 0) { + flag = !flag; + } + } + if (content[i].indexOf("$$") != -1) { + let a = content[i].split("$$")[0]; + if (a.length <= 0) { + flag = !flag; + } + } + if (flag) { + continue; + } + if (content[i] == "") { + continue; + } + if (content[i].indexOf("#") == -1) { + continue; + } + let lineList = content[i].trim().split(" "); + let element = lineList[0]; + if (element.indexOf("#") != -1) { + let eleLength = element.split("#").length - 1; + + if (eleLength == element.length && eleLength != 0) { + let mid1 = textFilter(content[i].substring(eleLength + 1).trim().replace(/ /g, "-")).toLowerCase(); + let mid2 = "* [" + content[i].substring(eleLength + 1) + "](#" + mid1 + ")\n"; + if (eleLength == 2) { + mid2 = " " + mid2 + } + if (eleLength == 3) { + mid2 = " " + mid2 + } + if (eleLength == 4) { + mid2 = " " + mid2 + } + if (eleLength == 5) { + mid2 = " " + mid2 + } + if (eleLength == 6) { + mid2 = " " + mid2 + } + result += mid2; + } + } + } + $('#toc').val(result) +}); + + +//去掉特殊符号的方法 +function textFilter(str) { + var pattern = new RegExp("[`~%!@#^=''?~!@#¥……&—‘”“'?*()(),,。.、]"); //[]内输入你要过滤的字符 + var rs = ""; + for (var i = 0; i < str.length; i++) { + rs += str.substr(i, 1).replace(pattern, ''); + } + return rs; +} \ No newline at end of file diff --git a/js/workbench.js b/js/workbench.js index 6348341..57cd84b 100644 --- a/js/workbench.js +++ b/js/workbench.js @@ -95,6 +95,7 @@