Last active
November 9, 2017 12:30
-
-
Save fzieris/1fd9099c9f7c87c880344a3a78df9e4b to your computer and use it in GitHub Desktop.
Save bookmarklet as "target"/"location" for a new browser bookmark, then click on bookmark to send current HTML to W3C for validation (see below for non-minified code)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:var%20doctype=document.doctype?(new%20XMLSerializer).serializeToString(document.doctype)+"\n":"",content=doctype+document.documentElement.outerHTML,iframe=document.createElement("iframe");iframe.style.position="fixed",iframe.style.zIndex=1e4,iframe.style.top=0,iframe.style.left="10px",iframe.style.width="calc(100%%20-%2020px)",iframe.style.height="calc(100%%20-%2020px)",iframe.style.border="3px%20solid%20red",iframe.style.background="white",document.body.appendChild(iframe);var%20target=iframe.contentDocument||iframe.contentWindow.document;target.write("loading..."),target.close();var%20xhttp=new%20XMLHttpRequest,fd=new%20FormData;fd.append("content",content),xhttp.onreadystatechange=function(){4==this.readyState&&200==this.status&&(target.write(this.responseText.replace('href="style.css"','href="https://validator.w3.org/nu/style.css"')),target.close())},xhttp.open("POST","https://validator.w3.org/nu/#textarea",!0),xhttp.send(fd); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// get current HTML code including DOCTYPE | |
var doctype = document.doctype ? (new XMLSerializer().serializeToString(document.doctype) + "\n") : ""; | |
var content = doctype + document.documentElement.outerHTML; | |
// create iframe for displaying the result | |
var iframe = document.createElement('iframe'); | |
iframe.style.position='fixed'; | |
iframe.style.zIndex=10000; | |
iframe.style.top=0; | |
iframe.style.left="10px"; | |
iframe.style.width="calc(100% - 20px)"; | |
iframe.style.height="calc(100% - 20px)"; | |
iframe.style.border="3px solid red"; | |
iframe.style.background="white"; | |
document.body.appendChild(iframe); | |
var target = iframe.contentDocument || iframe.contentWindow.document; | |
target.write("loading..."); | |
target.close(); | |
// prepare send POST request to W3C validator | |
var xhttp = new XMLHttpRequest(); | |
var fd = new FormData(); | |
fd.append('content', content); | |
xhttp.onreadystatechange = function() { | |
if (this.readyState == 4 && this.status == 200) { | |
// replace relative path to W3C stylesheet | |
target.write(this.responseText.replace( | |
'href="style.css"', | |
'href="https://validator.w3.org/nu/style.css"' | |
)); | |
target.close(); | |
} | |
}; | |
xhttp.open('POST', 'https://validator.w3.org/nu/#textarea', true); | |
xhttp.send(fd); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment