1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
|
(function() { 'use strict';
const DINGTALK_CONFIG = { webhookBase: 'https://oapi.dingtalk.com/robot/send?access_token=填写webhooktoken', secret: '填写加签秘钥' };
const TARGET_POPUP_XPATH = '//div[contains(@class, "qr-code") and @title]'; const BACKUP_POPUP_XPATH = '//*[@id="app"]/div/div[2]/div[1]/div[4]/div/div[2]/div/div[2]/div[1]//div[contains(@class, "qr-code")]';
let popupDetected = false; let lastDetectedTitle = '';
function loadCryptoJS() { return new Promise((resolve) => { if (typeof CryptoJS !== 'undefined') { resolve(); return; } const script = document.createElement('script'); script.src = 'https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js'; script.onload = resolve; script.onerror = resolve; document.head.appendChild(script); }); }
function generateDingTalkSignature(secret) { const timestamp = Date.now(); const stringToSign = timestamp + '\n' + secret; if (typeof CryptoJS !== 'undefined') { try { const sign = CryptoJS.enc.Base64.stringify(CryptoJS.HmacSHA256(stringToSign, secret)); const urlSafeSign = encodeURIComponent(sign); return Promise.resolve({ timestamp: timestamp, sign: urlSafeSign }); } catch (error) { console.error('CryptoJS签名错误:', error); } } return Promise.resolve({ timestamp: timestamp, sign: 'direct' }); }
function getElementByXpath(path) { return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; }
function findQrCodeWithTitle() { let qrCodeElement = getElementByXpath(TARGET_POPUP_XPATH); if (qrCodeElement) { console.log('通过主XPath找到二维码元素:', qrCodeElement); return qrCodeElement; } qrCodeElement = getElementByXpath(BACKUP_POPUP_XPATH); if (qrCodeElement) { console.log('通过备用XPath找到二维码元素:', qrCodeElement); if (qrCodeElement.hasAttribute('title')) { return qrCodeElement; } } qrCodeElement = document.querySelector('.qr-code[title]'); if (qrCodeElement) { console.log('通过CSS选择器找到二维码元素:', qrCodeElement); return qrCodeElement; } const allQrCodes = document.querySelectorAll('.qr-code'); for (let element of allQrCodes) { if (element.hasAttribute('title')) { console.log('遍历找到包含title的二维码元素:', element); return element; } } return null; }
function getElementDetails(element) { if (!element) return null; const title = element.getAttribute('title'); console.log('获取到的title属性:', title); const details = { outerHTML: element.outerHTML.substring(0, 500) + (element.outerHTML.length > 500 ? '...' : ''), tagName: element.tagName, className: element.className, id: element.id, title: title || '无', hasTitle: element.hasAttribute('title'), attributes: {}, childrenCount: element.children.length, computedStyle: {} };
for (let attr of element.attributes) { details.attributes[attr.name] = attr.value; }
try { const style = window.getComputedStyle(element); details.computedStyle = { display: style.display, visibility: style.visibility, opacity: style.opacity }; } catch (error) { details.computedStyle = { error: '无法获取样式' }; }
return details; }
function formatElementInfo(details) { if (!details) return '未找到有效元素信息'; let text = `**元素标签**: ${details.tagName}\n`; text += `**CSS类名**: ${details.className}\n`; text += `**元素ID**: ${details.id || '无'}\n`; text += `**包含title属性**: ${details.hasTitle ? '是' : '否'}\n`; text += `**title值**: ${details.title}\n`; text += `**显示状态**: ${details.computedStyle.display || '未知'}\n`; text += `**可见性**: ${details.computedStyle.visibility || '未知'}\n`; text += `**子元素数量**: ${details.childrenCount}\n\n`;
if (Object.keys(details.attributes).length > 0) { text += "**属性列表**:\n"; for (let [key, value] of Object.entries(details.attributes)) { text += `- ${key}: ${value}\n`; } text += "\n"; }
return text; }
function checkPopup() { const qrCodeElement = findQrCodeWithTitle();
if (qrCodeElement) { const currentTitle = qrCodeElement.getAttribute('title'); console.log('当前检测到的title:', currentTitle); if (currentTitle && currentTitle !== lastDetectedTitle) { popupDetected = true; lastDetectedTitle = currentTitle; console.log('检测到新的二维码弹窗,title:', currentTitle); const elementDetails = getElementDetails(qrCodeElement); console.log('元素详细信息:', elementDetails);
const pageTitle = document.title; const pageUrl = window.location.href;
sendToDingTalk(pageTitle, pageUrl, elementDetails); } } else if (popupDetected) { popupDetected = false; lastDetectedTitle = ''; console.log('弹窗已关闭'); } }
function sendToDingTalk(pageTitle, pageUrl, elementDetails) { const formattedInfo = formatElementInfo(elementDetails); const qrCodeUrl = elementDetails.title; let messageText = `## 网页弹窗检测通知\n\n`; messageText += `⚠️ 检测到人脸识别二维码弹窗,请及时处理!\n\n`; messageText += `**直接访问链接**: ${qrCodeUrl}`; const message = { "msgtype": "markdown", "markdown": { "title": "二维码弹窗检测通知", "text": messageText }, "at": { "isAtAll": false } };
sendDingTalkMessage(message); }
function sendDingTalkMessage(message) { generateDingTalkSignature(DINGTALK_CONFIG.secret).then(signatureData => { let webhookUrl = DINGTALK_CONFIG.webhookBase; if (signatureData.sign !== 'direct') { webhookUrl += `×tamp=${signatureData.timestamp}&sign=${signatureData.sign}`; }
GM_xmlhttpRequest({ method: 'POST', url: webhookUrl, headers: { 'Content-Type': 'application/json' }, data: JSON.stringify(message), onload: function(response) { if (response.status === 200) { console.log('钉钉通知发送成功'); } else { console.error('钉钉通知发送失败:', response.status, response.responseText); } }, onerror: function(error) { console.error('发送请求时出错:', error); } }); }).catch(error => { console.error('生成签名时出错:', error); }); }
function startMonitoring() { console.log('开始监控二维码弹窗...');
checkPopup();
const observer = new MutationObserver(function(mutations) { let shouldCheck = false; mutations.forEach(function(mutation) { if (mutation.type === 'childList') { mutation.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.matches && node.matches('.qr-code')) { shouldCheck = true; } else if (node.querySelector) { const hasQrCode = node.querySelector('.qr-code'); if (hasQrCode) shouldCheck = true; } } }); } }); if (shouldCheck) { setTimeout(checkPopup, 500); } });
observer.observe(document.body, { childList: true, subtree: true });
setInterval(checkPopup, 3000); }
function init() { loadCryptoJS().then(() => { console.log('初始化完成,开始监控'); startMonitoring(); }); }
if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', init); } else { init(); }
window.debugQrCode = function() { console.log('=== 二维码元素调试信息 ==='); const methods = [ { name: '主XPath', element: getElementByXpath(TARGET_POPUP_XPATH) }, { name: '备用XPath', element: getElementByXpath(BACKUP_POPUP_XPATH) }, { name: 'CSS选择器', element: document.querySelector('.qr-code[title]') }, { name: '所有qr-code', elements: document.querySelectorAll('.qr-code') } ]; methods.forEach(method => { console.log(`\n${method.name}:`); if (method.elements) { console.log(`找到 ${method.elements.length} 个.qr-code元素`); method.elements.forEach((el, index) => { const title = el.getAttribute('title'); console.log(` ${index + 1}. ${el.outerHTML.substring(0, 200)}`); console.log(` title: ${title}`); }); } else if (method.element) { const title = method.element.getAttribute('title'); console.log(`找到元素:`, method.element); console.log(`outerHTML:`, method.element.outerHTML); console.log(`title属性:`, title); } else { console.log('未找到元素'); } }); }; })();
|