-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathextside.min.js
2 lines (2 loc) · 12 KB
/
extside.min.js
1
2
if(typeof INJECTED=="undefined"){const POWERUPDEBUG=false;if(POWERUPDEBUG)console.log("Powerup: Dashboard powerups installed.");window.jQuery||console.log("Powerup: ERROR - No jQuery...");$(document).ready((function(){if(POWERUPDEBUG)console.log("Powerup: document ready");$(window).on("load hashchange",powerupListener);if(POWERUPDEBUG)console.log("Powerup: listener loaded");powerupListener()}));const ext_url=chrome.runtime.getURL("");const version=chrome.runtime.getManifest().version;const ext_id=chrome.runtime.id;const GH_URL="https://raw.githubusercontent.com/dynatrace-oss/DynatraceDashboardPowerups/master/";var HotFixMode=0;var waits=0;var timeout;let zoomA=false;function powerupListener(){if(window.location.hash.startsWith("#dashboard;")||window.location.hash.startsWith("#dashboard/dashboard;")){if(POWERUPDEBUG)console.log("Powerup: on a dashboard, power-up!");window.requestAnimationFrame(powerupDashboards)}else{if(POWERUPDEBUG)console.log("Powerup: not a dashboard, quit.");return}}function powerupDashboards(){let dGrid=document.querySelector('[uitestid="gwt-debug-dashboardGrid"]');if(dGrid){setTimeout((function(){if(!zoomA){dGrid.style.visibility="hidden";dGrid.style.zoom="10%";zoomA=true;setTimeout((function(){dGrid.style.zoom="100%";dGrid.style.visibility="visible"}),100)}}),100)}if(document.readyState=="complete"&&$('[uitestid="gwt-debug-dashboardGrid"]').length&&!$(".loader").length&&!$('[uitestid="gwt-debug-tileLoader"]:visible').length){dGrid.style.zoom="100%";dGrid.style.visibility="visible";if(POWERUPDEBUG)console.log("Powerup: things look ready, begin power-ups...");let config_p=loadConfig();$.when(config_p).done((function(config){let clientside_p=injectClientsideLib(config);injectCSS(config);if(POWERUPDEBUG)console.log("Powerup: clientside libs injected.");$.when(clientside_p).then((()=>{startBeaconListener();injectOtherModules(config);injectHighchartsModules(config);injectD3Modules(config);injectClientsideString(`\n DashboardPowerups.POWERUP_EXT_URL='${ext_url}';\n DashboardPowerups.VERSION='${version}';\n DashboardPowerups.EXT_ID='${ext_id}';\n DashboardPowerups.config = ${JSON.stringify(config)};\n DashboardPowerups.GridObserver.launchGridObserver();\n `);injectReportLib(config);console.log("Powerup: powerups complete.")}))}));return}else{waits++;if(waits%10==0)console.log(`Powerup: WARN - still doesn't look like things are loaded yet, slept ${waits}s.`);clearTimeout(timeout);timeout=setTimeout(powerupDashboards,1e3)}}function injectClientsideLib(config){let p=$.Deferred();if(!$("#DashboardPowerupsTag").length){if(config.Powerups.libLocation=="gh"||HotFixMode){console.log(`POWERUP: Loading libs from: GH...`);fetch(GH_URL+"clientside.min.js").then((response=>response.text())).then((text=>{var $s=$("<script>").attr("id","DashboardPowerupsTag").text(text).appendTo("body");p.resolve(true)})).catch((err=>{console.log(`POWERUP: Loading libs from: GH failed...`,err);let lib=ext_url+(POWERUPDEBUG?"clientside.js":"clientside.min.js");console.log(`POWERUP: Loading libs from: ${lib}...`);var $s=$("<script>").attr("id","DashboardPowerupsTag").attr("src",lib).appendTo("body");p.resolve(true)}))}else{let lib=(config.Powerups.libLocation=="gh"?GH_URL:ext_url)+(POWERUPDEBUG?"clientside.js":"clientside.min.js");console.log(`POWERUP: Loading libs from: ${lib}...`);var $s=$("<script>").attr("id","DashboardPowerupsTag").attr("src",lib).appendTo("body");p.resolve(true)}}else{p.resolve(false)}return p}function injectClientsideString(s){let id=uniqId();let wrapped=`\n function injectedFunction${id}(tries=0){\n if(typeof(DashboardPowerups) == "object"){\n ${s}\n } else {\n tries++;\n if(tries>20){\n console.log("Powerup: FATAL client lib never loaded.");\n return false;\n } else\n setTimeout(()=>{injectedFunction${id}(tries)},50);\n }\n }\n injectedFunction${id}();`;var $s=$("<script>").append(document.createTextNode(wrapped)).appendTo("body")}var uniqId=function(){var i=0;return function(){return i++}}();function injectCSS(config){let p=$.Deferred();if($("#PowerUpCSS").length<1){if(config.Powerups.libLocation=="gh"||HotFixMode){console.log(`POWERUP: Loading css from: GH...`);fetch(GH_URL+"powerup.css").then((response=>response.text())).then((text=>{var $s=$("<style>").attr("id","PowerUpCSS").text(text).appendTo("head");p.resolve(true)})).catch((err=>{console.log(`POWERUP: Loading css from: GH failed...`,err);console.log(`POWERUP: Loading css locally...`);var $link=$("<link>").attr("id","PowerUpCSS").attr("rel","stylesheet").attr("type","text/css").attr("href",ext_url+"powerup.css").appendTo("head");p.resolve(true)}))}else{var $link=$("<link>").attr("id","PowerUpCSS").attr("rel","stylesheet").attr("type","text/css").attr("href",ext_url+"powerup.css").appendTo("head");p.resolve(true)}}return p}function loadConfig(){let p=$.Deferred();let defaultConfig={Powerups:{tooltipPU:true,colorPU:true,svgPU:true,worldmapPU:true,bannerPU:true,usqlstackPU:true,usqlcolorPU:true,linePU:true,heatmapPU:true,sankeyPU:true,funnelPU:true,mathPU:true,datePU:true,gaugePU:true,comparePU:true,tablePU:true,honeycombPU:true,treemapPU:true,reporting:true,debug:false,colorPUTarget:"Text",animateCritical:"3 Pulses",animateWarning:"Never",sunburnMode:false,libLocation:"ext",ackedVersion:"0.0",BeaconOptOut:false,uuid:typeof uuidv4==="function"?uuidv4():""}};if(!chrome||!chrome.storage||!chrome.storage.local)return false;chrome.storage.local.get(["Powerups","hotfixMode"],(function(result){HotFixMode=result.hotfixMode?result.hotfixMode:0;if(result&&result.Powerups&&Object.keys(defaultConfig.Powerups).length===Object.keys(result.Powerups).length){if(result.Powerups.debug)console.log("Powerup: DEBUG - (extside) config from storage is: "+JSON.stringify(result));p.resolve(result)}else{console.log("Powerup: WARN - stored config format didn't match, merging...");if(typeof result=="object"&&typeof result.Powerups=="object"){for(const[key,value]of Object.entries(result.Powerups)){if(typeof defaultConfig[key]!="undefined")defaultConfig[key]=value}}writeConfig(defaultConfig);p.resolve(defaultConfig)}}));chrome.runtime.onMessage.addListener((function(request,sender,sendResponse){switch(request.Powerup){case"UpdateConfig":{chrome.storage.local.get(["Powerups"],(function(result){let s=`DashboardPowerups.config = ${JSON.stringify(result)};`;injectClientsideString(s);sendResponse({Powerup:"InjectedUpdatedConfig"})}));break}case"GenerateReport":{chrome.storage.local.get(["Powerups"],(function(result){let s=`if(typeof(PowerupReporting.openReportGenerator)=="function") PowerupReporting.openReportGenerator();\n else console.log("Powerup: generateReport called but lib not loaded");`;injectClientsideString(s);sendResponse({Powerup:"LaunchedReportGeneration"})}));break}}switch(request.PowerUpResult){case"PU_BACKGROUND":case"PU_IMAGE":insertImg(request.targetSelector,request.dataURL);break}return true}));return p}function writeConfig(defaultConfig){if(!chrome||!chrome.storage||!chrome.storage.local)return false;chrome.storage.local.set(defaultConfig,(function(){if(defaultConfig.Powerups.debug)console.log("Powerup: (extside) config storage set to "+JSON.stringify(defaultConfig))}))}function injectHighchartsModule(mod){let id="HighchartsMod_"+mod;let src=`${ext_url}3rdParty/Highcharts/modules/6.2.0/${mod}.js`;if(!$("#"+id).length){let $s=$("<script>").attr("id",id).attr("src",src).appendTo("body")}else{}}function injectHighchartsModules(config){if(config.Powerups.heatmapPU){injectHighchartsModule("heatmap-fixed");injectClientsideString(`\n //Highcharts Heatmap bug workaround\n if(Highcharts && Highcharts.charts)\n Highcharts.charts\n .filter(x=>typeof(x)!=="undefined")\n .filter(x=>typeof(x.colorAxis)=="undefined")\n .forEach(x=>{x.colorAxis=[];});\n `)}if(config.Powerups.sankeyPU){injectHighchartsModule("sankey")}if(config.Powerups.treemapPU)injectHighchartsModule("treemap");if(config.Powerups.gaugePU)injectHighchartsModule("solid-gauge");if(config.Powerups.honeycombPU)injectHighchartsModule("tilemap");if(config.Powerups.treemapPU)injectHighchartsModule("treemap");if(config.Powerups.reporting)injectHighchartsModule("annotations")}function injectD3Modules(config){if(config.Powerups.funnelPU){injectD3Module("d3-funnel.min.js")}}function injectD3Module(mod){let id="D3_"+mod;let src=`${ext_url}3rdParty/D3/${mod}`;if(!$("#"+id).length){let $s=$("<script>").attr("id",id).attr("src",src).appendTo("body")}else{}}function injectOtherModules(config){if(!config.Powerups.BeaconOptOut){injectOtherModule("3rdParty/node_modules/@dynatrace/openkit-js/dist/browser/openkit.js","OpenKitBuilder")}if(config.Powerups.sankeyPU){injectOtherModule("3rdParty/node_modules/@iconfu/svg-inject/dist/svg-inject.min.js","SVGInject")}if(config.Powerups.mathPU){injectOtherModule("3rdParty/node_modules/math-expression-evaluator/dist/browser/math-expression-evaluator.min.js","mexp")}if(config.Powerups.datePU){injectOtherModule("3rdParty/date_fns.min.js","dateFns")}if(config.Powerups.tablePU){injectOtherModule("3rdParty/xlsx.mini.min.js","XLSX")}}function injectOtherModule(mod,glob){let src=ext_url+encodeURI(mod);injectClientsideString(`\n if (typeof (${glob}) == "undefined" &&\n ! $("#powerup_lib_${glob}").length) {\n $("<script>")\n .attr("id", "powerup_lib_${glob}")\n .attr("src", "${src}" )\n .appendTo("body");\n }`)}function startBeaconListener(){if(typeof BEACON_LISTENING=="undefined"){window.addEventListener("message",(function(event){if(event.source!=window)return;if(event.data.OpenKit){console.log("POWERUP: Content script received: "+event.data.OpenKit);chrome.runtime.sendMessage(event.data)}if(event.data.PowerUp){extsidePowerup(event)}}),false)}BEACON_LISTENING=true}function extsidePowerup(event){switch(event.data.PowerUp){case"PU_BACKGROUND":case"PU_IMAGE":chrome.runtime.sendMessage(event.data);break}}function insertImg(target,file){let $target=$(target);$target.css("background-image",`url(${file})`).addClass("powerupBackground")}function insertImgResponse(target,request,response){const allowedFileTypes=["image/png","image/jpeg","image/gif"];response.blob().then((blobResponse=>{let type=blobResponse.type;let url=response.url||request.url;if(allowedFileTypes.indexOf(type)<0){let err=`POWERUP: insertImgResponse - not an allowed filetype: '${type}' for '${url}'`;console.warn(err);errorBeacon(err);return false}else{let reader=new FileReader;reader.onload=e=>{let file=e.target.result;let $target=$(target);$target.css("background-image",`url(${file})`).addClass("powerupBackground")};reader.readAsDataURL(blobResponse)}}))}function errorBeacon(err){chrome.runtime.sendMessage({OpenKit:"error_beacon",context:"extside",err:err})}function injectReportLib(config){let p=$.Deferred();if(!$("#PowerupsReportingTag").length){if(config.Powerups.libLocation=="gh"||HotFixMode){console.log(`POWERUP: Loading reporting lib from: GH...`);fetch(GH_URL+"reporting.min.js").then((response=>response.text())).then((text=>{var $s=$("<script>").attr("id","PowerupsReportingTag").text(text).appendTo("body");p.resolve(true)})).catch((err=>{console.log(`POWERUP: Loading reporting lib from: GH failed...`,err);let lib=ext_url+(POWERUPDEBUG?"reporting.js":"reporting.min.js");console.log(`POWERUP: Loading libs from: ${lib}...`);var $s=$("<script>").attr("id","PowerupsReportingTag").attr("src",lib).appendTo("body");p.resolve(true)}))}else{let lib=(config.Powerups.libLocation=="gh"?GH_URL:ext_url)+(POWERUPDEBUG?"reporting.js":"reporting.min.js");console.log(`POWERUP: Loading reporting libs from: ${lib}...`);var $s=$("<script>").attr("id","PowerupsReportingTag").attr("src",lib).appendTo("body");p.resolve(true)}}else{p.resolve(false)}return p}INJECTED=true}
//# sourceMappingURL=https://raw.githubusercontent.com/dynatrace-oss/DynatraceDashboardPowerups/master/extside.min.js.map