Skip to content

Commit

Permalink
onloadのhandlerを分離
Browse files Browse the repository at this point in the history
  • Loading branch information
hokaccha committed Mar 10, 2010
1 parent ce59293 commit 7055f7f
Showing 1 changed file with 31 additions and 24 deletions.
55 changes: 31 additions & 24 deletions html5validator.user.js
Expand Up @@ -9,37 +9,44 @@
// Version: 0.0.1

var validator_url = 'http://html5.validator.nu/';

var execute_validate = function() {
GM_xmlhttpRequest({
method: 'GET',
url: location.href,
onload: function(res) {
var boundary = get_boundary();
GM_xmlhttpRequest({
method: 'POST',
url: validator_url,
data: get_post_data(boundary, {
out: 'json',
content: res.responseText,
}),
headers: {
'Content-type': 'multipart/form-data; boundary=' + boundary,
},
onload: function(r) {
var data = eval('(' + r.responseText + ')');
if (data.messages.length) {
console.log('invalid');
console.log(data.messages);
}
else {
console.log('valid');
}
}
});
},
onload: on_load_self,
});
};

var on_load_self = function(res) {
var boundary = get_boundary();
var post_data = get_post_data(boundary, {
out: 'json',
content: res.responseText,
});
var headers = {
'Content-type': 'multipart/form-data; boundary=' + boundary,
};
GM_xmlhttpRequest({
method: 'POST',
url: validator_url,
data: post_data,
headers: headers,
onload: on_load_validate,
});
};

var on_load_validate = function(res) {
var data = eval( '(' + res.responseText + ')' );
if (data.messages.length) {
console.log('invalid');
console.log(data.messages);
}
else {
console.log('valid');
}
};

// get random boundary string
var get_boundary = function() {
var n = 50;
Expand Down

0 comments on commit 7055f7f

Please sign in to comment.