Browser Ponies

Ponify Scratch!

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name       Browser Ponies
// @namespace  http://scratch.mit.edu
// @version    1.0
// @description  Ponify Scratch!
// @match      *://scratch.mit.edu/projects/*
// @author Katherine C.
// ==/UserScript==

//Install base scripts
var basecfg_script = document.createElement('script');
basecfg_script.setAttribute('type', 'text/javascript');
basecfg_script.setAttribute('src', 'https://panzi.github.io/Browser-Ponies/basecfg.js');
basecfg_script.setAttribute('id', 'browser-ponies-config');
document.head.appendChild(basecfg_script);

var browserponies_script = document.createElement('script'); 
browserponies_script.setAttribute('type', 'text/javascript');
browserponies_script.setAttribute('src', 'https://panzi.github.io/Browser-Ponies/browserponies.js');
browserponies_script.setAttribute('id', 'browser-ponies-script');
document.head.appendChild(browserponies_script);
	
function installExtensionBrowserPonies() {
	var cfg = {
		"fadeDuration": 500,
		"volume": 1,
		"fps": 25,
		"speed": 3,
		"audioEnabled": false,
		"showFps": false,
		"showLoadProgress": true,
		"speakProbability": 0.1,
		"baseurl": "https://panzi.github.io/Browser-Ponies/",
		"spawn": {}
	};

    (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() {
        	if(BrowserPoniesBaseConfig.loaded){
            	return {status: 2, msg: 'Ready'};
            }
            else if(BrowserPonies != undefined && BrowserPoniesBaseConfig != undefined){
            	BrowserPonies.setBaseUrl(cfg.baseurl);
				BrowserPonies.loadConfig(BrowserPoniesBaseConfig);
				BrowserPonies.start();
				BrowserPoniesBaseConfig.loaded = true;
            	return {status: 1, msg: 'Not Ready'};
            }
            return {status: 0, msg: 'Not Ready'};
        };
        
        // Block and block menu descriptions
        var descriptor = {
            blocks: [
            	[' ', 'start', 'startPonies'],
            	[' ', 'stop', 'stopPonies'],
            	[' ', 'pause', 'pausePonies'],
            	[' ', 'resume', 'resumePonies'],
            	[' ', 'toggle ponies in background', 'toggleInBackground'],
            	[' ', 'remove all ponies', 'removePonies'],
            	['-'],
                [' ', 'add pony %s', 'addPony', 'derpy hooves'],
                [' ', 'add random pony', 'addRandomPony']
            ],

            menus: {
                ponies: ['derpy hooves', 'applejack','fluttershy','pinkie pie','rainbow dash','rarity','twilight sparkle']
            }
        };
		
		var ponyNames = [];
		
		//Commands
		ext.startPonies = function(){BrowserPonies.start();};
		ext.stopPonies = function(){BrowserPonies.stop();};
		ext.pausePonies = function(){BrowserPonies.pause();};
		ext.resumePonies = function(){BrowserPonies.resume();};
		ext.toggleInBackground = function(){BrowserPonies.togglePoniesToBackground()};
		ext.removePonies = function(){BrowserPonies.unspawnAll();};
		
		//Adding ponies
		ext.addPony = function(name){
			addPonyByName(name);
		}
		
		ext.addRandomPony = function(){
			checkLoaded();
			BrowserPonies.spawnRandom()
		}
		
		function addPonyByName (name){
			checkLoaded();
			if(BrowserPonies.ponies()[name] != undefined){
				//Check if the pony exists
				if(name == 'vinyl scratch'){
					//Seizure warning
					if(confirm('WARNING:\nContains flashing lights/patterns that may not be suitable for people with photosensitive epilepsy.')){
						if(BrowserPonies.ponies()[name] != undefined){
							console.log(cfg)
							cfg['spawn'] = {};
							cfg['spawn'][name] = 1;
							BrowserPonies.loadConfig(cfg);
						}
					}
				}
				else{
					console.log(cfg)
					cfg['spawn'] = {};
					cfg['spawn'][name] = 1;
					BrowserPonies.loadConfig(cfg);
				}
			}
		}
		
		function checkLoaded (){
			//Load BrowserPonies if it is not already loaded
			if(!BrowserPoniesBaseConfig.loaded){
				BrowserPonies.setBaseUrl(cfg.baseurl);
				BrowserPonies.loadConfig(BrowserPoniesBaseConfig);
				BrowserPonies.start();
				BrowserPoniesBaseConfig.loaded = true;
				ponyNames = keys(BrowserPonies.ponies());
			}
		}
		
        // Register the extension
        ScratchExtensions.register('Browser Ponies', descriptor, ext);
    })({});
}

installExtensionBrowserPonies();