MCPcopy Create free account
hub / github.com/ChinaGodMan/UserScripts / watchUpdate

Function watchUpdate

github-commit-viewer/github-commit-viewer.user.js:336–366  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

334 //
335}
336function watchUpdate() {//检查链接变化
337 // 检测浏览器是否支持 MutationObserver
338 const MutationObserver =
339 window.MutationObserver ||
340 window.WebKitMutationObserver ||
341 window.MozMutationObserver
342 // 获取当前页面的 URL
343 const getCurrentURL = () => location.href
344 getCurrentURL.previousURL = getCurrentURL()
345 // 创建 MutationObserver 实例,监听 DOM 变化
346 const observer = new MutationObserver((mutations, observer) => {
347 const currentURL = getCurrentURL()
348 // 如果页面的 URL 发生变化
349 if (currentURL !== getCurrentURL.previousURL) {
350 getCurrentURL.previousURL = currentURL
351 console.log('链接变化,正在启动监听器')
352 setTimeout(() => {
353 main()
354 }, 500)
355 }
356 })
357 // 配置 MutationObserver
358 const config = {
359 characterData: true,
360 subtree: true,
361 childList: true,
362 attributeFilter: ['value', 'placeholder', 'aria-label', 'data-confirm'] // 仅观察特定属性变化
363 }
364 // 开始观察 document.body 的变化
365 observer.observe(document.body, config)
366}

Callers 1

Calls 2

getCurrentURLFunction · 0.85
mainFunction · 0.70

Tested by

no test coverage detected