// ==UserScript== // @name OFD预览 // @namespace http://tampermonkey.net/ // @version 0.1 // @description try to take over the world! // @author You // @match http://*.zhbg.kjt.gx.gov/* // @require file://d:\OfdParser.js // @require file://d:\ofd.js // @grant none // ==/UserScript== (function() { 'use strict'; function findVue(el){ var child = [window._Vue]; while (child.length > 0){ var n = child.pop(); if(n.$el === el){ return n; } n.$children.forEach(function(i){child.push(i)}) } } //查找加载ofd失败后生成的div if (!document.querySelector('embed[type="application/ofd"] ')){ throw new Error('Whoops!')} //查找ofd文件的标识 var attachGuid = findVue(document.querySelector("div#OFD").parentNode.parentNode).attachguid; if (!attachGuid){ throw new Error('Whoops!')} var httpRequest = new XMLHttpRequest(); httpRequest.open('POST', 'http://dzgw.zhbg.kjt.gx.gov/bgtoa/rest/frame/base/attach/attachAction/getContent?isCommondto=true&attachGuid='+ attachGuid + '&contentType=undefined&fileName=undefined&t=1649214814841', true); //第二步:打开连接 httpRequest.responseType = "arraybuffer"; httpRequest.send(''); httpRequest.onreadystatechange = function () { if (httpRequest.readyState == 4 && httpRequest.status == 200) { //alert(httpRequest.responseType); ofd.parseOfdDocument({ ofd: httpRequest.response, success: function (res) { var divArray = []; var divs = ofd.renderOfd(res.data.ofd, 0); var OfdView = document.querySelector("div#OFD"); while (OfdView.firstChild) { OfdView.removeChild (OfdView.firstChild); } for(var i = 0; i < divs.length; i++){ OfdView.appendChild(divs[i]); } } }) } } })();