Skip to content
Snippets Groups Projects
Select Git revision
  • 7f1393ea607b5b6652542785f0bd5352362c1d3b
  • master default protected
  • develop
  • v22w09a
  • v22w08b
  • release
6 results

main.js

Blame
  • main.js 20.47 KiB
    var audioButton = false;
    var midiButton = false;
    var activateButton;
    var dataMidi;
    var editor;
    var langTools;
    
    var trashIcon = `<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-trash" width="24" height="24" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
    <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
    <line x1="4" y1="7" x2="20" y2="7"></line>
    <line x1="10" y1="11" x2="10" y2="17"></line>
    <line x1="14" y1="11" x2="14" y2="17"></line>
    <path d="M5 7l1 12a2 2 0 0 0 2 2h8a2 2 0 0 0 2 -2l1 -12"></path>
    <path d="M9 7v-3a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v3"></path>
    </svg>`;
    var recordIcon = `<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-player-record" width="24" height="24" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
    <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
    <circle cx="12" cy="12" r="7"></circle>
    </svg>`;
    var stopIcon = `<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-player-stop" width="24" height="24" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
    <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
    <rect x="5" y="5" width="14" height="14" rx="2"></rect>
    </svg>`;
    var pauseIcon = `<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-player-pause" width="24" height="24" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
    <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
    <rect x="6" y="5" width="4" height="14" rx="1"></rect>
    <rect x="14" y="5" width="4" height="14" rx="1"></rect>
    </svg>`;
    var playIcon = `<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-player-play" width="24" height="24" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
    <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
    <path d="M7 4v16l13 -8z"></path>
    </svg>`;
    var minus = "<svg xmlns=\"http://www.w3.org/2000/svg\" class=\"icon icon-tabler icon-tabler-minus\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" stroke-width=\"1.5\" stroke=\"currentColor\" fill=\"none\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path stroke=\"none\" d=\"M0 0h24v24H0z\" fill=\"none\"></path><circle cx=\"12\" cy=\"12\" r=\"9\"></circle><line x1=\"9\" y1=\"12\" x2=\"15\" y2=\"12\"></line></svg>";
    var plus = "<svg xmlns=\"http://www.w3.org/2000/svg\" class=\"icon icon-tabler icon-tabler-plus\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" stroke-width=\"1.5\" stroke=\"currentColor\" fill=\"none\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path stroke=\"none\" d=\"M0 0h24v24H0z\" fill=\"none\"></path><circle cx=\"12\" cy=\"12\" r=\"9\"></circle><line x1=\"9\" y1=\"12\" x2=\"15\" y2=\"12\"></line><line x1=\"12\" y1=\"9\" x2=\"12\" y2=\"15\"></line></svg>";
    var icon = "<svg xmlns=\"http://www.w3.org/2000/svg\" class=\"icon icon-tabler icon-tabler-grip-vertical\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" stroke-width=\"1.5\" stroke=\"currentColor\" fill=\"none\" stroke-linecap=\"round\" stroke-linejoin=\"round\"> <path stroke=\"none\" d=\"M0 0h24v24H0z\" fill=\"none\"></path> <circle cx=\"9\" cy=\"5\" r=\"1\"></circle> <circle cx=\"9\" cy=\"12\" r=\"1\"></circle> <circle cx=\"9\" cy=\"19\" r=\"1\"></circle> <circle cx=\"15\" cy=\"5\" r=\"1\"></circle> <circle cx=\"15\" cy=\"12\" r=\"1\"></circle> <circle cx=\"15\" cy=\"19\" r=\"1\"></circle></svg>";
    
    function setAutocompleteParameters() {
    	var autoComplete = [];
    	chrome.storage.local.get(['parameters'], function (result) {
    		parameters = JSON.parse(result.parameters);
    		parameters.forEach(p => {
    			autoComplete.push({ value: '[' + p[1] + ']', score: 1, meta: p[3] + " " + p[4] });
    		});
    	});
    	const cssTemplate = {
    		getCompletions: (editor, session, pos, prefix, callback) => {
    			callback(null, autoComplete);
    		},
    	};
    	langTools.addCompleter(cssTemplate);
    }
    
    /**
     * Load the editor and add css
     */
    function loadEditor() {
    	editor = ace.edit("editor", {
    		autoScrollEditorIntoView: true,
    		maxLines: 40,
    		minLines: 2
    	});
    	editor.setTheme("ace/theme/tomorrow_night_blue");
    	editor.session.setMode("ace/mode/css");
    	editor.getSession().setUseWorker(false); // Disable syntax checking, not working in chrome extension V3
    	langTools = ace.require('ace/ext/language_tools'); // Add autocomplete
    	langTools.setCompleters([langTools.snippetCompleter, langTools.keyWordCompleter]);
    	editor.setOptions({
    		enableBasicAutocompletion: true,
    		enableSnippets: true,
    		enableLiveAutocompletion: true