调整打印文件

感谢油猴中文网的 cxxjackie 大佬指点

  1. // ==UserScript==
  2. // @name 调整打印文件
  3. // @namespace print adjust
  4. // @match https://ctbpsp.com/*
  5. // @match https://custominfo.cebpubservice.com/*
  6. // @match https://bulletin.cebpubservice.com/qualifyBulletin/*
  7. // @match https://bulletin.cebpubservice.com/biddingBulletin/*
  8. // @match https://bulletin.cebpubservice.com/candidateBulletin/*
  9. // @match https://bulletin.cebpubservice.com/resultBulletin/*
  10. // @match https://bulletin.cebpubservice.com/resources/*
  11. // @match https://bulletin.cebpubservice.com/changeBulletin/*
  12. // @grant none
  13. // @run-at document-idle
  14. // @version 1.3.6
  15. // @author 我爱小熊啊
  16. // @description 感谢油猴中文网的 cxxjackie 大佬指点
  17. // @description 增加更正公告打印支持
  18. // @description 关于 postMessage() 跨域通信,学习地址 https://bbs.tampermonkey.net.cn/thread-2866-1-1.html
  19. // @description cebpubservice.com 文件加载时间较长,遇到未加载完成的,页码输入界面点击取消,文件加载完后,记住页码,刷新输入页码,等待加载完成
  20. // @description 将 ctbpsp.com 与 cebpubservice.com 的等待时间做区分
  21. // @description 自动隐藏 cebpubservice.com 上的二维码广告
  22. // @description 增加对 cebpubservice.com的支持
  23. // @description 中国招标投标公共服务平台公告文件打印调整
  24. // @description 2022/8/3 08:33:33
  25. // @license MIT
  26. // @homepageURL https://greasyfork.org/zh-CN/scripts/448818-%E8%B0%83%E6%95%B4%E6%89%93%E5%8D%B0%E6%96%87%E4%BB%B6
  27. // ==/UserScript==
  28.  
  29. (function() {
  30. 'use strict';
  31. // 中国招标公告公示
  32. // 此网站的 iframe 与主页面同域,均在 bulletin.cebpubservice.com
  33. if (location.hostname === 'bulletin.cebpubservice.com'){
  34. var b = document.getElementsByClassName('PublicAddress')[0];
  35. b.style.display = 'none';
  36. var pdf = document.getElementsByClassName('pdf_wraper')[0];
  37. var iframe = pdf.children[0]; // 定位 iframe,pdf.children['iframe'];
  38.  
  39. var t = setInterval(function(){
  40. // alert('1');
  41. // if(iframe.contentWindow.PDFViewerApplication.pdfDocument != null){
  42. if(iframe.contentWindow.PDFViewerApplication.downloadComplete){
  43. // alert('2');
  44. var n = 1 * iframe.contentDocument.getElementById('numPages').textContent[2];
  45. pdf.style.width = '900px';
  46. var h = n * 1150 + 'px';
  47. pdf.style.height = h;
  48. // slt[0].options[1].selected = true;
  49. clearInterval(t);
  50. // alert('3');
  51. }
  52. },1000);
  53. }
  54. // 全国招标投标公共服务平台
  55. // postMessage() 通信,感谢油猴中文网的 cxxjackie 大佬指点
  56. // 此网站的 iframe 与主页面 跨域,主页面在 ctbpsp.com,iframe 在 custominfo.cebpubservice.com
  57. // 主页面
  58. if (location.hostname === 'ctbpsp.com') {
  59. // 监听message事件,取得页码数后调整iframe大小
  60. window.addEventListener('message', e => {
  61. if ('numPages' in e.data) {
  62. document.querySelector('.loadingqrCode').style.display = 'none';
  63. var iframe = document.querySelector('.pdf-viewer');
  64. iframe.width = 900;
  65. iframe.height = 1150 * e.data.numPages;
  66. }
  67. });
  68. }
  69. // iframe页面
  70. if (location.hostname === 'custominfo.cebpubservice.com') {
  71. // iframe内有一个全局对象PDFViewerApplication,可对其进行劫持来判断pdf加载完毕,也可以用其他方法。
  72. var _load = window.PDFViewerApplication.load;
  73. window.PDFViewerApplication.load = function(pdfDocument) {
  74. // 获取页码数,发送给主页面
  75. window.top.postMessage({
  76. numPages: pdfDocument._pdfInfo.numPages
  77. }, 'https://ctbpsp.com');
  78. return _load.call(this, pdfDocument);
  79. };
  80. }
  81. })();