调整打印文件

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

目前為 2022-08-10 提交的版本,檢視 最新版本

// ==UserScript==
// @name        调整打印文件
// @namespace   print adjust
// @match       https://ctbpsp.com/*
// @match       https://custominfo.cebpubservice.com/*
// @match       https://bulletin.cebpubservice.com/qualifyBulletin/*
// @match       https://bulletin.cebpubservice.com/biddingBulletin/*
// @match       https://bulletin.cebpubservice.com/candidateBulletin/*
// @match       https://bulletin.cebpubservice.com/resultBulletin/*
// @match       https://bulletin.cebpubservice.com/resources/*
// @grant       none
// @run-at      document-idle
// @version     1.3.3
// @author      我爱小熊啊
// @description 感谢油猴中文网的 cxxjackie 大佬指点
// @description 关于 postMessage() 跨域通信,学习地址 https://bbs.tampermonkey.net.cn/thread-2866-1-1.html
// @description cebpubservice.com 文件加载时间较长,遇到未加载完成的,页码输入界面点击取消,文件加载完后,记住页码,刷新输入页码,等待加载完成
// @description 将 ctbpsp.com 与 cebpubservice.com 的等待时间做区分
// @description 自动隐藏 cebpubservice.com 上的二维码广告
// @description 增加对 cebpubservice.com的支持
// @description 中国招标投标公共服务平台公告文件打印调整
// @description 2022/8/3 08:33:33
// @license     MIT
// ==/UserScript==

(function() {
  'use strict';
  // 全国招标公告公示
  // 此网站的 iframe 与主页面同域,均在 bulletin.cebpubservice.com
  if (location.hostname === 'bulletin.cebpubservice.com'){
      window.onload = function(){
        var b = document.getElementsByClassName('PublicAddress')[0];
        b.style.display = 'none';
        var t = setInterval(function(){
          var pdf = document.getElementsByClassName('pdf_wraper')[0];
          var iframe = pdf.children['iframe'];    // 定位 iframe
          var slt = iframe.contentDocument.getElementsByTagName('select');
          // alert('1');
          if(iframe.contentWindow.PDFViewerApplication.pdfDocument != null){
            // alert('2');
            var n = 1 * iframe.contentDocument.getElementById('numPages').textContent[2];
            pdf.style.width = '900px';
            var h = n * 1150 + 'px';
            pdf.style.height = h;
            // slt[0].options[1].selected = true;
            clearInterval(t);
            // alert('3');
          }
        },1000);
      }
    }
  // 中国招标投标公共服务平台
  // postMessage() 通信,感谢油猴中文网的 cxxjackie 大佬指点
  // 此网站的 iframe 与主页面 跨域,主页面在 ctbpsp.com,iframe 在 custominfo.cebpubservice.com
  // 主页面
  if (location.hostname === 'ctbpsp.com') {
    // 监听message事件,取得页码数后调整iframe大小
    window.addEventListener('message', e => {
      if ('numPages' in e.data) {
        var iframe = document.querySelector('.pdf-viewer');
        iframe.width = 900;
        iframe.height = 1150 * e.data.numPages;
      }
    });
  }
  // iframe页面
  if (location.hostname === 'custominfo.cebpubservice.com') {
    // iframe内有一个全局对象PDFViewerApplication,可对其进行劫持来判断pdf加载完毕,也可以用其他方法。
    var _load = window.PDFViewerApplication.load;
    window.PDFViewerApplication.load = function(pdfDocument) {
      // 获取页码数,发送给主页面
      window.top.postMessage({
        numPages: pdfDocument._pdfInfo.numPages
      }, 'https://ctbpsp.com');
      return _load.call(this, pdfDocument);
    };
  }
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址