浏览器导出的书签是html文件
写了个JS小工具可以把书签html文件转换成JSON数组方便调用
把代码用记事本保存成 书签小工具.html 然后用浏览器打开就可以用啦
[HTML] 纯文本查看 复制代码 <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="format-detection" content="telephone=no">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title>(๑•̀ㅂ•́)و</title>
<style type="text/css">.Left,.Right{box-sizing:border-box;overflow:auto;margin:0;padding:20px;border:1px solid #ccc;color:#000;font-size:12px;line-height:20px;height:calc(100vh - 80px);background:#e6e6e6;float:left;width:50%;}a{color:#333;}</style>
<script type="text/javascript">
window.DataArray=[];
function DataArrayCheck(url){
for(var i=0;i<window.DataArray.length;i++)
if(window.DataArray[i].href==url)return i;
return -1;
}
function InputChange(input){
var reader=new FileReader();
reader.onload=function(event){
var stage=document.querySelector(".Left");
stage.innerHTML=event.target.result;
var list=stage.querySelectorAll("a");
for(var i=0;i<list.length;i++){
var link=list[i];
var href=link.getAttribute("href");
if(DataArrayCheck(href)<0)window.DataArray.push({"name":link.innerText,"href":href});
}
document.querySelector(".Right").innerText=JSON.stringify(window.DataArray,null,2);
document.title="共计"+String(window.DataArray.length)+"条数据";
};
reader.readAsText(input.files[0]);
}
function TipText(text){
document.querySelector(".Input .Tiper").innerText=text;
setTimeout(function(){document.querySelector(".Input .Tiper").innerText="复制到剪贴板";},2000);
}
function CopyText(text){
var input=document.createElement("input");
input.setAttribute("value",text?text:"");
document.body.appendChild(input);
input.select();
document.execCommand("copy");
document.body.removeChild(input);
return text?text.length:0;
}
function CopyJsonData(){
TipText(window.DataArray.length?CopyText(JSON.stringify(window.DataArray,null,2))?"复制成功":"复制失败":"请先加载数据");
}
</script>
</head>
<body>
<div class="Left"></div>
<pre class="Right" style="float:right;"></pre>
<div class="Input" style="padding:10px 0;clear:both;position:relative;">
<input type="file">
<button class="Tiper" style="position:absolute;right:0;top:50%;transform:translateY(-50%);">复制到剪贴板</button>
</div>
</body>
</html>
|