diff --git a/js/lib/genericFunctions.js b/js/lib/genericFunctions.js index a20e00d..e6c4ad9 100644 --- a/js/lib/genericFunctions.js +++ b/js/lib/genericFunctions.js @@ -130,4 +130,7 @@ String.prototype.hashCode = function(){ var uri = (document.location.pathname + document.location.search); return uri.indexOf(s) >= 0; } - \ No newline at end of file + +function debug (m) { + console.log(`Location: ${window.location} Message: ${m}`); +} \ No newline at end of file diff --git a/js/lib/poolImprovements.js b/js/lib/poolImprovements.js index 29c847b..b3d2d68 100644 --- a/js/lib/poolImprovements.js +++ b/js/lib/poolImprovements.js @@ -4,50 +4,87 @@ * **************************************************************************/ -function improvePoolList(){ +async function getURL(url){ - var poolStatuses = {} - var oldMessage = $(parent.top.document).find("div#message div#messagetype div#messagetext").text(); - - // Check when the loading screen for pools has disappears and then show a member statuses. - var statusInterval = setInterval(function(){ - if(!$(parent.top.document).find("div#message").is(":visible")){ - $(parent.top.document).find("div#message div#messagetype div#messagetext").text("Loading member statuses..."); - $(parent.top.document).find("div#message").show(); - clearInterval(statusInterval); - } - } , 100); - - $.ajax({ + return new Promise((resolve, reject) => { + $.ajax({ + + url: url, + type: "GET", + success: response => resolve(response), + error: e => reject(e) + }) + }) + +} + +// Check when the loading screen for pools has disappears and then show a member statuses. +async function showLoadingMessage(message){ + + let messageDiv = $(parent.top.document).find("div#message"); + + return new Promise((resolve, reject) => { + var statusInterval = setInterval(function(){ - url: "https://" + window.location.host + "/tmui/Control/jspmap/tmui/locallb/pool/stats.jsp?SearchString=*&", - type: "GET", - success: function(response) { - - $(response).find("tbody#list_body tr") - .filter(function() { - return this.id.match(/\/.+\//); - }) - .each(function(){ - - var poolName = this.id.replace(/_member_row_[0-9]+$/i, ""); - - if(!(poolName in poolStatuses)){ - poolStatuses[poolName] = {}; - } - - var memberName = $(this).find("td").eq(3).text().trim(); - var statusIcon = $(this).find("td").eq(1).find("img").attr("src"); - var title = $(this).find("td").eq(1).find("img").attr("title"); - - poolStatuses[poolName][memberName] = { "icon": statusIcon, "title": title }; - - }); + if(!(messageDiv.is(":visible"))){ + console.log(messageDiv); + messageDiv.html(` +
+
Loading...
+
${message}
+ `) + messageDiv.show(); + clearInterval(statusInterval); + resolve(); + } + }, 100); + }) + + +} + +async function improvePoolList(){ + + var poolStatuses = {} + + let messageDiv = $(parent.top.document).find("div#message"); + + await showLoadingMessage("Loading member statuses..."); + var response = await getURL("https://" + window.location.host + "/tmui/Control/jspmap/tmui/locallb/pool/stats.jsp?SearchString=*&"); + + messageDiv.fadeOut() + + $(response).find("tbody#list_body tr") + .filter(function() { + return /\/.+\//.test(this.id); + }) + .each(function(){ + + var poolName = this.id.replace(/_member_row_[0-9]+$/, ""); + + if(!(poolName in poolStatuses)){ + poolStatuses[poolName] = {}; + } + + let columns = $(this).find("td"); + let memberName = columns.eq(3).text().trim(); + let statusIconCell = columns.eq(1).find("img") + let statusIconSrc = statusIconCell.attr("src"); + let title = statusIconCell.attr("title"); + let totalConnections = parseInt(columns.eq(11).text()); + + poolStatuses[poolName][memberName] = { "icon": statusIconSrc, "title": title, "totalConnections": totalConnections }; + + }); $("tbody#list_body tr").each(function(){ - - var poolName = $(this).find("td").eq(2).find("a").attr("href").replace(/.+name=/i, ""); - var existingIcons = []; + + let poolRow = $(this); + let poolColumns = poolRow.find("td") + let poolName = poolColumns.eq(2).find("a").attr("href").replace(/.+name=/i, ""); + let poolIconCell = poolColumns.eq(1); + + let existingIcons = []; if(poolName in poolStatuses){ @@ -61,73 +98,75 @@ function improvePoolList(){ if(existingIcons.length > 1){ - var html = "
"; + var poolStatusIconHTML = `
`; for(var i = 0; i < existingIcons.length; i++){ - iconURL = existingIcons[i].replace(/\/.*_/i, "/tmui/tmui/skins/Default/images/status_circle_"); - + let iconURL = existingIcons[i].replace(/\/.*_/i, '/tmui/tmui/skins/Default/images/status_circle_'); + + // Boy is this a hack + // It adds the different icon states in different layers depending on how many different pool states there are + switch (i){ case 0: - html += "
" + poolStatusIconHTML += `
`; break; case 1: - html += "
" + poolStatusIconHTML += `
`; break; case 2: - html += "
" + poolStatusIconHTML += `
`; break; case 3: - html += "
" + poolStatusIconHTML += '
'; break; } } - html += "
"; - - $(this).find("td").eq(1).html(html); + poolStatusIconHTML += '
'; + + poolIconCell.html(poolStatusIconHTML); } else { - var html = "
" - $(this).find("td").eq(1).html(html); + var poolStatusIconHTML = `
`; + poolIconCell.html(poolStatusIconHTML); } - $(this).find("td").eq(1).find("div").on("mouseover", function(){ + poolIconCell.find('div').on('mouseover', function(){ poolName = $(this).attr("data-poolname"); if(poolName in poolStatuses){ - var table = "
"; + var table = '
MemberStatus
'; memberStatuses = poolStatuses[poolName]; var i = 0; for(member in memberStatuses){ - table += ""; + table += ``; i++; } - table += "
MemberStatus
" + member + "" + memberStatuses[member].title + "
${member}${memberStatuses[member].title}
"; + table += ''; - $(this).balloon({ position: "right", css: { whitespace: "nowrap", boxShadow: null, opacity: "1", padding: "0px", border: "0px", background: "rgba(0, 0, 255,1)" }, minLifetime: 0, tipSize:0, showDuration: 0, hideDuration: 0, contents: table }); + $(this).balloon({ position: 'right', css: { whitespace: 'nowrap', boxShadow: null, opacity: '1', padding: '0px', border: '0px', background: 'rgba(0, 0, 255,1)' }, minLifetime: 0, tipSize:0, showDuration: 0, hideDuration: 0, contents: table }); } }); - //For some reason I need to trigger this at least one ahead of time in order to get the popup to show on the first attempt - $(this).find("td").eq(1).find("div").trigger("mouseover"); - $(this).find("td").eq(1).find("div").trigger("mouseout"); + // For some reason I need to + // * Trigger this at least one ahead of time in order to get the popup to show on the first attempt + // * Not cache the jQuery selector or it will show the state of the last pool + $(this).find('td').eq(1).find('div').trigger('mouseover'); + $(this).find('td').eq(1).find('div').trigger('mouseout'); } }) - $(parent.top.document).find("div#message").fadeOut(function(){ - $(parent.top.document).find("div#message div#messagetype div#messagetext").text(oldMessage); - }); + } - }) - } + function improvePoolProperties(){ diff --git a/js/main.js b/js/main.js index 0757f40..866dcc1 100644 --- a/js/main.js +++ b/js/main.js @@ -342,13 +342,12 @@ var enhancementFunctions = { var majorVersion = null; - -console.log("Waiting for version info"); +debug("Waiting for version info"); waitForStorageKey('majorVersion').then(async () => { let version = await getStorage('majorVersion') - console.log("Got version info."); + debug("Got version info."); majorVersion = version.majorVersion; initiateBaloon(); diff --git a/manifest.json b/manifest.json index 8df5a68..b24c5cc 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,22 @@ "short_name": "ADCTweaks", "content_scripts": [ { - "matches": ["https://*/tmui/Control/*"], + "matches": [ + "https://*/tmui/Control/*", + "https://*/tmui/Control/jspmap/tmui/locallb/pool/list.jsp*", + "https://*/tmui/Control/jspmap/tmui/locallb/rule/properties.jsp*", + "https://*/tmui/Control/form?__handler=/tmui/locallb/virtual_server/resources&__source=Manage*", + "https://*/tmui/Control/jspmap/tmui/locallb/pool/properties.jsp?name*", + "https://*/tmui/Control/jspmap/tmui/locallb/pool/create.jsp*", + "https://*/tmui/Control/jspmap/tmui/locallb/pool/member/properties.jsp*", + "https://*/tmui/Control/jspmap/tmui/locallb/virtual_server/resources.jsp*", + "https://*/tmui/Control/jspmap/tmui/locallb/virtual_server/properties.jsp*", + "https://*/tmui/Control/jspmap/tmui/locallb/datagroup/properties.jsp*", + "https://*/tmui/Control/jspmap/tmui/locallb/datagroup/create.jsp*", + "https://*/tmui/Control/jspmap/tmui/locallb/profile/clientssl/create.jsp*", + "https://*/tmui/Control/jspmap/tmui/locallb/ssl_certificate/create.jsp*", + "https://*/tmui/Control/jspmap/tmui/overview/welcome/introduction.jsp*" + ], "css": ["css/poolimprovements.css"], "js": [ "settings/settings.js",