10 lines
3.5 KiB
JavaScript
10 lines
3.5 KiB
JavaScript
/*
|
|
* noVNC: HTML5 VNC client
|
|
* Copyright (C) 2012 Joel Martin
|
|
* Copyright (C) 2013 NTT corp.
|
|
* Licensed under MPL 2.0 (see LICENSE.txt)
|
|
*
|
|
* See README.md for usage and integration instructions.
|
|
*/
|
|
|
|
var WebUtil={},$D;window.$D||(window.$D=function(e){return document.getElementById?document.getElementById(e):document.all?document.all[e]:document.layers?document.layers[e]:void 0}),WebUtil.init_logging=function(e){"use strict";if(void 0!==e)Util._log_level=e;else{var t=document.location.href.match(/logging=([A-Za-z0-9\._\-]*)/);Util._log_level=(t||["",Util._log_level])[1]}Util.init_logging()},WebUtil.dirObj=function(e,t,i){"use strict";t||(t=2),i||(i="");var n="";for(var o in e)if(t>1&&"object"==typeof e[o])n+=WebUtil.dirObj(e[o],t-1,i+"."+o);else{var r="";r=void 0===e[o]?"undefined":e[o].toString().replace("\n"," "),r.length>30&&(r=r.substr(0,30)+"..."),n+=i+"."+o+": "+r+"\n"}return n},WebUtil.getQueryVar=function(e,t){"use strict";var i=new RegExp(".*[?&]"+e+"=([^&#]*)"),n=document.location.href.match(i);return void 0===t&&(t=null),n?decodeURIComponent(n[1]):t},WebUtil.getHashVar=function(e,t){"use strict";var i=new RegExp(".*[&#]"+e+"=([^&]*)"),n=document.location.hash.match(i);return void 0===t&&(t=null),n?decodeURIComponent(n[1]):t},WebUtil.getConfigVar=function(e,t){"use strict";var i=WebUtil.getHashVar(e);return null===i&&(i=WebUtil.getQueryVar(e,t)),i},WebUtil.createCookie=function(e,t,i){"use strict";var n,o;i?(n=new Date,n.setTime(n.getTime()+24*i*60*60*1e3),o="; expires="+n.toGMTString()):o="";var r;r="https:"===document.location.protocol?"; secure":"",document.cookie=e+"="+t+o+"; path=/"+r},WebUtil.readCookie=function(e,t){"use strict";for(var i=e+"=",n=document.cookie.split(";"),o=0;o<n.length;o+=1){for(var r=n[o];" "===r.charAt(0);)r=r.substring(1,r.length);if(0===r.indexOf(i))return r.substring(i.length,r.length)}return void 0!==t?t:null},WebUtil.eraseCookie=function(e){"use strict";WebUtil.createCookie(e,"",-1)},WebUtil.initSettings=function(e){"use strict";var t=Array.prototype.slice.call(arguments,1);window.chrome&&window.chrome.storage?window.chrome.storage.sync.get(function(i){WebUtil.settings=i,console.log(WebUtil.settings),e&&e.apply(this,t)}):e&&e.apply(this,t)},WebUtil.writeSetting=function(e,t){"use strict";window.chrome&&window.chrome.storage?WebUtil.settings[e]!==t&&(WebUtil.settings[e]=t,window.chrome.storage.sync.set(WebUtil.settings)):localStorage.setItem(e,t)},WebUtil.readSetting=function(e,t){"use strict";var i;return i=window.chrome&&window.chrome.storage?WebUtil.settings[e]:localStorage.getItem(e),void 0===i&&(i=null),null===i&&void 0!==typeof t?t:i},WebUtil.eraseSetting=function(e){"use strict";window.chrome&&window.chrome.storage?(window.chrome.storage.sync.remove(e),delete WebUtil.settings[e]):localStorage.removeItem(e)},WebUtil.getStylesheets=function(){"use strict";for(var e=document.getElementsByTagName("link"),t=[],i=0;i<e.length;i+=1)e[i].title&&e[i].rel.toUpperCase().indexOf("STYLESHEET")>-1&&t.push(e[i]);return t},WebUtil.selectStylesheet=function(e){"use strict";void 0===e&&(e="default");for(var t=WebUtil.getStylesheets(),i=0;i<t.length;i+=1){var n=t[i];n.title===e?(Util.Debug("Using stylesheet "+e),n.disabled=!1):n.disabled=!0}return e},WebUtil.injectParamIfMissing=function(e,t,i){e="/"+e;var n=document.createElement("a");n.href=e;var o,r=encodeURIComponent(t)+"=";return o=n.search?n.search.slice(1).split("&"):[],o.some(function(e){return e.startsWith(r)})||(o.push(r+encodeURIComponent(i)),n.search="?"+o.join("&")),"/"==n.pathname.charAt(0)?n.pathname.slice(1)+n.search+n.hash:n.pathname+n.search+n.hash}; |