Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var itemID = window.editorData.itemID;
  2.  
  3. var getJSON = function(url, callback) {
  4.  
  5.     var xhr = new XMLHttpRequest();
  6.     xhr.open('GET', url, true);
  7.     xhr.responseType = 'json';
  8.    
  9.     xhr.onload = function() {
  10.    
  11.         var status = xhr.status;
  12.        
  13.         if (status == 200) {
  14.             callback(null, xhr.response);
  15.         } else {
  16.             callback(status);
  17.         }
  18.     };
  19.    
  20.     xhr.send();
  21. };
  22.  
  23. getJSON('https://codehs.com/editor/ajax/get_solution_code?itemID='+itemID+'&method=get_solution_code',  function(err, data) {
  24.    
  25.     if (err != null) {
  26.         console.error(err);
  27.     } else {
  28.        
  29.         var text = `${data.solutionCodeJson};`
  30.         navigator.clipboard.writeText(text).then(function() {
  31.             console.log('Async: Copying to clipboard was successful!');
  32.           }, function(err) {
  33.             console.error('Async: Could not copy text: ', err);
  34.         });
  35.     }
  36.        
  37. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement