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 var patchContent = false //处理详情页中的大图,大图作为附件使用 const images = tmp.querySelectorAll("img"); images.forEach((img, i) => { if (img.width > 300) { patchContent = true const a = document.createElement("a"); a.href = img.src; a.innerText = img.src; tmp.appendChild(a); } }) } } if("{{.AttachCss}}"!=""){//附件 tmp = document.querySelectorAll("{{.AttachCss}} a") let attach=[] if(tmp){ tmp.forEach((v,i)=>{ attach.push({title:v.getAttribute("title")||v.innerText,href:v.href}) }) } ret["attachLinks"]=attach } //检查中文字符个数,少于20,修正正文内容 let regex = /[\u4e00-\u9fa5]/g; let chineseCharacters = ret["content"]?ret["content"].match(regex):[]; let chineseCharactersLen=chineseCharacters ? chineseCharacters.length : 0; if (chineseCharactersLen < 20 && ret["attachLinks"] && ret["attachLinks"].length>0) ret["content"] = '详情请访问原网页!' ret