var itemList = document.getElementsByClassName("heading"); for (var i = 0; i < itemList.length; i++) { var item = itemList[i].getElementsByTagName("a")[0]; console.log(item) value[item.href] = item.getElementsByTagName("span")[0].innerText } console.log(JSON.stringify(value))
btn.onclick = function () { //code copyToMarkdown() }
document.body.append(btn); functioncopyToMarkdown() { var url = window.location.href if (url.startsWith("https://blog.51cto.com/cloumn/detail")) { var value = getStorage(); var itemList = document.getElementsByClassName("heading"); for (var i = 0; i < itemList.length; i++) { var item = itemList[i].getElementsByTagName("a")[0]; console.log(item) value[item.href] = item.getElementsByTagName("span")[0].innerText } saveStorage(value); for (let key in value) { window.location.href = key; return; } } elseif (url.startsWith("https://blog.51cto.com/cloumn/blog")) { let obj = getStorage(); var title = obj[url]; var context = document.getElementsByClassName("artical-content-bak main-content")[0]
delete obj[url]; saveStorage(obj);
download(context.innerHTML, title); for (let key in obj) { window.location.href = key; return; }
} elseif (url.startsWith("https://blog.51cto.com/u_")) { let title = document.getElementsByTagName("h1")[0].innerText; let context = document.getElementById("container").innerHTML; download(context, title); } };
functiongetStorage() { var value = localStorage.getItem('title-list'); if (!value) { value = {}; } else { value = JSON.parse(value); } return value; }
functionsaveStorage(context) { localStorage.setItem('title-list', JSON.stringify(context)); } functiondownload(context, title) { const link = document.createElement('a'); var textBlob = newBlob([context], { type: 'text/plain' });
link.setAttribute('href', URL.createObjectURL(textBlob)); link.setAttribute('download', title + ".html"); link.click(); } })();