-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdisplay-crawl-results.html
243 lines (218 loc) · 8.45 KB
/
display-crawl-results.html
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
<!DOCTYPE html>
<html>
<head>
<title>Some crawl results</title>
<meta name="robots" content="noindex">
<script>
"use strict";
let jsonFilePath = "output/crawl.json";
let sites = [];
function loadCrawlData(callback) {
var xhr = new XMLHttpRequest();
xhr.overrideMimeType("application/json");
xhr.open("GET", "output/" + document.querySelector("#input-file").value, true);
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status == "200") {
sites = JSON.parse(xhr.responseText);
displayResults();
}
}
xhr.send(null);
}
function displayResults() {
let resultsElem = document.getElementById("results");
resultsElem.textContent = "Updating results...";
// Return to the event loop so that the above message displays before we go
// on to spend a long time building the results;
setTimeout(() => doDisplayResults(resultsElem), 0);
}
function doDisplayResults(resultsElem) {
resultsElem.textContent = "";
let p = document.createElement("p");
p.textContent = "Total sites crawled: " + sites.length + "; " +
"Total pages crawled: ";
let spanTotalPages = document.createElement("span");
p.append(spanTotalPages);
p.append(document.createTextNode("; Pages with subdocs: "));
let spanNumPagesWithSubdocs = document.createElement("span");
p.append(spanNumPagesWithSubdocs);
p.append(document.createTextNode("; Pages with subdocs matching filters: "));
let spanNumPagesWithSubdocsMatchingFilters = document.createElement("span");
p.append(spanNumPagesWithSubdocsMatchingFilters);
resultsElem.append(p);
let filters = {
bounds: {
w: parseFloat(document.querySelector("#bounds-width").value),
h: parseFloat(document.querySelector("#bounds-height").value),
},
isOnScreen: document.querySelector("#is-on-screen").checked,
notDisplayNone: document.querySelector("#not-display-none").checked,
isCrossOrigin: document.querySelector("#is-cross-origin").checked,
isTransformed: document.querySelector("#is-transformed").checked,
isFiltered: document.querySelector("#is-filtered").checked,
isMasked: document.querySelector("#is-masked").checked,
isClipped: document.querySelector("#is-clipped").checked,
};
let totalPages = 0, totalPagesWithSubdocs = 0,
totalPagesWithSubdocsMatchingFilters = 0;
for (let site of sites) {
let [pages, pagesWithSubdocs, pagesWithSubdocsMatchingFilters] =
generateAndAppendSiteToResults(site, filters, resultsElem);
totalPages += pages;
totalPagesWithSubdocs += pagesWithSubdocs;
totalPagesWithSubdocsMatchingFilters += pagesWithSubdocsMatchingFilters;
}
spanTotalPages.textContent = totalPages;
spanNumPagesWithSubdocs.textContent = totalPagesWithSubdocs;
spanNumPagesWithSubdocsMatchingFilters.textContent = totalPagesWithSubdocsMatchingFilters;
}
function generateAndAppendSiteToResults(site, filters, resultsElem) {
function subdocBoundsOK(docData, requiredBounds) {
let b = docData.bounds;
let rb = requiredBounds;
return b.w >= rb.w && b.h >= rb.h;
}
function isOnScreen(docData) {
let b = docData.bounds;
return (b.x + b.w) > 0 && (b.y + b.h) > 0;
}
function isSameOrigin(pageURL, subdocURL) {
try {
if (subdocURL == "about:blank" || subdocURL.startsWith("javascript:")) {
return true;
}
pageURL = new URL(pageURL);
subdocURL = new URL(subdocURL);
return pageURL.origin == subdocURL.origin;
} catch(e) {
// Broken URLs aren't interesting; don't add them to the cross-origin list.
return true;
}
}
function passesFilters(page, sdoc, filters) {
if (!subdocBoundsOK(sdoc, filters.bounds) ||
(filters.isOnScreen && !isOnScreen(sdoc)) ||
(filters.notDisplayNone && sdoc.isDisplayNone) ||
(filters.isCrossOrigin && isSameOrigin(page.url, sdoc.url)) ||
(filters.isTransformed && !sdoc.transform) ||
(filters.isFiltered && !sdoc.hasFilter) ||
(filters.isMasked && !sdoc.hasMask) ||
(filters.isClipped && !sdoc.hasClipPath)) {
return false;
}
return true;
}
function addSubdocToOutput(page, sdoc, listElem) {
let li = document.createElement("li");
li.textContent = sdoc.url.replace(/\?.*/, "?...").replace(/#.*/, ""); // drop query string and anchor
let details = [];
let b = sdoc.bounds;
details.push(`bounds(${Math.round(b.x)}, ${Math.round(b.y)}, ${Math.round(b.w)}, ${Math.round(b.h)})`);
if (sdoc.transform) {
details.push("transform=" + sdoc.transform);
}
if (sdoc.hasFilter) {
details.push("has filter");
}
if (sdoc.hasMask) {
details.push("has mask");
}
if (sdoc.hasClipPath) {
details.push("has clipPath");
}
li.append(document.createElement("br"));
li.append(document.createTextNode("- " + details.join("; ")));
listElem.append(li);
}
let siteStats = {
crashed: 0,
error: 0,
loadNotComplete: 0,
};
let h = document.createElement("h4");
h.textContent = site.hostname + " - " + site.pages.length + " pages crawled.";
resultsElem.append(h);
let numPagesWithSubdocs = 0, numPagesWithSubdocsMatchingFilters = 0;
let pagesWithMatchingSubdocs = [];
let pagesUL = document.createElement("ul");
for (let page of site.pages) {
if (page.crashed) {
siteStats.crashed += 1;
}
if (page.error) {
siteStats.error += 1;
}
if (page.loadNotComplete) {
siteStats.loadNotComplete += 1;
}
if (page.subdocs.length > 0) {
++numPagesWithSubdocs;
}
let subdocsOutput = document.createElement("ul");
for (let sdoc of page.subdocs) {
if (passesFilters(page, sdoc, filters)) {
addSubdocToOutput(page, sdoc, subdocsOutput);
}
}
if (subdocsOutput.children.length) {
++numPagesWithSubdocsMatchingFilters;
let url = page.url;
let pageLI = document.createElement("li");
let a = document.createElement("a");
a.href = url;
a.textContent = url.replace(/\?.*/, "?...").replace(/#.*/, "");
pageLI.append(a);
pageLI.append(subdocsOutput);
pagesUL.append(pageLI);
}
}
if (pagesUL.children.length > 0) {
resultsElem.append(pagesUL);
}
let statsMsgs = [];
if (siteStats.crashed > 0) {
statsMsgs.push(siteStats.crashed + " crashed");
}
if (siteStats.error > 0) {
statsMsgs.push(siteStats.error + " had unknown errors");
}
if (siteStats.loadNotComplete > 0) {
statsMsgs.push(siteStats.loadNotComplete + " did not finish loading");
}
if (statsMsgs.length > 0) {
h.textContent += " (" + statsMsgs.join("; ") + ")";
}
return [site.pages.length, numPagesWithSubdocs, numPagesWithSubdocsMatchingFilters];
}
addEventListener("load", _ => {
document.querySelector("#filterform").addEventListener(
"change",
displayResults
);
loadCrawlData();
});
</script>
</head>
<body>
<h1>Some crawl results</h1>
<p>For background on the crawler see the <a href="README.md">README</a>. For the raw crawl output see the <a href="output">output directory</a>.</p>
<p>Some pages below may not appear to belong to the site that they are grouped under. This happens when the original page that we loaded redirected to an external site. For example, when the youtube.com homepage redirects to accounts.google.com/signin.</p>
<p>The bounds given in the results befow are of the form "bounds(x,y,width,height)".</p>
<h4>Results file to use</h4>
<p>File: <input id="input-file" value="crawl-alexa-1st-down.json" onchange="loadCrawlData()"> (enter a file name from the <a href="output">output directory</a></p>
<h4>Subdocument filters:</h4>
<form id="filterform">
Bounds width >= <input id="bounds-width" value="6"> (as reported by getBoundingClientRect)<br>
Bounds height >= <input id="bounds-height" value="6"><br>
<input id="is-on-screen" type="checkbox" checked> Is on screen (technically, not off top or left)<br>
<input id="not-display-none" type="checkbox" checked> Is not display:none<br>
<input id="is-cross-origin" type="checkbox" checked> Is cross-origin<br>
<input id="is-transformed" type="checkbox"> Is transformed<br>
<input id="is-filtered" type="checkbox"> Has a filter on or above iframe<br>
<input id="is-masked" type="checkbox"> Has a mask on or above iframe<br>
<input id="is-clipped" type="checkbox"> Has a clipPath on or above iframe<br>
</form>
<h4>Filtered results</h4>
<section id="results">Processing crawl results...</section>
</body>
</html>