Greasy Fork 还支持 简体中文。

Browser Ponies

Ponify Scratch!

  1. // ==UserScript==
  2. // @name Browser Ponies
  3. // @namespace http://scratch.mit.edu
  4. // @version 1.0
  5. // @description Ponify Scratch!
  6. // @match *://scratch.mit.edu/projects/*
  7. // @author Katherine C.
  8. // ==/UserScript==
  9.  
  10. //Install base scripts
  11. var basecfg_script = document.createElement('script');
  12. basecfg_script.setAttribute('type', 'text/javascript');
  13. basecfg_script.setAttribute('src', 'https://panzi.github.io/Browser-Ponies/basecfg.js');
  14. basecfg_script.setAttribute('id', 'browser-ponies-config');
  15. document.head.appendChild(basecfg_script);
  16.  
  17. var browserponies_script = document.createElement('script');
  18. browserponies_script.setAttribute('type', 'text/javascript');
  19. browserponies_script.setAttribute('src', 'https://panzi.github.io/Browser-Ponies/browserponies.js');
  20. browserponies_script.setAttribute('id', 'browser-ponies-script');
  21. document.head.appendChild(browserponies_script);
  22. function installExtensionBrowserPonies() {
  23. var cfg = {
  24. "fadeDuration": 500,
  25. "volume": 1,
  26. "fps": 25,
  27. "speed": 3,
  28. "audioEnabled": false,
  29. "showFps": false,
  30. "showLoadProgress": true,
  31. "speakProbability": 0.1,
  32. "baseurl": "https://panzi.github.io/Browser-Ponies/",
  33. "spawn": {}
  34. };
  35.  
  36. (function(ext) {
  37. // Cleanup function when the extension is unloaded
  38. ext._shutdown = function() {};
  39.  
  40. // Status reporting code
  41. // Use this to report missing hardware, plugin or unsupported browser
  42. ext._getStatus = function() {
  43. if(BrowserPoniesBaseConfig.loaded){
  44. return {status: 2, msg: 'Ready'};
  45. }
  46. else if(BrowserPonies != undefined && BrowserPoniesBaseConfig != undefined){
  47. BrowserPonies.setBaseUrl(cfg.baseurl);
  48. BrowserPonies.loadConfig(BrowserPoniesBaseConfig);
  49. BrowserPonies.start();
  50. BrowserPoniesBaseConfig.loaded = true;
  51. return {status: 1, msg: 'Not Ready'};
  52. }
  53. return {status: 0, msg: 'Not Ready'};
  54. };
  55. // Block and block menu descriptions
  56. var descriptor = {
  57. blocks: [
  58. [' ', 'start', 'startPonies'],
  59. [' ', 'stop', 'stopPonies'],
  60. [' ', 'pause', 'pausePonies'],
  61. [' ', 'resume', 'resumePonies'],
  62. [' ', 'toggle ponies in background', 'toggleInBackground'],
  63. [' ', 'remove all ponies', 'removePonies'],
  64. ['-'],
  65. [' ', 'add pony %s', 'addPony', 'derpy hooves'],
  66. [' ', 'add random pony', 'addRandomPony']
  67. ],
  68.  
  69. menus: {
  70. ponies: ['derpy hooves', 'applejack','fluttershy','pinkie pie','rainbow dash','rarity','twilight sparkle']
  71. }
  72. };
  73. var ponyNames = [];
  74. //Commands
  75. ext.startPonies = function(){BrowserPonies.start();};
  76. ext.stopPonies = function(){BrowserPonies.stop();};
  77. ext.pausePonies = function(){BrowserPonies.pause();};
  78. ext.resumePonies = function(){BrowserPonies.resume();};
  79. ext.toggleInBackground = function(){BrowserPonies.togglePoniesToBackground()};
  80. ext.removePonies = function(){BrowserPonies.unspawnAll();};
  81. //Adding ponies
  82. ext.addPony = function(name){
  83. addPonyByName(name);
  84. }
  85. ext.addRandomPony = function(){
  86. checkLoaded();
  87. BrowserPonies.spawnRandom()
  88. }
  89. function addPonyByName (name){
  90. checkLoaded();
  91. if(BrowserPonies.ponies()[name] != undefined){
  92. //Check if the pony exists
  93. if(name == 'vinyl scratch'){
  94. //Seizure warning
  95. if(confirm('WARNING:\nContains flashing lights/patterns that may not be suitable for people with photosensitive epilepsy.')){
  96. if(BrowserPonies.ponies()[name] != undefined){
  97. console.log(cfg)
  98. cfg['spawn'] = {};
  99. cfg['spawn'][name] = 1;
  100. BrowserPonies.loadConfig(cfg);
  101. }
  102. }
  103. }
  104. else{
  105. console.log(cfg)
  106. cfg['spawn'] = {};
  107. cfg['spawn'][name] = 1;
  108. BrowserPonies.loadConfig(cfg);
  109. }
  110. }
  111. }
  112. function checkLoaded (){
  113. //Load BrowserPonies if it is not already loaded
  114. if(!BrowserPoniesBaseConfig.loaded){
  115. BrowserPonies.setBaseUrl(cfg.baseurl);
  116. BrowserPonies.loadConfig(BrowserPoniesBaseConfig);
  117. BrowserPonies.start();
  118. BrowserPoniesBaseConfig.loaded = true;
  119. ponyNames = keys(BrowserPonies.ponies());
  120. }
  121. }
  122. // Register the extension
  123. ScratchExtensions.register('Browser Ponies', descriptor, ext);
  124. })({});
  125. }
  126.  
  127. installExtensionBrowserPonies();