Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var itemID = window.editorData.itemID;
- var getJSON = function(url, callback) {
- var xhr = new XMLHttpRequest();
- xhr.open('GET', url, true);
- xhr.responseType = 'json';
- xhr.onload = function() {
- var status = xhr.status;
- if (status == 200) {
- callback(null, xhr.response);
- } else {
- callback(status);
- }
- };
- xhr.send();
- };
- getJSON('https://codehs.com/editor/ajax/get_solution_code?itemID='+itemID+'&method=get_solution_code', function(err, data) {
- if (err != null) {
- console.error(err);
- } else {
- var text = `${data.solutionCodeJson};`
- navigator.clipboard.writeText(text).then(function() {
- console.log('Async: Copying to clipboard was successful!');
- }, function(err) {
- console.error('Async: Could not copy text: ', err);
- });
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement