-
Notifications
You must be signed in to change notification settings - Fork 0
/
bp联动爬虫获取路径.js
83 lines (70 loc) · 2.51 KB
/
bp联动爬虫获取路径.js
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
function getDomain(url) {
const a = document.createElement('a');
a.href = url;
return a.hostname;
}
function filterElementsByDomain(elements, domain) {
return Array.from(elements).filter(element => {
if (element.tagName === 'A') {
return getDomain(element.href) === domain;
}
return true;
});
}
function triggerInteractiveElementsInNewWindow() {
const clickableSelectors = [
'a[href]',
'button',
'[onclick]',
'[tabindex]',
];
const clickableElements = document.querySelectorAll(clickableSelectors.join(','));
const currentDomain = getDomain(window.location.href);
const filteredClickableElements = filterElementsByDomain(clickableElements, currentDomain);
filteredClickableElements.forEach((element, index) => {
setTimeout(() => {
const newWindow = window.open('', '_blank');
if (newWindow && newWindow.document) {
newWindow.document.write('<!DOCTYPE html><html><head><title>Triggered Element</title></head><body></body></html>');
newWindow.document.close();
const clonedElement = element.cloneNode(true);
newWindow.document.body.appendChild(clonedElement);
if (clonedElement.tagName === 'A') {
clonedElement.click();
} else {
const event = new MouseEvent('click', {
bubbles: true,
cancelable: true,
view: newWindow,
});
clonedElement.dispatchEvent(event);
}
}
}, index * 1000);
});
}
function triggerAllElementsSimultaneously() {
const clickableSelectors = [
'a[href]',
'button',
'[onclick]',
'[tabindex]',
];
const clickableElements = document.querySelectorAll(clickableSelectors.join(','));
const currentDomain = getDomain(window.location.href);
const filteredClickableElements = filterElementsByDomain(clickableElements, currentDomain);
filteredClickableElements.forEach(element => {
if (element.tagName === 'A') {
element.click();
} else {
const event = new MouseEvent('click', {
bubbles: true,
cancelable: true,
view: window,
});
element.dispatchEvent(event);
}
});
}
triggerInteractiveElementsInNewWindow();
triggerAllElementsSimultaneously();