// ==UserScript==
// @name 审核任务书
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match http://gkg.kjt.gxzf.gov.cn/egrantweb/ctrapprove/*
// @grant none
// @require http://incaseofstairs.com/jsdiff/diff.js
// ==/UserScript==
(function() {
'use strict';
// Your code here...
//alert(window.location.href.slice(73,73+14));
var httpRequest = new XMLHttpRequest();
httpRequest.open('POST', 'http://gkg.kjt.gxzf.gov.cn/egrantweb/ctrapprove/list-grid?_search=false&rows=20&page=1&sidx=zhTitle&sord=asc&searchString=', true); //第二步:打开连接
//httpRequest.setRequestHeader("Content-type","application/x-www-form-urlencoded");
httpRequest.send('');//发送请求
httpRequest.onreadystatechange = function () {
if (httpRequest.readyState == 4 && httpRequest.status == 200) {
var domParser = new DOMParser();
var xmlDoc = domParser.parseFromString(httpRequest.responseText, 'text/xml');
var row = xmlDoc.getElementById(window.location.href.slice(73,window.location.href.indexOf("&grantCode=")));
var codes = row.children[6].textContent.match(/\'([^\']*)\'/g);
var httpRequest1 = new XMLHttpRequest();
var url = 'http://gkg.kjt.gxzf.gov.cn/egrantweb/proposal/view-prp?posCodeStr=';
url = url + codes[0].slice(1,-1) + '&grantCodeStr=';
url = url + codes[1].slice(1,-1) + '&subGrantCodeStr=';
url = url + codes[2].slice(1,-1) + '&';
httpRequest1.open('POST', url, true); //第二步:打开连接
//httpRequest.setRequestHeader("Content-type","application/x-www-form-urlencoded");
httpRequest1.send('');//发送请求
httpRequest1.onreadystatechange = function () {
if (httpRequest1.readyState == 4 && httpRequest1.status == 200) {
//alert(httpRequest1.responseText);
console.log(httpRequest1.responseText);
var htmlPrp = domParser.parseFromString(httpRequest1.responseText, 'text/html');
//比对负责人
var zh_persons = document.querySelectorAll("table#zh_persons");
zh_persons = zh_persons[2].querySelectorAll("tbody > tr > td:nth-child(2)");
checkItem(htmlPrp.querySelector("#tab > tr > td:nth-child(3) > a > span"), zh_persons[1]);
//比对项目组成员
var prpPersons = htmlPrp.querySelectorAll("#kfpsn > tbody > tr > td:nth-child(3) > a > span");
for(var i = 2; i < Math.min(zh_persons.length, prpPersons.length + 2); i++){
checkItem(prpPersons[i - 2], zh_persons[i]);
}
var bMajor = document.querySelector("body > div > div:nth-child(3) > table:nth-child(89) > tbody > tr:nth-child(3) > td > font > strong").innerText.indexOf("重大专项") > 0;
var ztmb = document.querySelectorAll("#baseInfo01 > tbody > tr > td")
//比对总体目标
checkText(htmlPrp.querySelector("#baseInfo > tbody > tr:nth-child(8) > td:nth-child(2)"), ztmb[0]);
//比对主要研究内容
if (bMajor){//重大专项和重点研发格式不同
checkText(htmlPrp.querySelector("#baseInfo > tbody > tr:nth-child(9) > td:nth-child(2)"), ztmb[1].nextElementSibling);
}
else{
checkText(htmlPrp.querySelector("#baseInfo > tbody > tr:nth-child(9) > td:nth-child(2)"), ztmb[1]);
}
//技术指标
checkText(htmlPrp.querySelector("#ndmb_list > tbody > tr:nth-child(2) > td:nth-child(3) > pre"), document.querySelector("#ndmb_list > tbody > tr:nth-child(2) > td:nth-child(2)"));
//经济指标
checkText(htmlPrp.querySelector("#ndmb_list > tbody > tr:nth-child(3) > td:nth-child(3) > pre"), document.querySelector("#ndmb_list > tbody > tr:nth-child(3) > td:nth-child(2)"));
//人才指标
checkText(htmlPrp.querySelector("#ndmb_list > tbody > tr:nth-child(4) > td:nth-child(3) > pre"), document.querySelector("#ndmb_list > tbody > tr:nth-child(4) > td:nth-child(2)"));
//其他指标
checkText(htmlPrp.querySelector("#ndmb_list > tbody > tr:nth-child(5) > td:nth-child(3) > pre"), document.querySelector("#ndmb_list > tbody > tr:nth-child(5) > td:nth-child(2)"));
var tdPrp = htmlPrp.querySelectorAll("#cgxy > tbody td");
var tdCtr = document.querySelectorAll("#cgxy > tbody td");
for(i = 0; i < tdPrp.length; i++){
checkItem(tdPrp[i], tdCtr[i]);
}
tdPrp = htmlPrp.querySelectorAll("#fundTab2 > tbody td");
tdCtr = document.querySelectorAll("#fundTab2 > tbody td");
for(i = 0; i < tdPrp.length; i++){
checkItem(tdPrp[i], tdCtr[i + 6]);
}
alert("检查完毕!");
}
}
}
};
function checkItem(itemPrp, itemCtr){
var namePrp = itemPrp.innerText.trim();
var nameCtr= itemCtr.innerText.trim();
if (namePrp != nameCtr){
itemCtr.innerHTML = '' + namePrp + '' + nameCtr +'';
}
}
function checkText(textPrp, textCtr){
var tPrp = textPrp.innerText.trim();
var tCtr= textCtr.innerText.trim();
var diff = JsDiff["diffChars"](tPrp, tCtr);
var fragment = document.createDocumentFragment();
for (var i=0; i < diff.length; i++) {
if (diff[i].added && diff[i + 1] && diff[i + 1].removed) {
var swap = diff[i];
diff[i] = diff[i + 1];
diff[i + 1] = swap;
}
var node;
if (diff[i].removed) {
node = document.createElement('del');
node.style.color = "red"
node.appendChild(document.createTextNode(diff[i].value));
} else if (diff[i].added) {
node = document.createElement('add');
node.style.color = "green"
node.appendChild(document.createTextNode(diff[i].value));
} else {
node = document.createTextNode(diff[i].value);
}
fragment.appendChild(node);
}
textCtr.textContent = '';
textCtr.appendChild(fragment);
}
})();