-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbookmark.browser.iife.js
8 lines (8 loc) · 2.18 KB
/
bookmark.browser.iife.js
1
2
3
4
5
6
7
8
/**
* @file bookmark.browser.iife.js
* @name netscape-bookmark-tree
* @version 2.1.1 Build.1684236336177
* @author ZMY
* @license MIT
*/
var bookmark=function(t){"use strict";function e(t,e,n){const r=" ";function i(t,a){return t.reduce((function(t,c){const{name:s,attributes:o,children:u}=e(c,a),l=a.concat(c),d=a.reduce((t=>t+r),n+r),f=function(t){return t?t.reduce((function(t,e){return`${t} ${e[0].toUpperCase()}="${e[1]}"`}),""):""}(o);let T;if(Array.isArray(u)){const t=i(u,l),e=[`<DT><H3${f}>${s}</H3>`,"<DL><p>",r+t,"</DL><p>"];0===u.length&&e.splice(2,1),T=e.join(d)}else T=`<DT><A${f}>${s}</A>`;return t?t+d+T:T}),"")}return t.map((function(t){const{children:n,name:a}=e(t);let c=i(n,[]);return c=`\n<!DOCTYPE NETSCAPE-Bookmark-file-1>\n\x3c!-- This is an automatically generated file.\n It will be read and overwritten.\n DO NOT EDIT! --\x3e\n<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">\n<TITLE>Bookmarks</TITLE>\n<H1>${a}</H1>\n<DL><p>\n${r}${c}\n</DL><p>\n`,c=c.trimStart(),c}))}const n={parseHTML(t){const e=document.createElement("div");return e.innerHTML=t,e.childNodes},getTag:t=>t.nodeName.toLowerCase(),getName:t=>t.textContent,setAttrs(t,e){const n=e.attributes,r=[];for(let e=0;e<n.length;e++){const i=n[e];t[i.name]=i.value,r.push([i.name,i.value])}return r}},r={parse:{each(t,e){const n=(i=e.parentPath)[i.length-1],r=e.index;var i;return t.index=r,n?(t.id=`${n.id}_${r}`,t.pid=n.id):t.id=r.toString(),t},setChildren(t,e){t.children=e}},stringify:{each:function(t){return t},eol:"\n"}};return t.defaultOptions=r,t.parse=function(t,e){return e=Object.assign({},r.parse,e),function(t,e,n,r){const i=e.replace(/<!DOCTYPE [\s\S]+?<\/TITLE>|<DT>|<p>/g,""),a=function e(i,a){const c=[];return i.forEach((function(i){const s=t.getTag(i);function o(e){const r=c.length;let o={name:t.getName(i)};const u=t.setAttrs(o,i);o=n(o,{parentPath:a,isLeaf:e,index:r,attributes:u,tag:s},i)||o,c.push(o)}if("a"===s)o(!0);else if("h3"===s||"h1"===s)o(!1);else if("dl"===s){const t=c[c.length-1],n=a.concat(t),s=e(i.childNodes,n);r(t,s)}})),c}(t.parseHTML(i),[]);return a}(n,t,e.each,e.setChildren)},t.stringify=function(t,n){return e(t,(n=Object.assign({},r.stringify,n)).each,n.eol)},t}({});