// ==UserScript== // @name xiaohongshu Download Markdown // @namespace https://space.bilibili.com/1208812226 // @version 0.7 // @description 快捷键:Ctrl+Alt+S,一键下载xiaohongshu页面内容为Markdown文档,也可点击右侧下载图标下载页面内容 // @author dawangeee // @match https://www.xiaohongshu.com/ // @match https://www.xiaohongshu.com/* // @match https://www.xiaohongshu.com/user/profile/* // @match http*://www.xiaohongshu.com/user/profile/* // @icon https://www.xiaohongshu.com/favicon.ico // @grant none // @license AGPL License // @downloadURL https://update.greasyfork.icu/scripts/466624/xiaohongshu%20Download%20Markdown.user.js // @updateURL https://update.greasyfork.icu/scripts/466624/xiaohongshu%20Download%20Markdown.meta.js // ==/UserScript== (function () { "use strict"; document.addEventListener("keydown", function (event) { if (event.altKey && event.keyCode == 83) {//下载为markdown格式——快捷键:Ctrl+Alt+S if (event.ctrlKey) { downloadMD(); } } }); })(); function getFormatDate(time) { return time.getFullYear() + "" + (time.getMonth() + 1) + "" + time.getDate()+ "" + time.getHours()+ "" + time.getMinutes()+ "" + time.getSeconds(); } function downloadMD(){ const wFull = document.querySelectorAll(".note-item"); var allContent = ""; if (wFull != null && wFull.length > 0) { var myTitle =document.querySelector(".user-name")?document.querySelector(".user-name").innerHTML+document.querySelectorAll(".count")[1].innerHTML+"粉丝":"explore_"+getFormatDate(new Date()); for (let i = 0; i < wFull.length; i++) { //allContent+=""+wFull[i].innerText+"\n"; var doc = new DOMParser().parseFromString(wFull[i].innerHTML, 'text/html'); var testDom=doc.body.childNodes[0].childNodes[2]; allContent+=testDom.childNodes[0].innerText+"("; allContent+=testDom.childNodes[1].childNodes[1].innerText+")"; var docDom=doc.body.childNodes[0].childNodes[1]; allContent += "[查看详情~](" + docDom.href + ")\n"; var myimg = docDom.style.background + "\n"; const regex = /url\("([^"]+)"\)/; // 匹配url("...")中的内容 const match = myimg.match(regex); if (match) { const url = match[1]; allContent += "![|250](" + url + ")\n\n"; } else { allContent += "\n\n"; } } let blob = new Blob([allContent]); let a = document.createElement('a'); a.download = "xiaohongshu_" + myTitle + ".md"; a.href = URL.createObjectURL(blob); document.body.appendChild(a); a.click(); URL.revokeObjectURL(blob); document.body.removeChild(a); } } window.onload=function(){ var svgDom= ''; var newDiv = document.createElement("div"); newDiv.innerHTML = svgDom; newDiv.addEventListener("click", () => { downloadMD(); }); document.body.append(newDiv); };