376 lines
18 KiB
JavaScript
376 lines
18 KiB
JavaScript
// ==UserScript==
|
|
// @name Status.io Selector 2
|
|
// @namespace https://status.io
|
|
// @description Effort to simplify configuration of incidents/maintenance windows
|
|
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js
|
|
// @require http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/jquery-ui.min.js
|
|
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
|
|
// @grant GM_addStyle
|
|
// @grant GM_setClipboard
|
|
// @version 0.0.1
|
|
// ==/UserScript==
|
|
|
|
|
|
// draw frame
|
|
var zNode = document.createElement('div');
|
|
zNode.innerHTML = 'Loading...';
|
|
zNode.setAttribute('id', 'myContainer');
|
|
document.body.appendChild(zNode);
|
|
|
|
if (window.location.href.indexOf("5d49ec10226b9e13cb6a422e") > -1) {
|
|
var componentArray = ["api", "auth", "compute", "jobs", "odbc", "webapp", "sql"];
|
|
var regionArray = ["canadacentral", "canadaeast", "centralindia", "southindia", "westindia",
|
|
"switzerlandnorth", "norwayeast", "westus2", "westus", "southcentralus",
|
|
"westeurope", "northeurope", "ukwest", "uksouth", "southafricanorth",
|
|
"uaenorth", "australiaeast", "australiacentral", "australiacentral2",
|
|
"australiasoutheast", "japaneast", "japanwest", "koreacentral",
|
|
"southeastasia", "eastasia", "brazilsouth", "eastus2", "eastus",
|
|
"centralus", "northcentralus", "francecentral", "chinanorth2", "chinaeast2",
|
|
"usgovvirginia", "usgovarizona"];
|
|
var selectedComponents = new Map();
|
|
var selectedRegions = new Map();
|
|
|
|
// init maps
|
|
for (i = 0; i < componentArray.length; i++) {
|
|
selectedComponents.set(componentArray[i], false);
|
|
}
|
|
for (i = 0; i < regionArray.length; i++) {
|
|
selectedRegions.set(regionArray[i], false)
|
|
}
|
|
var profilesHTML = '<center><button id="controlPlanesButton type="button">Controlplanes</button> ' +
|
|
'<button id="stagesButton type="button">Stages</button> <button id="dataPlanesButton type="button">' +
|
|
'Dataplanes</button></center>';
|
|
|
|
var controlplanesHTML = '<button id="canadaCentralButton" type="button">canadacentral</button><button id="centralIndiaButton" type="button>centralindia</button>' +
|
|
'<button id="switzerlandNorthButton" type="button">switzerlandnorth</button><button id="norwayEastButton" type="button">norwayeast</button></br></br>' +
|
|
'<button id="westUsButton" type="button">westus</button></br></br>' +
|
|
'<button id="westEuropeButton" type="button">westeurope</button><button id="ukWestButton" type="button">ukwest</button>' +
|
|
'<button id="southAfricaNorthButton" type="button">southafricanorth</button><button id="uaeNorthButton" type="button">uaenorth</button></br></br>' +
|
|
'<button id="australiaEastButton" type="button">australiaeast</button><button id="japanEastButton" type="button">japaneast</button>' +
|
|
'<button id="koreaCentralButton" type="button">koreacentral</button><button id="southeastAsiaButton" type="button">southeastasia</button></br></br>' +
|
|
'<button id="brazilSouthButton" type="button">brazilsouth</button><button id="eastUs2Button" type="button">eastus2</button>' +
|
|
'<button id="franceCentralButton" type="button">francecentral</button></br></br>' +
|
|
'<button id="chinaNorth2Button" type="button">chinanorth2</button><button id="chinaEast2Button" type="button">chinaeast2</button>' +
|
|
'<button id="usGovVirginiaButton" type="button">usgovvirginia</button><button id="usGovArizonaButton" type="button">usgovarizona</button>';
|
|
var stagesHTML = '<button id="stage1Button" type="button">Stage-1</button><button id="stage1.5Button" type="button">Stage-1.5</button>' +
|
|
'<button id="stage2Button" type="button">Stage-2</button><button id="stage3AMButton" type="button">Stage-3AM</button>' +
|
|
'<button id="stage3PMButton" type="button">Stage-3PM</button><button id="govCloudButton" type="button">Govcloud</button>' +
|
|
'<button id="mooncakeButton" type="button">Mooncake</button>';
|
|
var componentsHTML = '<button id="allComponentsButton" type="button">AllComponents</button> <button id="apiButton" type="button">API</button>' +
|
|
'<button id="authButton">Auth</button><button id="computeButton" type="button">Compute</button><button id="jobsButton" type="button">Jobs</button>' +
|
|
'<button id="odbcButton" type="button">ODBC/JDBC</button><button id="webappButton" type="button">Webapp</button>' +
|
|
'<button id="sqlButton" type="button">SQL</button></br></br>';
|
|
function canadaEastButtonClickAction(zEvent) {
|
|
toggleRegion("canadaeast");
|
|
toggleButtonColor("canadaEastButton");
|
|
};
|
|
function canadaCentralButtonClickAction(zEvent) {
|
|
toggleRegion("canadacentral");
|
|
toggleButtonColor("canadaCentralButton");
|
|
};
|
|
function centralIndiaButtonClickAction(zEvent) {
|
|
toggleRegion("centralindia");
|
|
toggleButtonColor("centralIndiaButton");
|
|
};
|
|
function southIndiaButtonClickAction(zEvent) {
|
|
toggleRegion("southindia");
|
|
toggleButtonColor("southIndiaButton");
|
|
};
|
|
function westIndiaButtonClickAction(zEvent) {
|
|
toggleRegion("westindia");
|
|
toggleButtonColor("westIndiaButton");
|
|
};
|
|
function switzerlandNorthButtonClickAction(zEvent) {
|
|
toggleRegion("switzerlandnorth");
|
|
toggleButtonColor("switzerlandNorthButton");
|
|
};
|
|
function norwayEastButtonClickAction(zEvent) {
|
|
toggleRegion("norwayeast");
|
|
toggleButtonColor("norwayEastButton");
|
|
};
|
|
function westUsButtonClickAction(zEvent) {
|
|
toggleRegion("westus");
|
|
toggleButtonColor("westUsButton");
|
|
};
|
|
function westUs2ButtonClickAction(zEvent) {
|
|
toggleRegion("westus2");
|
|
toggleButtonColor("westUs2Button");
|
|
};
|
|
function southCentralUsButtonClickAction(zEvent) {
|
|
toggleRegion("southcentralus");
|
|
toggleButtonColor("southCentralUsButton");
|
|
};
|
|
function westEuropeButtonClickAction(zEvent) {
|
|
toggleRegion("westeurope");
|
|
toggleButtonColor("westEuropeButton");
|
|
};
|
|
function northEuropeButtonClickAction(zEvent) {
|
|
toggleRegion("northeurope");
|
|
toggleButtonColor("northEuropeButton");
|
|
};
|
|
function northEuropeButtonClickAction(zEvent) {
|
|
toggleRegion("northeurope");
|
|
toggleButtonColor("northEuropeButton");
|
|
};
|
|
function ukWestButtonClickAction(zEvent) {
|
|
toggleRegion("ukwest");
|
|
toggleButtonColor("ukWestButton");
|
|
};
|
|
function ukSouthButtonClickAction(zEvent) {
|
|
toggleRegion("uksouth");
|
|
toggleButtonColor("ukSouthButton");
|
|
};
|
|
function southAfricaNorthButtonClickAction(zEvent) {
|
|
toggleRegion("southafricanorth");
|
|
toggleButtonColor("southAfricaNorthButton");
|
|
};
|
|
function uaeNorthButtonClickAction(zEvent) {
|
|
toggleRegion("uaenorth");
|
|
toggleButtonColor("uaeNorthButton");
|
|
};
|
|
function loadDataplanes() {
|
|
var locationHTML = '<button id="canadaCentralButton" type="button">canadacentral</button><button id="canadaEastButton" type="button">canadaeast</button>' +
|
|
'<button id="centralIndiaButton" type="button">centralindia</button><button id="southIndiaButton" type="button">southindia</button>' +
|
|
'<button id="westIndiaButton" type="button">westindia</button><button id="switzerlandNorthButton" type="button">switzerlandnorth</button>' +
|
|
'<button id="norwayEastButton" type="button">norwayeast</button></br></br>' +
|
|
'<button id="westUsButton" type="button">westus</button><button id="westUs2Button" type="button">westus2</button>' +
|
|
'<button id="southCentralUsButton" type="button">southcentralus</button></br></br>' +
|
|
'<button id="westEuropeButton" type="button">westeurope</button><button id="northEuropeButton" type="button">northeurope</button>' +
|
|
'<button id="ukWestButton" type="button">ukwest</button><button id="ukSouthButton" type="button">uksouth</button>' +
|
|
'<button id="southAfricaNorthButton" type="button">southafricanorth</button><button id="uaeNorthButton" type="button">uaenorth</button></br></br>' +
|
|
'<button id="australiaEastButton" type="button">australiaeast</button><button id="australiaCentralButton" type="button">australiacentral</button>' +
|
|
'<button id="australiaCentral2Button" type="button">australiacentral2</button><button id="australiaSoutheastButton" type="button">australiasoutheast</button>' +
|
|
'<button id="japanEastButton" type="button">japaneast</button></br><button id="japanWestButton" type="button">japanwest</button>' +
|
|
'<button id="koreaCentralButton" type="button">koreacentral</button><button id="southeastAsiaButton" type="button">southeastasia</button>' +
|
|
'<button id="eastAsiaButton" type="button">eastasia</button></br></br>' +
|
|
'<button id="brazilSouthButton" type="button">brazilsouth</button><button id="eastUs2Button" type="button">eastus2</button>' +
|
|
'<button id="eastUsButton" type="button">eastus</button><button id="centralUsButton" type="button">centralus</button>' +
|
|
'<button id="northCentralUsButton" type="button">northcentralus</button><button id="franceCentralButton" type="button">francecentral</button></br></br>' +
|
|
'<button id="chinaNorth2Button" type="button">chinanorth2</button><button id="chinaEast2Button" type="button">chinaeast2</button>' +
|
|
'<button id="usGovVirginiaButton" type="button">usgovvirginia</button><button id="usGovArizonaButton" type="button">usgovarizona</button>';
|
|
|
|
|
|
zNode.innerHTML = profilesHTML + '<hr class="solid">' + locationHTML + '<hr class="solid">' + componentsHTML + '<button id="applyButton" type="button">Apply Selection</button>';
|
|
|
|
document.getElementById("canadaCentralButton").addEventListener("click", canadaCentralButtonClickAction, false);
|
|
document.getElementById("canadaEastButton").addEventListener("click", canadaEastButtonClickAction, false);
|
|
document.getElementById("centralIndiaButton").addEventListener("click", centralIndiaButtonClickAction, false);
|
|
document.getElementById("southIndiaButton").addEventListener("click", southIndiaButtonClickAction, false);
|
|
document.getElementById("westIndiaButton").addEventListener("click", westIndiaButtonClickAction, false);
|
|
document.getElementById("switzerlandNorthButton").addEventListener("click", switzerlandNorthButtonClickAction, false);
|
|
document.getElementById("norwayEastButton").addEventListener("click", norwayEastButtonClickAction, false);
|
|
document.getElementById("westUsButton").addEventListener("click", westUsButtonClickAction, false);
|
|
document.getElementById("westUs2Button").addEventListener("click", westUs2ButtonClickAction, false);
|
|
document.getElementById("southCentralUsButton").addEventListener("click", southCentralUsButtonClickAction, false);
|
|
document.getElementById("westEuropeButton").addEventListener("click", westEuropeButtonClickAction, false);
|
|
document.getElementById("northEuropeButton").addEventListener("click", northEuropeButtonClickAction, false);
|
|
document.getElementById("ukWestButton").addEventListener("click", ukWestButtonClickAction, false);
|
|
document.getElementById("ukSouthButton").addEventListener("click", ukSouthButtonClickAction, false);
|
|
document.getElementById("southAfricaNorthButton").addEventListener("click", southAfricaNorthButtonClickAction, false);
|
|
document.getElementById("uaeNorthButton").addEventListener("click", uaeNorthButtonClickAction, false);
|
|
// document.getElementById("Button").addEventListener("click", ButtonClickAction, false);
|
|
};
|
|
loadDataplanes();
|
|
}
|
|
|
|
if (window.location.href.indexOf("5cf02dde58a00904bda41926") > -1) {
|
|
}
|
|
|
|
if (window.location.href.indexOf("60087ab5608daf0535dc8e23") > -1) {
|
|
}
|
|
// setup some variables
|
|
var apiGroup = $("div.form-group").filter(":contains('API Service')");
|
|
var authGroup = $("div.form-group").filter(":contains('Authentication')");
|
|
var computeGroup = $("div.form-group").filter(":contains('Compute Service')");
|
|
var jobsGroup = $("div.form-group").filter(":contains('Jobs Service')");
|
|
var odbcGroup = $("div.form-group").filter(":contains('ODBC/JDBC Service')");
|
|
var webappGroup = $("div.form-group").filter(":contains('User Interface')");
|
|
var sqlGroup = $("div.form-group").filter(":contains('Databricks SQL')");
|
|
|
|
// component buttons
|
|
|
|
function authButtonClickAction(zEvent) {
|
|
toggleComponent("auth");
|
|
toggleButtonColor("authButton");
|
|
}
|
|
function apiButtonClickAction(zEvent) {
|
|
toggleComponent("api");
|
|
toggleButtonColor("apiButton");
|
|
}
|
|
function computeButtonClickAction(zEvent) {
|
|
toggleComponent("compute");
|
|
toggleButtonColor("computeButton");
|
|
}
|
|
function jobsButtonClickAction(zEvent) {
|
|
toggleComponent("jobs");
|
|
toggleButtonColor("jobsButton");
|
|
}
|
|
function odbcButtonClickAction(zEvent) {
|
|
toggleComponent("odbc");
|
|
toggleButtonColor("odbcButton");
|
|
}
|
|
function webappButtonClickAction(zEvent) {
|
|
toggleComponent("webapp");
|
|
toggleButtonColor("webappButton");
|
|
}
|
|
function sqlButtonClickAction(zEvent) {
|
|
toggleComponent("sql");
|
|
toggleButtonColor("sqlButton");
|
|
}
|
|
document.getElementById("apiButton").addEventListener("click", apiButtonClickAction, false);
|
|
document.getElementById("authButton").addEventListener("click", authButtonClickAction, false);
|
|
document.getElementById("computeButton").addEventListener("click", computeButtonClickAction, false);
|
|
document.getElementById("jobsButton").addEventListener("click", jobsButtonClickAction, false);
|
|
document.getElementById("odbcButton").addEventListener("click", odbcButtonClickAction, false);
|
|
document.getElementById("webappButton").addEventListener("click", webappButtonClickAction, false);
|
|
document.getElementById("sqlButton").addEventListener("click", sqlButtonClickAction, false);
|
|
document.getElementById("allComponentsButton").addEventListener("click", allComponentsButtonClickAction, false);
|
|
|
|
|
|
// aux buttons
|
|
document.getElementById("applyButton").addEventListener("click", applyButtonClickAction, false);
|
|
// aux functions
|
|
function applyButtonClickAction(zEvent) {
|
|
apply();
|
|
}
|
|
function toggleComponent(component) {
|
|
if (checkComponent(component) == false) {
|
|
selectComponent(component);
|
|
} else {
|
|
deselectComponent(component);
|
|
}
|
|
}
|
|
function toggleButtonColor(buttonName) {
|
|
var bg = document.getElementById(buttonName).style.background;
|
|
if(bg != '') {
|
|
clearButtonColor(buttonName);
|
|
} else {
|
|
setButtonColor(buttonName);
|
|
}
|
|
}
|
|
function checkComponent(component) {
|
|
var status = selectedComponents.get(component);
|
|
return status;
|
|
}
|
|
function checkRegion(region) {
|
|
var status = selectedRegions.get(region)
|
|
return status;
|
|
}
|
|
function selectComponent(component) {
|
|
selectedComponents.set(component, true);
|
|
console.log(selectedComponents);
|
|
}
|
|
function deselectComponent(component) {
|
|
selectedComponents.set(component, false);
|
|
console.log(selectedComponents);
|
|
}
|
|
function toggleRegion(region) {
|
|
if (checkRegion(region) == false) {
|
|
selectRegion(region);
|
|
} else {
|
|
deselectRegion(region);
|
|
}
|
|
}
|
|
function selectRegion(region) {
|
|
selectedRegions.set(region, true);
|
|
console.log(selectedRegions);
|
|
}
|
|
function deselectRegion(region) {
|
|
selectedRegions.set(region, false);
|
|
console.log(selectedRegions);
|
|
}
|
|
function setButtonColor(buttonName) {
|
|
document.getElementById(buttonName).style.background = '#00FF00';
|
|
}
|
|
function clearButtonColor(buttonName) {
|
|
document.getElementById(buttonName).style.background = '';
|
|
}
|
|
function selectCheckbox(box) {
|
|
box.setAttribute("class", "checked");
|
|
}
|
|
function deselectCheckbox(box) {
|
|
box.setAttribute("class", "");
|
|
}
|
|
function apply() {
|
|
for (i = 0; i < componentArray.length; i++) {
|
|
var component = componentArray[i];
|
|
for (j = 0; j < regionArray.length; j++) {
|
|
var region = regionArray[j];
|
|
var groupName = component + "Group";
|
|
var group = eval(groupName);
|
|
var checkboxStr = `group.find('*').filter(\":contains('${region}')\").filter("div.clearfix.prettycheckbox.labelright.blue").children().filter("A")[0]`;
|
|
var checkbox = eval(checkboxStr);
|
|
if (checkRegion(region) == true && checkComponent(component) == true) {
|
|
console.log(region);
|
|
console.log(component);
|
|
console.log(groupName);
|
|
console.log(group);
|
|
console.log(checkbox);
|
|
selectCheckbox(checkbox);
|
|
} else {
|
|
deselectCheckbox(checkbox);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
function allComponentsButtonClickAction(zEvent) {
|
|
var enabledCount = 0
|
|
for (i = 0; i < componentArray.length; i++) {
|
|
var component = componentArray[i];
|
|
if (checkComponent(component) == true) {
|
|
enabledCount++;
|
|
}
|
|
}
|
|
if (enabledCount == componentArray.length) {
|
|
for (i = 0; i < componentArray.length; i++) {
|
|
var component = componentArray[i];
|
|
var buttonName = component + "Button";
|
|
deselectComponent(component);
|
|
clearButtonColor(buttonName);
|
|
}
|
|
} else {
|
|
for (i = 0; i < componentArray.length; i++) {
|
|
var component = componentArray[i];
|
|
var buttonName = component + "Button";
|
|
selectComponent(component);
|
|
setButtonColor(buttonName);
|
|
}
|
|
}
|
|
}
|
|
function multilineStr(dummyFunc) {
|
|
var str = dummyFunc.toString();
|
|
str = str.replace(/^[^\/]+\/\*!?/, '') // Strip function () { /*!
|
|
.replace(/\s*\*\/\s*\}\s*$/, '') // Strip */ }
|
|
.replace(/\/\/.+$/gm, '') // Double-slash comments wreck CSS. Strip them.
|
|
;
|
|
return str;
|
|
}
|
|
// frame CSS style
|
|
GM_addStyle(multilineStr(function() {
|
|
/*!
|
|
#myContainer {
|
|
position: fixed;
|
|
bottom: 0;
|
|
right: 0;
|
|
font-size: 14px;
|
|
background: orange;
|
|
border: 3px outset black;
|
|
margin: 3px;
|
|
opacity: 0.7;
|
|
z-index: 222;
|
|
padding: 5px 5px;
|
|
}
|
|
#myButton {
|
|
cursor: pointer;
|
|
}
|
|
#myContainer p {
|
|
color: red;
|
|
background: white;
|
|
}
|
|
hr.solid {
|
|
border-top: 3px solid #bbb;
|
|
}
|
|
*/
|
|
}));
|
|
|