7 changed files with 283 additions and 135 deletions
@ -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();
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -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…
Reference in new issue