Last active
September 20, 2017 18:53
-
-
Save csf30816/1ce49ea3d9abc5bd3144eddc5f0e03a3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(function(ext) { | |
// Cleanup function when the extension is unloaded | |
ext._shutdown = function() {}; | |
// Status reporting code | |
// Use this to report missing hardware, plugin or unsupported browser | |
ext._getStatus = function() { | |
return {status: 2, msg: 'Ready'}; | |
}; | |
// Block and block menu descriptions | |
var descriptor = { | |
blocks: [ | |
['r', 'Messages Count', 'getMessageCount'], | |
[' ', 'Follow %s', 'putFollower', 'csf30816'], | |
[' ', 'Alert %s', 'addAlert', 'This page is top secret!'], | |
[' ', 'Love Project# %n', 'addLove', 100000], | |
[' ', 'Favorite Project# %n', 'addFave', 100000], | |
[' ', 'Shut down this project with reason %s', 'shut', ''], | |
['r', 'Amount of projects on scratch', 'projectsGetAmount'] | |
] | |
}; | |
ext.getMessageCount = function(callback) { | |
$.ajax({ | |
url: 'https://scratch.mit.edu/messages/ajax/get-message-count/', | |
dataType: 'json', | |
success: function (responseText) { | |
messages = responseText['msg_count']; | |
callback(messages); | |
} | |
}) | |
} | |
ext.putFollower = function(user) { | |
$.ajax({ | |
type: "PUT", | |
url: "https://scratch.mit.edu/site-api/users/followers/" + user + "/add/", | |
data: { | |
usernames: Scratch.INIT_DATA.LOGGED_IN_USER.model.username | |
} | |
}) | |
} | |
ext.addAlert = function(alert) { | |
ScratchExtensions.notify(alert); | |
}; | |
ext.addLove = function(projectID) { | |
$.ajax({ | |
type: "PUT", | |
url: "https://scratch.mit.edu/site-api/users/lovers/" + projectID + "/add/?usernames=" + Scratch.INIT_DATA.LOGGED_IN_USER.model.username, | |
data: { | |
usernames: Scratch.INIT_DATA.LOGGED_IN_USER.model.username | |
} | |
}) | |
} | |
ext.addFave = function(projectID) { | |
$.ajax({ | |
type: "PUT", | |
url: "https://scratch.mit.edu/site-api/users/favoriters/" + projectID + "/add/?usernames=" + Scratch.INIT_DATA.LOGGED_IN_USER.model.username, | |
data: { | |
usernames: Scratch.INIT_DATA.LOGGED_IN_USER.model.username | |
} | |
}) | |
} | |
ext.shutdown = function(shut) { | |
document.write('This project has been shut down for this reason: ' + shut + '!'); | |
} | |
ext.projectGetAmount = function(callback) { | |
$.ajax({ | |
url: 'https://api-staging.scratch.mit.edu/projects/count/all', | |
dataType: 'json', | |
success: function (responseText) { | |
projects = responseText['count']; | |
callback(projects) | |
} | |
}) | |
} | |
// Register the extension | |
ScratchExtensions.register('Scratch Api', descriptor, ext); | |
})({}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
?