load_content.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //执行JS代码
  2. var ret = {}
  3. var tmp = null
  4. if ("{{.TitleCss}}" != "") {//标题
  5. tmp = document.querySelector("{{.TitleCss}}")
  6. if (tmp) ret["title"] = tmp.getAttribute("title") || tmp.innerText
  7. }
  8. if ("{{.PublishUnitCss}}" != "") {//采购单位
  9. tmp = document.querySelector("{{.PublishUnitCss}}")
  10. if (tmp) ret["publishUnit"] = tmp.getAttribute("title") || tmp.innerText
  11. }
  12. if ("{{.PublishTimeCss}}" != "") {//发布时间
  13. tmp = document.querySelector("{{.PublishTimeCss}}")
  14. if (tmp) ret["publishTime"] = tmp.getAttribute("title") || tmp.innerText
  15. }
  16. if ("{{.ContentCss}}" != "") {//正文内容
  17. tmp = document.querySelector("{{.ContentCss}}")
  18. if (tmp) {
  19. ret["content"] = tmp.innerText
  20. ret["contentHtml"] = tmp.innerHTML
  21. }
  22. }
  23. //if("{{.AttachCss}}"!=""){//附件
  24. // tmp = document.querySelectorAll("{{.AttachCss}} a")
  25. // let attach=[]
  26. // if(tmp){
  27. // tmp.forEach((v,i)=>{
  28. // attach.push([v.getAttribute("title")||v.innerText,v.href])
  29. // })
  30. // }
  31. // ret["attachLinks"]=attach
  32. //}
  33. ret['attachLinks']=findFileAttachmentTag();
  34. function findFileAttachmentTag(container = document.body) {
  35. const ns = []
  36. const extensions = ['pdf', 'doc', 'docx', 'xls', 'xlsx', 'zip', 'rar','PDF','DOC','DOCX','XLS','XLSX','ZIP','RAR']
  37. const extensionRegex = new RegExp('\\.(' + extensions.join('|') + ')$', 'i');
  38. const aTagList = container.querySelectorAll('a[href]')
  39. aTagList.forEach((v, i)=>{
  40. v.setAttribute('target', '_blank');
  41. const linkText = v.innerText
  42. const href = v.href
  43. const filename = v.download || v.filename || linkText
  44. if(extensionRegex.test(linkText.toLowerCase()) || extensionRegex.test(href.toLowerCase())){
  45. ns.push({
  46. title :linkText,
  47. href :v.href,
  48. filename,
  49. })
  50. }
  51. });
  52. return ns;
  53. }
  54. ret