Hi there! I was wondering, is it possible to captu...
# general
f
Hi there! I was wondering, is it possible to capture the navigation bar colour? so I can then use that same colour on different suitelets
d
Programmatically or manually? Programmatically probably via some jQuery. Manually you can inspect your netsuite page (dev tools), and one of the `link`s under
head
will contain the
/core/styles/pagestyles.nl
stylesheet. The color theme colors will be in the href, for instance here's the values for "Basic : Orange"
🙌 1
I think for nav bar colour, it's
bgoff
(in this case #E5772A)
m
Copy code
/**
   * Attempt to figure out user's selected theme colour
   *
   * @returns {string} NetSuite theme colour as hex string
   */
  function getNetSuiteThemeColour() {
    const defaultColour = "#607799";
    const $nsNavigation = document.getElementById("ns_navigation");

    if ($nsNavigation) {
      return window.getComputedStyle($nsNavigation)["background-color"];
    }

    return defaultColour;
  }
🙌 1
slack bookmark 1
d
That's some handy code, saving that
f
I've made a few modifications to the code so it returns the colour value as hex instead or rgb. `const rgbToHex = ([r, g, b]) => `#${Number(r).toString(16)}${Number(g).toString(16)}${Number(b).toString(16)}``
const getNetSuiteThemeColour = () => {
const defaultColour = "#607799";
const $nsNavigation = document.getElementById("ns_navigation");
if ($nsNavigation) {
const rgb = window.getComputedStyle($nsNavigation)["background-color"].toString(16);
var rgbArray = rgb.replace('rgb(', '').replace(')', '');
rgbArray = rgbArray.split(', ');
return rgbToHex(rgbArray);
}
return defaultColour;
}
1
d
could also use
Copy code
const rgb = window.getComputedStyle($nsNavigation)["background-color"];
return '#'+rgb.match(/\d+/g).map(x=>(+x).toString(16).padStart(2,0)).join('')
🏌️ 2
2
just note that IE returns background-color in hex already..... 🙄 because of course it does