288 lines
10 KiB
JavaScript
288 lines
10 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==
|
|
|
|
if (window.location.href.indexOf("5d49ec10226b9e13cb6a422e") > -1) {
|
|
console.log("azure status page");
|
|
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 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 dataplanesHTML = '<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>'
|
|
var locationHTML = dataplanesHTML
|
|
}
|
|
|
|
if (window.location.href.indexOf("5cf02dde58a00904bda41926") > -1) {
|
|
console.log("aws status page");
|
|
}
|
|
|
|
if (window.location.href.indexOf("60087ab5608daf0535dc8e23") > -1) {
|
|
console.log("gcp status page");
|
|
}
|
|
// 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')");
|
|
|
|
|
|
var selectedComponents = new Map();
|
|
var selectedRegions = new Map();
|
|
for (i = 0; i < componentArray.length; i++) {
|
|
selectedComponents.set(componentArray[i], false);
|
|
}
|
|
|
|
for (i = 0; i < regionArray.length; i++) {
|
|
selectedRegions.set(regionArray[i], false)
|
|
}
|
|
|
|
function apply() {
|
|
for (i = 0; i < componentArray.length; i++) {
|
|
var component = componentArray[i];
|
|
console.log(component)
|
|
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) {
|
|
selectCheckbox(checkbox);
|
|
} else {
|
|
deselectCheckbox(checkbox);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// draw frame
|
|
var zNode = document.createElement('div');
|
|
zNode.innerHTML = profilesHTML + '</br>' + locationHTML + '</br></br><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>'+
|
|
'<button id="applyButton" type="button">Apply Selection</button>';
|
|
zNode.setAttribute('id', 'myContainer');
|
|
document.body.appendChild(zNode);
|
|
|
|
// component buttons
|
|
document.getElementById("apiButton").addEventListener(
|
|
"click", apiButtonClickAction, false
|
|
);
|
|
|
|
function apiButtonClickAction(zEvent) {
|
|
toggleComponent("api");
|
|
toggleButtonColor("apiButton");
|
|
}
|
|
document.getElementById("authButton").addEventListener(
|
|
"click", authButtonClickAction, false
|
|
);
|
|
|
|
function authButtonClickAction(zEvent) {
|
|
toggleComponent("auth");
|
|
toggleButtonColor("authButton");
|
|
}
|
|
document.getElementById("computeButton").addEventListener(
|
|
"click", computeButtonClickAction, false
|
|
);
|
|
function computeButtonClickAction(zEvent) {
|
|
toggleComponent("compute");
|
|
toggleButtonColor("computeButton");
|
|
}
|
|
|
|
document.getElementById("jobsButton").addEventListener(
|
|
"click", jobsButtonClickAction, false
|
|
);
|
|
|
|
function jobsButtonClickAction(zEvent) {
|
|
toggleComponent("jobs");
|
|
toggleButtonColor("jobsButton");
|
|
}
|
|
document.getElementById("odbcButton").addEventListener(
|
|
"click", odbcButtonClickAction, false
|
|
);
|
|
|
|
function odbcButtonClickAction(zEvent) {
|
|
toggleComponent("odbc");
|
|
toggleButtonColor("odbcButton");
|
|
}
|
|
document.getElementById("webappButton").addEventListener(
|
|
"click", webappButtonClickAction, false
|
|
);
|
|
|
|
function webappButtonClickAction(zEvent) {
|
|
toggleComponent("webapp");
|
|
toggleButtonColor("webappButton");
|
|
}
|
|
document.getElementById("sqlButton").addEventListener(
|
|
"click", sqlButtonClickAction, false
|
|
);
|
|
|
|
function sqlButtonClickAction(zEvent) {
|
|
toggleComponent("sql");
|
|
toggleButtonColor("sqlButton");
|
|
}
|
|
document.getElementById("allComponentsButton").addEventListener(
|
|
"click", allComponentsButtonClickAction, false
|
|
);
|
|
|
|
function allComponentsButtonClickAction(zEvent) {
|
|
for (i = 0; i < componentArray.length; i++) {
|
|
var component = componentArray[i];
|
|
var buttonName = component + "Button";
|
|
selectComponent(component);
|
|
setButtonColor(buttonName);
|
|
}
|
|
}
|
|
|
|
// regional buttons
|
|
function canadaCentralButtonClickAction(zEvent) {
|
|
toggleRegion("canadacentral");
|
|
toggleButtonColor("canadaCentralButton")
|
|
|
|
}
|
|
document.getElementById("canadaCentralButton").addEventListener(
|
|
"click", canadaCentralButtonClickAction, false
|
|
);
|
|
function canadaEastButtonClickAction(zEvent) {
|
|
toggleRegion("canadaeast");
|
|
toggleButtonColor("canadaEastButton")
|
|
}
|
|
document.getElementById("canadaEastButton").addEventListener(
|
|
"click", canadaEastButtonClickAction, false
|
|
);
|
|
// aux buttons
|
|
|
|
function applyButtonClickAction(zEvent) {
|
|
apply();
|
|
}
|
|
document.getElementById("applyButton").addEventListener(
|
|
"click", applyButtonClickAction, false
|
|
)
|
|
// aux functions
|
|
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 toggleCheckbox(box) {
|
|
if (box.getAttribute("class") == "checked") {
|
|
box.setAttribute("class", "");
|
|
} else {
|
|
box.setAttribute("class", "checked");
|
|
|
|
}
|
|
}
|
|
|
|
|
|
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;
|
|
}
|
|
*/
|
|
}));
|
|
|