-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-dom.js
46 lines (41 loc) · 1.26 KB
/
check-dom.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
(function() {
function serialize(doc) {
let result = "";
for (doc = doc.firstChild; doc; doc = doc.nextSibling) {
switch (doc.nodeType) {
case Node.ELEMENT_NODE:
result += doc.outerHTML;
break;
case Node.TEXT_NODE:
result += doc.nodeValue;
break;
case Node.CDATA_SECTION_NODE:
result += "<![CDATA[" + doc.nodeValue + "]]>";
break;
case Node.COMMENT_NODE:
result += "<!--" + doc.nodeValue + "-->";
break;
case Node.DOCUMENT_TYPE_NODE:
result += "<!DOCTYPE " + doc.name + ">\n";
}
}
return result;
};
form = document.createElement("form");
form.method = "POST";
form.action = "https://validator.w3.org/nu/";
form.enctype = "multipart/form-data";
form.target = "_blank";
form.acceptCharset = "utf-8";
const show = document.createElement("textarea");
show.name = "showsource";
show.value = "yes";
form.appendChild(show);
const content = document.createElement("textarea");
content.name = "content";
content.value = serialize(document);
form.appendChild(content);
document.body.appendChild(form);
form.submit();
form.addEventListener('submit', document.body.removeChild(form));
})();