MegaApuTurkUltra

scratchy_extensions.user.js

Oct 6th, 2014
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        Scratchy Extensions
  3. // @namespace   http://aputurk.tk/
  4. // @include     http://scratch.mit.edu/*
  5. // @version     0.0.1
  6. // @grant       none
  7. // ==/UserScript==
  8.  
  9.  
  10. (function(){
  11.     enabled = false;
  12.     activate = function(){
  13.         if(enabled)return true;
  14.         var str = ($("#instructions textarea").length > 0) ? $("#instructions textarea").text() : $("#instructions .overview").text();
  15.         var matches = str.match(/\$\{.+?\}/);
  16.         console.log(matches);
  17.         if(matches==null || matches.length==0)return 0;
  18.         var jsonm = JSON.parse(matches[0].substring(1));
  19.         if(jsonm.hasOwnProperty("requires") && jsonm['requires'] instanceof Array){
  20.             var warning = "Warning! Loading arbitrary scripts can be dangerous! Make sure you trust the following extensions before continuing:\n\n";
  21.             for(i in jsonm['requires'])warning+=jsonm['requires'][i]+"\n";
  22.             warning+="\nClick OK to continue, or Cancel to prevent loading these extensions";
  23.             if(confirm(warning)){
  24.                 for(i in jsonm['requires']){
  25.                     var scriptElement = document.createElement('script');
  26.                     scriptElement.src = jsonm['requires'][i].replace(/raw.githubusercontent.com/g, "cdn.rawgit.com");
  27.                     document.head.appendChild(scriptElement);
  28.                 }
  29.                 enabled = true;
  30.                 $("#enable-extensions").text("Enabled :)").css("background","#eee").css("border", "1px solid #ccc").css("color", "gray");
  31.                 return 1;
  32.             }
  33.             return -1;
  34.         } else return 0;
  35.     };
  36.     $(document).ready(function(){
  37.         if(location.href.match(/scratch.mit.edu\/projects\/[0-9]+/).length > 0){
  38.             $("<div id='enable-extensions' class='button'><span>Enable Extensions</span></div>")
  39.                 .click(function(){
  40.                     var success = (activate)();
  41.                     if(success==0){
  42.                         $(this).text("No exts found").css("background","#eee").css("border", "1px solid #ccc").css("color", "gray");
  43.                     } else if(success==-1) {
  44.                         $(this).attr("style", "");
  45.                     }
  46.                 }).prependTo($("#project .buttons"));
  47.         }
  48.     });
  49. })();
Advertisement
Add Comment
Please, Sign In to add comment