Marvin for JavaScript Example - Add custom button to the toolbar

Append a custom button to the toolbar at startup (the icon URL is relative to the editor.html document):
<script>	
    document.getElementById("sketch").addEventListener("load", function() {

		var marvin = getMarvin("sketch");
		if(marvin != null) {
			marvin.onReady(function() {
				if(typeof marvin.sketch != 'undefined') {
					marvin.sketch.addButton("custom","examples/images/custom-icon.png","W", function() {
						alert('The custom button has been pushed.');
					});
				}
			});
		}
    });
<script>