// ==UserScript== // @name 显示主办意见 // @namespace http://tampermonkey.net/ // @version 0.2 // @description try to take over the world! // @author You // @match http://dzgw.zhbg.kjt.gx.gov/dist/* // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== // @grant none // @run-at document-end // ==/UserScript== (function() { 'use strict'; if (window.location.href.indexOf("http://dzgw.zhbg.kjt.gx.gov/dist/#/forms/wd25/wd25formopinion") < 0){ //如果不是会签会办意见页面就直接返回 return null; } // 延迟1秒设置数据劫持函数 setTimeout(setProxy, 200); // 数据劫持函数 function setProxy(){ if (getHuibanHuiqianItem()){ //如果查找到会办会签标签,下载docguid信息 let httpRequest = new XMLHttpRequest(); httpRequest.open('POST', 'http://dzgw.zhbg.kjt.gx.gov/bgtoa/rest/handleframehbaction/getDataBean?isCommondto=true&action2rest=true&myScript=ShowZhuban', true); //使用myScript=ShowZhuban标记插件的调用 httpRequest.setRequestHeader("Content-type","application/x-www-form-urlencoded"); let params = {inboxGuid:getQueryString('inboxGuid'), outboxGuid:getQueryString('outboxGuid'),rowGuid:getQueryString('rowGuid'),fileType:getQueryString('filetype')}; httpRequest.send("params=" + JSON.stringify(params) + '&cmdParams=%5B%5D'); httpRequest.onreadystatechange = function () { if (httpRequest.readyState == 4 && httpRequest.status == 200) { let data = JSON.parse(httpRequest.responseText); downLoadwdtype(data.custom.docguid); } }; }else { setTimeout(setProxy, 200); } } function downLoadwdtype(docguid){ //根据docguid下载wdtype,然后下载主办意见 let httpRequest = new XMLHttpRequest(); httpRequest.open('POST', 'http://dzgw.zhbg.kjt.gx.gov/bgtoa/rest/handleframeaction/getDataBean?isCommondto=true&action2rest=true&myScript=ShowZhuban', true); //第二步:打开连接 httpRequest.setRequestHeader("Content-type","application/x-www-form-urlencoded"); let params = {guid:docguid, count:"1"}; httpRequest.send("params=" + JSON.stringify(params)); httpRequest.onreadystatechange = function () { if (httpRequest.readyState == 4 && httpRequest.status == 200) { let data = JSON.parse(httpRequest.responseText); downLoadZhuban(docguid, data.custom.wdtype); } }; } function downLoadZhuban(docguid, wdtype){ //根据docguid下载主办意见,主办意见保存在数据的niban和hg字段中 let httpRequest = new XMLHttpRequest(); if (wdtype == 24){ httpRequest.open('POST', 'http://dzgw.zhbg.kjt.gx.gov/bgtoa/rest/wd24form1action/getDataBean?isCommondto=true&action2rest=true&myScript=ShowZhuban', true); //第二步:打开连接 }else{ httpRequest.open('POST', 'http://dzgw.zhbg.kjt.gx.gov/bgtoa/rest/wd25form2action/getDataBean?isCommondto=true&action2rest=true&myScript=ShowZhuban', true); //第二步:打开连接 } httpRequest.setRequestHeader("Content-type","application/x-www-form-urlencoded"); let params = {guid:docguid, archivefiletypeguid:""}; httpRequest.send("params=" + JSON.stringify(params)); httpRequest.onreadystatechange = function () { if (httpRequest.readyState == 4 && httpRequest.status == 200) { let opinion = getOpinionItem(); //生成主办意见页面元素 let data = JSON.parse(httpRequest.responseText); let item = document.createElement('div'); if(opinion){ //如果有区域处意见就将主办意见隐藏 item.innerHTML = "
主办意见:
" + data.custom.niban + "
" + data.custom.hg + "

"; }else{ item.innerHTML = "
主办意见:
" + data.custom.niban + "
" + data.custom.hg + "

"; } //将主办意见页面元素插入到会办会签元素前面 let t = getHuibanHuiqianItem().parentNode; t.parentNode.insertBefore(item, t); //将区域处意见移动到最前面 if(opinion){ let table = opinion.parentNode.parentNode.parentNode; if (opinion.parentNode.parentNode != table.firstChild){ table.insertBefore(opinion.parentNode.parentNode, table.firstChild); } } } }; } //在页面中查找区域处意见元素 function getOpinionItem(){ let xpathExpression = '//li[@class="opinion-item"]/div/span[contains(text(),"成果转化与区域创新处")]'; let result = document.evaluate(xpathExpression, document, null, XPathResult.ANY_TYPE, null); return result.iterateNext(); } //根据页面URL查找返回“会办意见:”或“会签意见”的网页元素 function getHuibanHuiqianItem(){ let opinon = getHuibanHuiqianTypeString(); let xpathExpression = "//a[contains(text(),'" + opinon + "')]"; let result = document.evaluate(xpathExpression, document, null, XPathResult.ANY_TYPE, null); return result.iterateNext(); } //根据页面URL返回“会办意见:”或“会签意见” function getHuibanHuiqianTypeString(){ return getQueryString('filetype') + "意见:"; } //返回页面URL中的参数 function getQueryString(name) { var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i'); var r = window.location.href.substr(1).match(reg); if (r != null) { return decodeURI(r[2]); } return null; } })();