preload.js 1.7 KB
Newer Older
M
Matt Bierner 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
'use strict';

(function() {
	function getConfig() {
		const queryParams = window.location.search.substring(1).split('&');
		for (var i = 0; i < queryParams.length; i++) {
			var kv = queryParams[i].split('=');
			if (kv[0] === 'config' && kv[1]) {
				return JSON.parse(decodeURIComponent(kv[1]));
			}
		}
		return {};
	}
	try {
		const config = getConfig();
		const document = window.document;

		// sets the base theme class ('vs', 'vs-dark', 'hc-black')
		const baseTheme = config.baseTheme || 'vs';
		document.body.className = 'monaco-shell ' + baseTheme;

26 27
		// makes the window draggable if there is no frame
		if  (config.frameless) {
R
Ryan Adolf 已提交
28 29
			document.documentElement.style.webkitAppRegion = 'drag';
			document.documentElement.style.height = '100%';
30 31
		}

M
Matt Bierner 已提交
32
		// adds a stylesheet with the backgrdound color
R
Ryan Adolf 已提交
33 34 35 36
		var backgroundColor = config.backgroundColor;
		if (!backgroundColor) {
			backgroundColor = baseTheme === 'hc-black' ? '#000000' : (baseTheme === 'vs' ? '#FFFFFF' : '#1E1E1E');
		}
M
Matt Bierner 已提交
37 38
		const foregroundColor = baseTheme === 'hc-black' ? '#FFFFFF' : (baseTheme === 'vs' ? '#6C6C6C' : '#CCCCCC');
		const style = document.createElement('style');
R
Ryan Adolf 已提交
39
		style.innerHTML = '.monaco-shell { background-color:' + backgroundColor + '; color:' + foregroundColor + '; }';
M
Matt Bierner 已提交
40 41 42 43 44
		document.head.appendChild(style);

	} catch (error) {
		console.error(error);
	}
45
})();