Advertisement
Guest User

Scratch Cookies

a guest
Dec 19th, 2014
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function setCookie(cname, cvalue, exdays) {
  2.     var d = new Date();
  3.     d.setTime(d.getTime() + (exdays*24*60*60*1000));
  4.     var expires = "expires="+d.toUTCString();
  5.     document.cookie = cname + "=" + cvalue + "; " + expires;
  6. } ;
  7. function getCookie(cname) {
  8.     var name = cname + "=";
  9.     var ca = document.cookie.split(';');
  10.     for(var i=0; i<ca.length; i++) {
  11.         var c = ca[i];
  12.         while (c.charAt(0)==' ') c = c.substring(1);
  13.         if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
  14.     }
  15.     return "";
  16. } ;
  17. (function(ext) {
  18.     // Cleanup function when the extension is unloaded
  19.     ext._shutdown = function() {};
  20.  
  21.     // Status reporting code
  22.     // Use this to report missing hardware, plugin or unsupported browser
  23.     ext._getStatus = function() {
  24.         return {status: 2, msg: 'Ready'};
  25.     };
  26.     ext.save = function(thing, cookie){
  27.         setCookie(cookie, thing, 99999999999999);
  28.     };
  29.     ext.read = function(that){
  30.         return getCookie(that);
  31.     };
  32.     ext.delete = function(cookie){
  33.         setCookie(cookie, '12', -10);
  34.     };
  35.     ext.installed = function(){
  36.         var foo = true;
  37.         return foo;
  38.     };
  39.  
  40.     // Block and block menu descriptions
  41.     var descriptor = {
  42.         blocks: [
  43.             [' ', 'save %s to cookie %s', 'save', 'thing', 'cookie1'],
  44.             ['r', 'read cookie %s', 'read', 'cookie1'],
  45.             [' ', 'delete cookie %s', 'delete', 'cookie1'],
  46.             ['b', 'installed?', 'installed'],
  47.         ],
  48.         url: 'http://scratch.mit.edu/projects/40581194/'
  49.  
  50.     };
  51.  
  52.     // Register the extension
  53.     ScratchExtensions.register('Cookies', descriptor, ext);
  54. })({});
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement