Browse Source

fit:1、浏览器插件优化和完善

master
pengwei 6 months ago
parent
commit
38f5947c17
  1. 22
      src/background/index.ts
  2. 253
      src/contentScript/ajhc/getInfo.ts
  3. 55
      src/contentScript/netComplaint/getInfo.ts
  4. 14
      src/contentScript/submit/getInfo.ts
  5. 8
      src/manifest.ts
  6. 2
      src/options/Options.vue
  7. 64
      src/utils/HtmlUtil.ts

22
src/background/index.ts

@ -8,12 +8,14 @@ import {
supervisionAjhcInfoUrl supervisionAjhcInfoUrl
} from "../../globalConfig"; } from "../../globalConfig";
import { ajax } from "../utils/ajax"; import { ajax } from "../utils/ajax";
import request = chrome.permissions.request
console.log('后台开始运行'); console.log('后台开始运行');
// 当前申请案件办结的outerId // 当前申请案件办结的outerId
let curCompletionOuterId: string | null = null; let curCompletionOuterId: string | null = null;
//捕获请求接口
chrome.webRequest.onBeforeRequest.addListener( chrome.webRequest.onBeforeRequest.addListener(
/* /*
-- --
@ -53,7 +55,8 @@ chrome.webRequest.onBeforeRequest.addListener(
} }
} }
} }
} else if (details.url === "http://11.33.3.4/api/v5/gzzx/ajhc/zjxx") { }
else if (details.url === "http://11.33.3.4/api/v5/gzzx/ajhc/zjxx") {
/* /*
-- --
*/ */
@ -88,7 +91,8 @@ chrome.webRequest.onBeforeRequest.addListener(
} }
} }
} }
} else if (details.url === "http://11.33.3.4/api/v5/gzzx/ajcz") { }
else if (details.url === "http://11.33.3.4/api/v5/gzzx/ajcz") {
/* /*
- -
*/ */
@ -119,7 +123,8 @@ chrome.webRequest.onBeforeRequest.addListener(
} }
} }
} }
} else if (details.url === "http://11.33.3.4/api/v5/gzzx/ajcz/czmx") { }
else if (details.url === "http://11.33.3.4/api/v5/gzzx/ajcz/czmx") {
/* /*
- -
*/ */
@ -156,7 +161,8 @@ chrome.webRequest.onBeforeRequest.addListener(
} }
} }
} }
} else if (details.url.startsWith("http://11.33.3.4/api/v5/gzzx/bj/anqx/")) { }
else if (details.url.startsWith("http://11.33.3.4/api/v5/gzzx/bj/anqx/")) {
/* /*
-id -id
*/ */
@ -207,16 +213,17 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
/* /*
- -
*/ */
console.log('background-data---------')
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === 'sendAjhcData') { if (request.action === 'sendAjhcData') {
console.log('案件核查-投诉受理数据上传')
const { caseNumber, caseSource, complaintTime, reporterName, reporterContact, verifiedObjectUnit, verifiedObjectUnitCode, verifiedObjectName, verifiedObjectPosition, briefCase, organization, complaintIssueNature, acceptanceLevel } = request.data; const { caseNumber, caseSource, complaintTime, reporterName, reporterContact, verifiedObjectUnit, verifiedObjectUnitCode, verifiedObjectName, verifiedObjectPosition, briefCase, organization, complaintIssueNature, acceptanceLevel } = request.data;
// 使用 ajax 方法发送请求 // 使用 ajax 方法发送请求
ajax(supervisionAjhcInfoUrl, { ajax(supervisionAjhcInfoUrl, {
method: 'POST', method: 'POST',
body: { caseNumber, caseSource, complaintTime, reporterName, reporterContact, verifiedObjectUnit, verifiedObjectUnitCode, verifiedObjectName, verifiedObjectPosition, briefCase, organization, complaintIssueNature, acceptanceLevel } body: { caseNumber, caseSource, complaintTime, reporterName, reporterContact, verifiedObjectUnit, verifiedObjectUnitCode, verifiedObjectName, verifiedObjectPosition, briefCase, organization, complaintIssueNature, acceptanceLevel }
}) })
.then(response => response.json())
.then((data: any) => { .then((data: any) => {
console.log('投诉受理数据上传Success:', data); console.log('投诉受理数据上传Success:', data);
sendResponse({ status: 'success', data }); sendResponse({ status: 'success', data });
@ -229,8 +236,9 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
} }
}); });
/* /*
- * -
*/ */
// 监听来自 contentScript 的消息 // 监听来自 contentScript 的消息
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {

253
src/contentScript/ajhc/getInfo.ts

@ -1,113 +1,180 @@
import {ajhcInfoUrl, ajhcSysUrl} from "../../../globalConfig"; import {showNotification} from '../../utils/HtmlUtil'
// // import {ajhcInfoUrl, ajhcSysUrl} from "../../../globalConfig";
// 获取样本源头编号和问题发现时间 // //
function getSampleData(): { sampleSourceNumber: string | null, issueDiscoveryTime: string | null } { // // // 获取样本源头编号和问题发现时间
const elements = Array.from(document.querySelectorAll('div.col.col-6')); // // function getSampleData(): { sampleSourceNumber: string | null, issueDiscoveryTime: string | null } {
let sampleSourceNumber: string | null = null; // // const elements = Array.from(document.querySelectorAll('div.col.col-6'));
let issueDiscoveryTime: string | null = null; // // let sampleSourceNumber: string | null = null;
// // let issueDiscoveryTime: string | null = null;
for (const element of elements) { // //
const labelElement = element.querySelector('label'); // // for (const element of elements) {
const spanElement = element.querySelector('span'); // // const labelElement = element.querySelector('label');
// // const spanElement = element.querySelector('span');
if (labelElement && spanElement) { // //
if (labelElement.textContent === '样本源头编号') { // // if (labelElement && spanElement) {
sampleSourceNumber = spanElement.textContent; // // if (labelElement.textContent === '样本源头编号') {
} else if (labelElement.textContent === '问题发现时间') { // // sampleSourceNumber = spanElement.textContent;
issueDiscoveryTime = spanElement.textContent; // // } else if (labelElement.textContent === '问题发现时间') {
} // // issueDiscoveryTime = spanElement.textContent;
} // // }
} // // }
// // }
return { sampleSourceNumber, issueDiscoveryTime }; // //
} // // return { sampleSourceNumber, issueDiscoveryTime };
// // }
// 发送样本源头编号和问题发现时间到指定接口 // //
function sendData(sampleSourceNumber: string, issueDiscoveryTime: string) { // // // 发送样本源头编号和问题发现时间到指定接口
fetch(ajhcSysUrl + '/data/caseVerif', { // // function sendData(sampleSourceNumber: string, issueDiscoveryTime: string) {
method: 'POST', // // fetch(ajhcSysUrl + '/data/caseVerif', {
headers: { // // method: 'POST',
'Content-Type': 'application/json', // // headers: {
}, // // 'Content-Type': 'application/json',
body: JSON.stringify({ sampleSourceNumber, issueDiscoveryTime }), // // },
}) // // body: JSON.stringify({ sampleSourceNumber, issueDiscoveryTime }),
.then(response => response.json()) // // })
.then(data => console.log('Success:', data)) // // .then(response => response.json())
.catch((error) => console.error('Error:', error)); // // .then(data => console.log('Success:', data))
} // // .catch((error) => console.error('Error:', error));
// // }
// 持续监控页面 // //
function monitorPage() { // // // 持续监控页面
let lastSampleSourceNumber: string | null = null; // // function monitorPage() {
let lastIssueDiscoveryTime: string | null = null; // // let lastSampleSourceNumber: string | null = null;
// // let lastIssueDiscoveryTime: string | null = null;
setInterval(() => { // //
const { sampleSourceNumber, issueDiscoveryTime } = getSampleData(); // // setInterval(() => {
if (sampleSourceNumber && issueDiscoveryTime && // // const { sampleSourceNumber, issueDiscoveryTime } = getSampleData();
(sampleSourceNumber !== lastSampleSourceNumber || issueDiscoveryTime !== lastIssueDiscoveryTime)) { // // if (sampleSourceNumber && issueDiscoveryTime &&
console.log('已找到样本源头编号和问题发现时间:', sampleSourceNumber, issueDiscoveryTime); // // (sampleSourceNumber !== lastSampleSourceNumber || issueDiscoveryTime !== lastIssueDiscoveryTime)) {
sendData(sampleSourceNumber, issueDiscoveryTime); // // console.log('已找到样本源头编号和问题发现时间:', sampleSourceNumber, issueDiscoveryTime);
lastSampleSourceNumber = sampleSourceNumber; // 更新上次检测到的编号 // // sendData(sampleSourceNumber, issueDiscoveryTime);
lastIssueDiscoveryTime = issueDiscoveryTime; // 更新上次检测到的时间 // // lastSampleSourceNumber = sampleSourceNumber; // 更新上次检测到的编号
} // // lastIssueDiscoveryTime = issueDiscoveryTime; // 更新上次检测到的时间
}, 1000); // 每秒检查一次 // // }
} // // }, 1000); // 每秒检查一次
// // }
let isMonitoring = false; // 添加标志位 // //
// // let isMonitoring = false; // 添加标志位
// 使用 MutationObserver 监控 URL 变化 // //
function observeUrlChange() { // // // 使用 MutationObserver 监控 URL 变化
const observer = new MutationObserver(() => { // // function observeUrlChange() {
if (!isMonitoring && window.location.href.includes(ajhcInfoUrl)) { // // const observer = new MutationObserver(() => {
console.log('URL 包含指定路径,开始监控页面'); // // // console.log('打印内容')
monitorPage(); // //
isMonitoring = true; // 设置标志位为 true // // if (!isMonitoring && window.location.href.includes(ajhcInfoUrl)) {
observer.disconnect(); // 断开观察 // // console.log('URL 包含指定路径,开始监控页面');
} // // monitorPage();
checkAndShowWarning(); // // isMonitoring = true; // 设置标志位为 true
}); // // observer.disconnect(); // 断开观察
// // }else{
observer.observe(document.body, { childList: true, subtree: true }); // // return;
} // // }
// // // checkAndShowWarning();
// 执行 URL 监控函数 // // });
observeUrlChange(); // //
// // observer.observe(document.body, { childList: true, subtree: true });
// 创建警告消息的 div 元素 // // }
// //
// // // 执行 URL 监控函数
// // observeUrlChange();
// //
// // // 创建警告消息的 div 元素
function createWarningDiv(): HTMLElement { function createWarningDiv(): HTMLElement {
const warningDiv = document.createElement('div'); const warningDiv = document.createElement('div');
warningDiv.style.position = 'fixed'; warningDiv.style.position = 'fixed';
warningDiv.style.top = '10px'; warningDiv.style.top = '10px';
warningDiv.style.right = '100px'; warningDiv.style.right = '100px';
warningDiv.style.color = 'red'; warningDiv.style.backgroundColor="white";
warningDiv.style.fontWeight = 'bold'; warningDiv.style.border="#ebeef5";
warningDiv.style.boxShadow="0px 0px 12px 0px";
warningDiv.style.padding="20px";
warningDiv.style.fontSize="12px";
warningDiv.style.borderRadius="10px";
warningDiv.style.overflowWrap="break-word";
warningDiv.textContent = '请登录插件,否则数据无法同步至一体化平台!'; warningDiv.textContent = '请登录插件,否则数据无法同步至一体化平台!';
warningDiv.classList.add('crx-login-warning'); warningDiv.classList.add('crx-login-warning');
warningDiv.style.display = 'none'; // 默认隐藏 warningDiv.style.display = 'none'; // 默认隐藏
document.body.appendChild(warningDiv); document.body.appendChild(warningDiv);
return warningDiv; return warningDiv;
} }
// 创建一个通知栏函数
function showNotification(message:string, duration = 3000) {
// 创建通知栏的容器
let notificationDiv = document.createElement('div');
notificationDiv.id = 'notification'; // 设置一个唯一的ID以便后续操作
notificationDiv.style.position = 'fixed';
notificationDiv.style.top = '20px'; // 调整到你希望的位置
notificationDiv.style.right = '20px'; // 调整到你希望的位置
notificationDiv.style.backgroundColor = "white";
notificationDiv.style.border = "1px solid #ebeef5"; // 注意这里应该是border,而不是单独设置四个边的border
notificationDiv.style.boxShadow = "0px 0px 12px rgba(0, 0, 0, 0.1)"; // 增加了rgba颜色值来设置阴影的透明度
notificationDiv.style.padding = "20px";
notificationDiv.style.fontSize = "14px"; // 稍微增大了字体大小以提高可读性
notificationDiv.style.borderRadius = "8px"; // 调整了边框圆角的大小
notificationDiv.style.zIndex = "1000"; // 确保通知栏在其他内容之上
notificationDiv.style.transition = "opacity 0.3s ease, transform 0.3s ease"; // 添加过渡效果
notificationDiv.style.opacity = "1"; // 初始时完全可见
// 创建消息内容
const messageContent = document.createElement('div');
messageContent.textContent = message;
messageContent.style.margin = "0"; // 移除默认的margin
// 将消息内容添加到通知栏容器中
notificationDiv.appendChild(messageContent);
// 将通知栏容器添加到文档中
document.body.appendChild(notificationDiv);
// 设置定时器在指定时间后隐藏通知栏
setTimeout(() => {
notificationDiv.style.opacity = "0"; // 透明度逐渐变为0
notificationDiv.style.transform = "translateY(100%)"; // 向上移动出视线外
setTimeout(() => {
// 完全隐藏后从文档中移除
document.body.removeChild(notificationDiv);
}, 300); // 过渡效果的持续时间应与CSS中设置的transition时间相匹配
}, duration);
}
// 显示警告消息的函数 // 显示警告消息的函数
function showWarningMessage(warningDiv: HTMLElement, showMessage: boolean) { function showWarningMessage(warningDiv: HTMLElement, showMessage: boolean) {
warningDiv.style.display = showMessage ? 'block' : 'none'; warningDiv.style.display = showMessage ? 'block' : 'none';
} }
// 检查并显示警告的函数 // // // 检查并显示警告的函数
function checkAndShowWarning() { function checkAndShowWarning() {
const warningDiv = createWarningDiv(); // 创建警告 div const warningDiv = createWarningDiv(); // 创建警告 div
setInterval(() => { // showWarningMessage(warningDiv, true); // 显示警告
console.log('检查并显示警告'); showNotification('xxx的数据已抓取成功',3000)
if (window.location.href.includes(ajhcSysUrl)) {
chrome.storage.local.get(['srcAuthToken'], (result) => {
const token = result.srcAuthToken;
if (!token) {
console.log('未找到 srcAuthToken');
showWarningMessage(warningDiv, true); // 显示警告
} else {
showWarningMessage(warningDiv, false); // 隐藏警告
}
});
}
}, 5000); // 每5秒检查一次
} }
checkAndShowWarning()
//
// import { ajhcInProgressUrl } from '../../../globalConfig'
//
// // function checkButtonAndExecute() {
// //
// //
// // setInterval(() => {
// //
// // chrome.runtime.sendMessage({action: 'ces'}, (response) => {
// // console.log(response)
// // });
// // // 发送消息到 popup
// // }, 5000); // 每2秒检查一次
// // }
//
//
//
// // chrome.
//
//
//
// // 执行定期检查函数
// checkButtonAndExecute();
//
//
//

55
src/contentScript/netComplaint/getInfo.ts

@ -1,5 +1,5 @@
import {ajhcOutInfoUrl} from "../../../globalConfig"; import {ajhcOutInfoUrl} from "../../../globalConfig";
import {showNotification} from '../../utils/HtmlUtil'
/* /*
*/ */
@ -20,23 +20,19 @@ function getSampleData(): { caseNumber: string | null, caseSource: string | null
// 获取基本信息栏中的数据 // 获取基本信息栏中的数据
const basicInfoTitle = findElementByText('div.ant-card-head-title', '基本信息'); const basicInfoTitle = findElementByText('div.ant-card-head-title', '基本信息');
console.log('获取到basicInfoTitle' + basicInfoTitle);
let caseNumber = null; let caseNumber = null;
let caseSource = null; let caseSource = null;
let complaintTime = null; let complaintTime = null;
if (basicInfoTitle) { if (basicInfoTitle) {
const basicInfoSection = basicInfoTitle.closest('.ant-card')?.querySelector('.ant-card-body'); const basicInfoSection = basicInfoTitle.closest('.ant-card')?.querySelector('.ant-card-body');
console.log('获取到basicInfoSection' + basicInfoSection);
if (basicInfoSection) { if (basicInfoSection) {
const caseNumberLabel = basicInfoSection.querySelector('div.ant-col.ant-form-item-label:has(label[title="案件编号"])'); const caseNumberLabel = basicInfoSection.querySelector('div.ant-col.ant-form-item-label:has(label[title="案件编号"])');
caseNumber = caseNumberLabel?.nextElementSibling?.querySelector('span.ant-form-item-children span')?.textContent || null; caseNumber = caseNumberLabel?.nextElementSibling?.querySelector('span.ant-form-item-children span')?.textContent || null;
console.log('获取到caseNumber' + caseNumber);
const caseSourceLabel = basicInfoSection.querySelector('div.ant-col.ant-form-item-label:has(label[title="案件来源"])'); const caseSourceLabel = basicInfoSection.querySelector('div.ant-col.ant-form-item-label:has(label[title="案件来源"])');
caseSource = caseSourceLabel?.nextElementSibling?.querySelector('span.ant-form-item-children')?.textContent || null; caseSource = caseSourceLabel?.nextElementSibling?.querySelector('span.ant-form-item-children')?.textContent || null;
console.log('获取到caseSource' + caseSource);
const complaintTimeLabel = basicInfoSection.querySelector('div.ant-col.ant-form-item-label:has(label[title="投诉时间"])'); const complaintTimeLabel = basicInfoSection.querySelector('div.ant-col.ant-form-item-label:has(label[title="投诉时间"])');
complaintTime = complaintTimeLabel?.nextElementSibling?.querySelector('span.ant-form-item-children')?.textContent || null; complaintTime = complaintTimeLabel?.nextElementSibling?.querySelector('span.ant-form-item-children')?.textContent || null;
console.log('获取到complaintTime' + complaintTime);
} else { } else {
console.log('basicInfoSection没有找到'); console.log('basicInfoSection没有找到');
} }
@ -50,14 +46,14 @@ function getSampleData(): { caseNumber: string | null, caseSource: string | null
let reporterContact = null; let reporterContact = null;
if (reporterInfoTitle) { if (reporterInfoTitle) {
const reporterInfoSection = reporterInfoTitle.closest('.ant-card')?.querySelector('.ant-card-body'); const reporterInfoSection = reporterInfoTitle.closest('.ant-card')?.querySelector('.ant-card-body');
console.log('获取到reporterInfoSection' + reporterInfoSection);
if (reporterInfoSection) { if (reporterInfoSection) {
const reporterNameLabel = reporterInfoSection.querySelector('div.ant-col.ant-form-item-label:has(label[title="举报人姓名"])'); const reporterNameLabel = reporterInfoSection.querySelector('div.ant-col.ant-form-item-label:has(label[title="举报人姓名"])');
reporterName = reporterNameLabel?.nextElementSibling?.querySelector('span.ant-form-item-children')?.textContent || null; reporterName = reporterNameLabel?.nextElementSibling?.querySelector('span.ant-form-item-children')?.textContent || null;
console.log('获取到reporterName' + reporterName);
const reporterContactLabel = reporterInfoSection.querySelector('div.ant-col.ant-form-item-label:has(label[title="联系方式"])'); const reporterContactLabel = reporterInfoSection.querySelector('div.ant-col.ant-form-item-label:has(label[title="联系方式"])');
reporterContact = reporterContactLabel?.nextElementSibling?.querySelector('span.ant-form-item-children')?.textContent || null; reporterContact = reporterContactLabel?.nextElementSibling?.querySelector('span.ant-form-item-children')?.textContent || null;
console.log('获取到reporterContact' + reporterContact);
} else { } else {
console.log('reporterInfoSection没有找到'); console.log('reporterInfoSection没有找到');
} }
@ -73,11 +69,10 @@ function getSampleData(): { caseNumber: string | null, caseSource: string | null
let verifiedObjectPosition = null; let verifiedObjectPosition = null;
if (verifiedObjectTitle) { if (verifiedObjectTitle) {
const verifiedObjectSection = verifiedObjectTitle.closest('.ant-card')?.querySelector('.ant-card-body'); const verifiedObjectSection = verifiedObjectTitle.closest('.ant-card')?.querySelector('.ant-card-body');
console.log('获取到verifiedObjectSection' + verifiedObjectSection);
if (verifiedObjectSection) { if (verifiedObjectSection) {
const verifiedObjectUnitLabel = verifiedObjectSection.querySelector('div.ant-col.ant-form-item-label:has(label[title="单位"])'); const verifiedObjectUnitLabel = verifiedObjectSection.querySelector('div.ant-col.ant-form-item-label:has(label[title="单位"])');
verifiedObjectUnit = verifiedObjectUnitLabel?.nextElementSibling?.querySelector('span.ant-form-item-children')?.textContent || null; verifiedObjectUnit = verifiedObjectUnitLabel?.nextElementSibling?.querySelector('span.ant-form-item-children')?.textContent || null;
console.log('获取到verifiedObjectUnit' + verifiedObjectUnit);
const verifiedObjectUnitCodeString = verifiedObjectUnitLabel?.nextElementSibling?.querySelector('span.ant-form-item-children a')?.getAttribute('href') || null; const verifiedObjectUnitCodeString = verifiedObjectUnitLabel?.nextElementSibling?.querySelector('span.ant-form-item-children a')?.getAttribute('href') || null;
if (verifiedObjectUnitCodeString !== null) { if (verifiedObjectUnitCodeString !== null) {
const verifiedObjectUnitCodeMatch = verifiedObjectUnitCodeString.match(/bjbdw_(\d+)/); const verifiedObjectUnitCodeMatch = verifiedObjectUnitCodeString.match(/bjbdw_(\d+)/);
@ -85,13 +80,10 @@ function getSampleData(): { caseNumber: string | null, caseSource: string | null
verifiedObjectUnitCode = verifiedObjectUnitCodeMatch[1]; verifiedObjectUnitCode = verifiedObjectUnitCodeMatch[1];
} }
} }
console.log('获取到verifiedObjectUnitCode' + verifiedObjectUnitCode);
const verifiedObjectNameLabel = verifiedObjectSection.querySelector('div.ant-col.ant-form-item-label:has(label[title="姓名"])'); const verifiedObjectNameLabel = verifiedObjectSection.querySelector('div.ant-col.ant-form-item-label:has(label[title="姓名"])');
verifiedObjectName = verifiedObjectNameLabel?.nextElementSibling?.querySelector('span.ant-form-item-children')?.textContent || null; verifiedObjectName = verifiedObjectNameLabel?.nextElementSibling?.querySelector('span.ant-form-item-children')?.textContent || null;
console.log('获取到verifiedObjectName' + verifiedObjectName);
const verifiedObjectPositionLabel = verifiedObjectSection.querySelector('div.ant-col.ant-form-item-label:has(label[title="职务"])'); const verifiedObjectPositionLabel = verifiedObjectSection.querySelector('div.ant-col.ant-form-item-label:has(label[title="职务"])');
verifiedObjectPosition = verifiedObjectPositionLabel?.nextElementSibling?.querySelector('span.ant-form-item-children')?.textContent || null; verifiedObjectPosition = verifiedObjectPositionLabel?.nextElementSibling?.querySelector('span.ant-form-item-children')?.textContent || null;
console.log('获取到verifiedObjectPosition' + verifiedObjectPosition);
} else { } else {
console.log('verifiedObjectSection没有找到'); console.log('verifiedObjectSection没有找到');
} }
@ -105,19 +97,16 @@ function getSampleData(): { caseNumber: string | null, caseSource: string | null
let briefCase = null; let briefCase = null;
if (complaintCaseTitle) { if (complaintCaseTitle) {
const complaintCaseSection = complaintCaseTitle.closest('.ant-card')?.querySelector('.ant-card-body'); const complaintCaseSection = complaintCaseTitle.closest('.ant-card')?.querySelector('.ant-card-body');
console.log('获取到complaintCaseSection' + complaintCaseSection);
if (complaintCaseSection) { if (complaintCaseSection) {
const organizationLabel = complaintCaseSection.querySelector('div.ant-col.ant-col-7.org-label'); const organizationLabel = complaintCaseSection.querySelector('div.ant-col.ant-col-7.org-label');
if (organizationLabel && organizationLabel.textContent && organizationLabel.textContent.trim() === "组织机构:") { if (organizationLabel && organizationLabel.textContent && organizationLabel.textContent.trim() === "组织机构:") {
organization = organizationLabel.nextElementSibling?.textContent || null; organization = organizationLabel.nextElementSibling?.textContent || null;
console.log('获取到organization: ' + organization);
} else { } else {
console.log('未找到"组织机构"标签'); console.log('未找到"组织机构"标签');
} }
const briefCaseLabel = complaintCaseSection.querySelector('div.ant-col.ant-col-5 span'); const briefCaseLabel = complaintCaseSection.querySelector('div.ant-col.ant-col-5 span');
if (briefCaseLabel && briefCaseLabel.textContent && briefCaseLabel.textContent.trim() === "简要案情:") { if (briefCaseLabel && briefCaseLabel.textContent && briefCaseLabel.textContent.trim() === "简要案情:") {
briefCase = briefCaseLabel?.parentElement?.nextElementSibling?.textContent || null; briefCase = briefCaseLabel?.parentElement?.nextElementSibling?.textContent || null;
console.log('获取到briefCase:', briefCase);
} else { } else {
console.log('未找到"简要案情"标签'); console.log('未找到"简要案情"标签');
} }
@ -133,11 +122,11 @@ function getSampleData(): { caseNumber: string | null, caseSource: string | null
let complaintIssueNature = null; let complaintIssueNature = null;
if (questionTypeTitle) { if (questionTypeTitle) {
const questionTypeSection = questionTypeTitle.closest('.ant-card')?.querySelector('.ant-card-body'); const questionTypeSection = questionTypeTitle.closest('.ant-card')?.querySelector('.ant-card-body');
console.log('获取到questionTypeSection' + questionTypeSection);
if (questionTypeSection) { if (questionTypeSection) {
const complaintIssueNatureLabel = questionTypeSection.querySelector('div.ant-col.ant-form-item-label:has(label[title="投诉问题性质"])'); const complaintIssueNatureLabel = questionTypeSection.querySelector('div.ant-col.ant-form-item-label:has(label[title="投诉问题性质"])');
complaintIssueNature = complaintIssueNatureLabel?.nextElementSibling?.querySelector('ul.ant-select-selection__rendered')?.textContent || null; complaintIssueNature = complaintIssueNatureLabel?.nextElementSibling?.querySelector('ul.ant-select-selection__rendered')?.textContent || null;
console.log('获取到complaintIssueNature' + complaintIssueNature);
} else { } else {
console.log('questionTypeSection没有找到'); console.log('questionTypeSection没有找到');
} }
@ -150,11 +139,11 @@ function getSampleData(): { caseNumber: string | null, caseSource: string | null
let acceptanceLevel = null; let acceptanceLevel = null;
if (acceptanceOpinionTitle) { if (acceptanceOpinionTitle) {
const acceptanceOpinionSection = acceptanceOpinionTitle.closest('.ant-card')?.querySelector('.ant-card-body'); const acceptanceOpinionSection = acceptanceOpinionTitle.closest('.ant-card')?.querySelector('.ant-card-body');
console.log('获取到acceptanceOpinionSection' + acceptanceOpinionSection);
if (acceptanceOpinionSection) { if (acceptanceOpinionSection) {
const acceptanceLevelLabel = acceptanceOpinionSection.querySelector('div.ant-col.ant-form-item-label:has(label.ant-form-item-required[title="拟办方式"])'); const acceptanceLevelLabel = acceptanceOpinionSection.querySelector('div.ant-col.ant-form-item-label:has(label.ant-form-item-required[title="拟办方式"])');
acceptanceLevel = acceptanceLevelLabel?.nextElementSibling?.querySelector('label.ant-radio-wrapper.ant-radio-wrapper-checked')?.textContent || "本级办理"; acceptanceLevel = acceptanceLevelLabel?.nextElementSibling?.querySelector('label.ant-radio-wrapper.ant-radio-wrapper-checked')?.textContent || "本级办理";
console.log('获取到acceptanceLevel' + acceptanceLevel);
} else { } else {
console.log('acceptanceOpinionSection没有找到'); console.log('acceptanceOpinionSection没有找到');
} }
@ -165,14 +154,25 @@ function getSampleData(): { caseNumber: string | null, caseSource: string | null
return { caseNumber, caseSource, complaintTime, reporterName, reporterContact, verifiedObjectUnit, verifiedObjectUnitCode, verifiedObjectName, verifiedObjectPosition, briefCase, organization, complaintIssueNature, acceptanceLevel }; return { caseNumber, caseSource, complaintTime, reporterName, reporterContact, verifiedObjectUnit, verifiedObjectUnitCode, verifiedObjectName, verifiedObjectPosition, briefCase, organization, complaintIssueNature, acceptanceLevel };
} }
/* /*
*/ */
// 发送样本源头编号和问题发现时间到指定接口 // 发送样本源头编号和问题发现时间到指定接口
function sendData(caseNumber: string | null, caseSource: string | null, complaintTime: string | null, reporterName: string | null, reporterContact: string | null, verifiedObjectUnit: string | null, verifiedObjectUnitCode: string | null, verifiedObjectName: string | null, verifiedObjectPosition: string | null, briefCase: string | null, organization: string | null, complaintIssueNature: string | null, acceptanceLevel: string | null) { function sendData(caseNumber: string | null, caseSource: string | null, complaintTime: string | null, reporterName: string | null, reporterContact: string | null, verifiedObjectUnit: string | null, verifiedObjectUnitCode: string | null, verifiedObjectName: string | null, verifiedObjectPosition: string | null, briefCase: string | null, organization: string | null, complaintIssueNature: string | null, acceptanceLevel: string | null) {
// 发送消息到 background 脚本 // 发送消息到 background 脚本
chrome.runtime.sendMessage({ action: 'sendAjhcData', data: { caseNumber, caseSource, complaintTime, reporterName, reporterContact, verifiedObjectUnit, verifiedObjectUnitCode, verifiedObjectName, verifiedObjectPosition, briefCase, organization, complaintIssueNature, acceptanceLevel } }, response => { chrome.runtime.sendMessage({ action: "sendAjhcData", data: { caseNumber, caseSource, complaintTime, reporterName, reporterContact, verifiedObjectUnit, verifiedObjectUnitCode, verifiedObjectName, verifiedObjectPosition, briefCase, organization, complaintIssueNature, acceptanceLevel } },
console.log('获取投诉受理数据结果:', response); response => {
console.log(response)
if(response.status === 'success' ){
console.log('获取投诉受理数据结果:', response);
}else{
console.log("获取投诉受理数据失败")
}
}); });
} }
@ -181,6 +181,7 @@ function checkButtonAndExecute() {
let confirmButtonClickListener: () => void; let confirmButtonClickListener: () => void;
setInterval(() => { setInterval(() => {
const confirmButton = Array.from(document.querySelectorAll('button.ant-btn.ant-btn-primary')) const confirmButton = Array.from(document.querySelectorAll('button.ant-btn.ant-btn-primary'))
.find(button => button.querySelector('span')?.textContent === '确 认'); .find(button => button.querySelector('span')?.textContent === '确 认');
if (confirmButton && window.location.href.includes(ajhcOutInfoUrl)) { if (confirmButton && window.location.href.includes(ajhcOutInfoUrl)) {
@ -191,17 +192,23 @@ function checkButtonAndExecute() {
confirmButton.removeEventListener('click', confirmButtonClickListener); confirmButton.removeEventListener('click', confirmButtonClickListener);
} }
// 定义新的事件监听器并添加 // 定义新的事件监听器并添加
confirmButtonClickListener = () => { confirmButtonClickListener = () => {
const { caseNumber, caseSource, complaintTime, reporterName, reporterContact, verifiedObjectUnit, verifiedObjectUnitCode, verifiedObjectName, verifiedObjectPosition, briefCase, organization, complaintIssueNature, acceptanceLevel } = getSampleData(); const { caseNumber, caseSource, complaintTime, reporterName, reporterContact, verifiedObjectUnit, verifiedObjectUnitCode, verifiedObjectName, verifiedObjectPosition, briefCase, organization, complaintIssueNature, acceptanceLevel } = getSampleData();
console.log('已找到案件信息:', caseNumber, caseSource, complaintTime, reporterName, reporterContact, verifiedObjectUnit, verifiedObjectUnitCode, verifiedObjectName, verifiedObjectPosition, briefCase, organization, complaintIssueNature, acceptanceLevel); console.log('已找到案件信息:', caseNumber, caseSource, complaintTime, reporterName, reporterContact, verifiedObjectUnit, verifiedObjectUnitCode, verifiedObjectName, verifiedObjectPosition, briefCase, organization, complaintIssueNature, acceptanceLevel);
showNotification(reporterName+"数据已抓取成功")
sendData(caseNumber, caseSource, complaintTime, reporterName, reporterContact, verifiedObjectUnit, verifiedObjectUnitCode, verifiedObjectName, verifiedObjectPosition, briefCase, organization, complaintIssueNature, acceptanceLevel); sendData(caseNumber, caseSource, complaintTime, reporterName, reporterContact, verifiedObjectUnit, verifiedObjectUnitCode, verifiedObjectName, verifiedObjectPosition, briefCase, organization, complaintIssueNature, acceptanceLevel);
}; };
//绑定点击事件
confirmButton.addEventListener('click', confirmButtonClickListener); confirmButton.addEventListener('click', confirmButtonClickListener);
} }
}, 1000); // 每1秒检查一次 }, 1000); // 每1秒检查一次
} }
// 执行定期检查函数 // 执行定期检查函数
checkButtonAndExecute(); checkButtonAndExecute();

14
src/contentScript/submit/getInfo.ts

@ -60,24 +60,27 @@ function checkAndShowWarning() {
checkAndShowWarning(); // 在脚本加载时立即调用 checkAndShowWarning checkAndShowWarning(); // 在脚本加载时立即调用 checkAndShowWarning
/* /*
ID列表上传 ID列表上传 -- -
*/ */
let windowOn: boolean = false; let windowOn: boolean = false;
function checkAndCallUpdateDataRowKeys() { function checkAndCallUpdateDataRowKeys() {
if (window.location.href.includes(ajhcInProgressUrl)) { if (window.location.href.includes(ajhcInProgressUrl)) {
const currentResult = document.querySelector('div.antd-pro-pages-workcenter-ajhc-ajhc-hcbg-index-hc');
updateDataRowKeys(); updateDataRowKeys();
if (currentResult !== null && !windowOn) {
const currentResult = document.querySelector('div.antd-pro-pages-workcenter-ajhc-ajhc-hcbg-index-hc');
if (currentResult !== null && !windowOn) {
console.log('currentResult',currentResult)
//todo 不知道干啥,前面的人写的,先保留看看,console迁移到这里,减少打印的数量
} }
windowOn = currentResult !== null; windowOn = currentResult !== null;
} }
} }
//持续监听ID列表
setInterval(checkAndCallUpdateDataRowKeys, 1000); setInterval(checkAndCallUpdateDataRowKeys, 1000);
const sentData = new Set<string>(); // 用于存储已经发送过的 caseNumber const sentData = new Set<string>(); // 用于存储已经发送过的 caseNumber
//案件列表{ 案件编号 caseNumber,outerId } id 列表上传
function updateDataRowKeys() { function updateDataRowKeys() {
const scroll = document.querySelector('div.ant-table-scroll'); const scroll = document.querySelector('div.ant-table-scroll');
if (!scroll) { if (!scroll) {
@ -90,9 +93,9 @@ function updateDataRowKeys() {
return { caseNumber, outerId }; return { caseNumber, outerId };
}) })
.filter(({ caseNumber }) => caseNumber !== null && caseNumber !== undefined && !sentData.has(caseNumber)); // 过滤掉已经发送过的 caseNumber .filter(({ caseNumber }) => caseNumber !== null && caseNumber !== undefined && !sentData.has(caseNumber)); // 过滤掉已经发送过的 caseNumber
// 检查 dataRowKeyMaps 是否为空 // 检查 dataRowKeyMaps 是否为空
if (dataRowKeyMaps.length > 0) { if (dataRowKeyMaps.length > 0) {
console.log('dataRowKeyMaps',dataRowKeyMaps)
chrome.runtime.sendMessage({ action: 'fetchDataRowKeys', data: dataRowKeyMaps }, response => { chrome.runtime.sendMessage({ action: 'fetchDataRowKeys', data: dataRowKeyMaps }, response => {
console.log('上传ID列表结果:', response); console.log('上传ID列表结果:', response);
if (response.status === "success") { if (response.status === "success") {
@ -174,4 +177,3 @@ function checkButtonAndExecute() {
checkButtonAndExecute(); checkButtonAndExecute();

8
src/manifest.ts

@ -63,10 +63,10 @@ export default defineManifest({
}, },
], ],
permissions: [ permissions: [
'alarms', 'alarms', //定时器
'sidePanel', 'sidePanel',//侧边栏
'storage', 'storage', //本地存储
'webRequest', 'webRequest',//web请求
'webRequestBlocking', 'webRequestBlocking',
'activeTab', 'activeTab',
'notifications', 'notifications',

2
src/options/Options.vue

@ -2,7 +2,7 @@
import { ref, onMounted } from 'vue' import { ref, onMounted } from 'vue'
const countSync = ref(0) const countSync = ref(0)
const link = ref('https://github.com/guocaoyi/create-chrome-ext') // const link = ref('https://github.com/guocaoyi/create-chrome-ext')
onMounted(() => { onMounted(() => {
chrome.storage.sync.get(['count'], (result) => { chrome.storage.sync.get(['count'], (result) => {

64
src/utils/HtmlUtil.ts

@ -0,0 +1,64 @@
/**
*
* @param message
* @param duration 3
* */
export const showNotification= (message:string, duration = 3000)=> {
// 创建通知栏的容器
let notificationDiv = document.createElement('div');
notificationDiv.id = 'notification'; // 设置一个唯一的ID以便后续操作
notificationDiv.style.position = 'fixed';
notificationDiv.style.top = '20px'; // 调整到你希望的位置
notificationDiv.style.right = '20px'; // 调整到你希望的位置
notificationDiv.style.backgroundColor = "white";
notificationDiv.style.border = "1px solid #ebeef5"; // 注意这里应该是border,而不是单独设置四个边的border
notificationDiv.style.boxShadow = "0px 0px 12px rgba(0, 0, 0, 0.1)"; // 增加了rgba颜色值来设置阴影的透明度
notificationDiv.style.padding = "20px";
notificationDiv.style.fontSize = "14px"; // 稍微增大了字体大小以提高可读性
notificationDiv.style.borderRadius = "8px"; // 调整了边框圆角的大小
notificationDiv.style.zIndex = "1000"; // 确保通知栏在其他内容之上
notificationDiv.style.transition = "opacity 0.3s ease, transform 0.3s ease"; // 添加过渡效果
notificationDiv.style.opacity = "1"; // 初始时完全可见
// 创建消息内容
const messageContent = document.createElement('div');
messageContent.textContent = message;
messageContent.style.margin = "0"; // 移除默认的margin
// 将消息内容添加到通知栏容器中
notificationDiv.appendChild(messageContent);
// 将通知栏容器添加到文档中
document.body.appendChild(notificationDiv);
// 设置定时器在指定时间后隐藏通知栏
setTimeout(() => {
notificationDiv.style.opacity = "0"; // 透明度逐渐变为0
notificationDiv.style.transform = "translateY(100%)"; // 向上移动出视线外
setTimeout(() => {
// 完全隐藏后从文档中移除
document.body.removeChild(notificationDiv);
}, 300); // 过渡效果的持续时间应与CSS中设置的transition时间相匹配
}, duration);
}
/**
*
* @param div
* @param content
* @param type
* */
export const addHintSpan=(div:HTMLDivElement,content="已同步",type="success")=>{
let message = document.createElement('span');
message.style.padding="2px";
message.style.display="inline-block";
message.style.color="white";
message.style.borderRadius="5px";
if(type==="success"){
message.style.border="1px solid blue";
message.style.backgroundColor="blue";
}else{
message.style.border="1px solid red";
message.style.backgroundColor="red";
}
message.textContent=content;
div.appendChild(message);
}
Loading…
Cancel
Save