//执行JS代码 var ret = {} var tmp = null if ("{{.TitleCss}}" != "") {//标题 tmp = document.querySelector("{{.TitleCss}}") if (tmp) ret["title"] = tmp.getAttribute("title") || tmp.innerText } if ("{{.PublishUnitCss}}" != "") {//采购单位 tmp = document.querySelector("{{.PublishUnitCss}}") if (tmp) ret["publishUnit"] = tmp.getAttribute("title") || tmp.innerText } if ("{{.PublishTimeCss}}" != "") {//发布时间 tmp = document.querySelector("{{.PublishTimeCss}}") if (tmp) ret["publishTime"] = tmp.getAttribute("title") || tmp.innerText } if ("{{.ContentCss}}" != "") {//正文内容 tmp = document.querySelector("{{.ContentCss}}") if (tmp) { ret["content"] = tmp.innerText ret["contentHtml"] = tmp.innerHTML } } //if("{{.AttachCss}}"!=""){//附件 // tmp = document.querySelectorAll("{{.AttachCss}} a") // let attach=[] // if(tmp){ // tmp.forEach((v,i)=>{ // attach.push([v.getAttribute("title")||v.innerText,v.href]) // }) // } // ret["attachLinks"]=attach //} ret['attachLinks']=findFileAttachmentTag(); function findFileAttachmentTag(container = document.body) { const ns = [] const extensions = ['pdf', 'doc', 'docx', 'xls', 'xlsx', 'zip', 'rar','PDF','DOC','DOCX','XLS','XLSX','ZIP','RAR'] const extensionRegex = new RegExp('\\.(' + extensions.join('|') + ')$', 'i'); const aTagList = container.querySelectorAll('a[href]') aTagList.forEach((v, i)=>{ v.setAttribute('target', '_blank'); const linkText = v.innerText const href = v.href const filename = v.download || v.filename || linkText if(extensionRegex.test(linkText.toLowerCase()) || extensionRegex.test(href.toLowerCase())){ ns.push({ title :linkText, href :v.href, filename, }) } }); return ns; } ret