youtube-video-download.user.js
// calling the callback(json, error) function on completion
calling the callback(json, error) function on completion
calling the callback ( json error ) function on completion
function apiRequest(path, callback)
 {
  var xhr = new XMLHttpRequest();
  xhr.open("GET", path);
  xhr.onload = function() {
   var json;
   try {
    json = JSON.parse(xhr.responseText);
   }
   catch (e) {
    callback(null, true);
   }
   if (json)
    callback(json);
  };
  xhr.onerror = function() {
   callback(null, true);
  };
  xhr.send();
 }
function apiRequest ( path , callback ) { var xhr = new XMLHttpRequest ( ) ; xhr . open ( "GET" , path ) ; xhr . onload = function ( ) { var json ; try { json = JSON . parse ( xhr . responseText ) ; } catch ( e ) { callback ( null , true ) ; } if ( json ) callback ( json ) ; } ; xhr . onerror = function ( ) { callback ( null , true ) ; } ; xhr . send ( ) ; }
calling the callback(json, error) function on completion
calling the callback ( json error ) function on completion