Created
June 24, 2022 00:02
-
-
Save AndyDaSilva52/899d22e6df0c1f58917f7ab22115a099 to your computer and use it in GitHub Desktop.
Changes the Title of the Page for the Design Center Project opened.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Anypoint Design Center - API Design - Title with Project/Branch | |
// @namespace http://tampermonkey.net/ | |
// @version 0.3 | |
// @description Improves the browser window title when using Anypoint Design Center by adding the project name +c branch | |
// @author AndyDaSilva52 | |
// @match https://anypoint.mulesoft.com/designcenter/designer/ | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=bing.com | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
var initialWindowTitle = null; | |
function updateWindowTitle(newTitle) { | |
var initialWindowTitle = window.document.title; | |
if (newTitle) { | |
window.document.title = initialWindowTitle + " - " + newTitle; | |
} | |
} | |
function existsDiv() { | |
if (!document.querySelector("[class^=branches__branchesComponent]")) { | |
console.log('Anypoint Design Title: Still loading!'); | |
return false; | |
} else { | |
console.log('Anypoint Design Title: Loaded!'); | |
return true; | |
} | |
return true; | |
} | |
function getApiName() { | |
var apiName = null; | |
if (document.querySelector("[class^=branches__mainLabel]")) { | |
apiName = document.querySelector("[class^=branches__mainLabel]").textContent; | |
} else if (document.querySelector("[class^=branches__textOverflow]")) { | |
apiName = document.querySelector("[class^=branches__textOverflow]").textContent | |
} | |
return apiName; | |
} | |
function updateAnypointDesignCenterTitle() { | |
if (existsDiv()) { | |
var currentProject = getApiName(); | |
//console.log('currentProject: ' + currentProject); | |
updateWindowTitle(currentProject); | |
clearInterval(run); | |
return true; | |
} else { | |
return false; | |
} | |
} | |
let run = window.setInterval(updateAnypointDesignCenterTitle, 1000); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment