Advertisement
Guest User

Enhance Add Pages Test

a guest
Feb 24th, 2025
49
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Define the selectors for the menu wrapper, menu box and original content box
  2. const menuSelector = '#root > [data-qa="box"] > [data-qa="box"]:first-child';  
  3. const originalBoxSelector = '#root > [data-qa="box"] > [data-qa="box"]:nth-child(2)';  
  4. const dashboardSpine = document.getElementById('dashboard-spine');
  5.  
  6. function injectCSS(customCSS) {
  7.     const style = document.createElement('style');
  8.     style.textContent = customCSS;
  9.     document.head.appendChild(style);
  10. }
  11.  
  12. function cloneAndModifyNavLink(newHref, newTitle, newSvg, callback) {
  13.  
  14.     if (!dashboardSpine) return;
  15.  
  16.     const navLinks = dashboardSpine.querySelectorAll('a[data-qa="navLink"]');
  17.     if (navLinks.length === 0) return;
  18.  
  19.     const lastNavLink = navLinks[navLinks.length - 1];
  20.     const newNavLink = lastNavLink.cloneNode(true);
  21.  
  22.     newNavLink.href = newHref;
  23.     newNavLink.title = newTitle;
  24.     newNavLink.setAttribute('aria-label', newTitle);
  25.     newNavLink.classList.add('extLinks');  // Add the extLinks class
  26.  
  27.     const textElement = newNavLink.querySelector('p[data-qa="text"]');
  28.     if (textElement) textElement.textContent = newTitle;
  29.  
  30.     const svgElement = newNavLink.querySelector('svg');
  31.     if (svgElement && newSvg) {
  32.         svgElement.outerHTML = newSvg;
  33.     }
  34.  
  35.     const uniqueId = newHref.replace('#', '') + '-content';
  36.  
  37.     newNavLink.addEventListener('click', function(e) {
  38.         e.preventDefault();  
  39.  
  40.        
  41.         // Remove the 'selected' class from any previously selected link
  42.         const previouslySelectedLink = dashboardSpine.querySelector('a.selected');
  43.         if (previouslySelectedLink) {
  44.             previouslySelectedLink.classList.remove('selected');
  45.         }
  46.         newNavLink.classList.add('selected');
  47.  
  48.        
  49.         // Hide the original box
  50.         const originalBox = document.querySelector(originalBoxSelector);
  51.         if (originalBox) {
  52.             originalBox.style.display = 'none';  // Hide the original box
  53.         }
  54.  
  55.         // Hide all other extLink content divs
  56.         const otherDivs = document.querySelectorAll('.ext-page-wrapper');
  57.         otherDivs.forEach(div => {
  58.             div.style.display = 'none';  // Hide all other content divs
  59.         });
  60.  
  61.         // Show the corresponding content div for the clicked extLink
  62.         const contentDiv = document.getElementById(uniqueId);
  63.         if (contentDiv) {
  64.             contentDiv.style.display = 'block';  // Show the corresponding content div
  65.         }
  66.  
  67.         // Show the menu box
  68.         const menuBox = document.querySelector(menuSelector);
  69.         if (menuBox) {
  70.             menuBox.style.display = 'block';  // Show the menu
  71.         }
  72.     });
  73.  
  74.    
  75.     if (callback && typeof callback === 'function') {
  76.         const content = callback();  
  77.        
  78.         const box = document.querySelector('#root > [data-qa="box"]');
  79.         if (box) {
  80.             const newDiv = document.createElement('div');
  81.             newDiv.id = uniqueId;  
  82.             newDiv.style.display = 'none';
  83.             newDiv.classList.add('ext-page-wrapper');
  84.             newDiv.innerHTML = content;  
  85.             box.appendChild(newDiv);
  86.         }
  87.     }
  88.  
  89.     dashboardSpine.appendChild(newNavLink);
  90. }
  91.  
  92. // Restore original box when an original link is clicked
  93. const originalLinks = document.querySelectorAll('a[data-qa="navLink"]:not(.extLinks)');
  94. originalLinks.forEach(link => {
  95.     link.addEventListener('click', function() {
  96.         const previouslySelectedLink = dashboardSpine.querySelector('a.extLinks.selected');
  97.         if (previouslySelectedLink) {
  98.             previouslySelectedLink.classList.remove('selected');
  99.         }
  100.        
  101.      
  102.         const originalBox = document.querySelector(originalBoxSelector);
  103.         if (originalBox) {
  104.             originalBox.style.display = 'flex';  // Show the original box
  105.         }
  106.  
  107.      
  108.         const otherDivs = document.querySelectorAll('.ext-page-wrapper');
  109.         otherDivs.forEach(div => {
  110.             div.style.display = 'none';  // Hide all extLink content divs
  111.         });
  112.     });
  113. });
  114.  
  115. //fix spacing between default and new menu items
  116. injectCSS(`#dashboard-spine > div:last-of-type {
  117. height: 1px;
  118.     background: white;
  119.     margin: 0;
  120. }`)
  121.  
  122. //Add CSS for spacing of pages etc
  123. injectCSS(`
  124. .ext-page-wrapper iframe {
  125. width:100%;
  126. height:100vh;
  127. }
  128. .ext-page-wrapper{
  129. width:100%;
  130. background:gray;
  131. display:flex;
  132. }
  133.  
  134. `)
  135.  
  136. cloneAndModifyNavLink('#hello', 'Hello World', `<svg fill="#000000" height="800px" width="800px" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 485 485" xml:space="preserve"> <g> <path d="M382.5,69.429c-7.441,0-14.5,1.646-20.852,4.573c-4.309-23.218-24.7-40.859-49.148-40.859 c-7.68,0-14.958,1.744-21.467,4.852C285.641,16.205,265.932,0,242.5,0c-23.432,0-43.141,16.206-48.533,37.995 c-6.508-3.107-13.787-4.852-21.467-4.852c-27.57,0-50,22.43-50,50v122.222c-6.129-2.686-12.891-4.187-20-4.187 c-27.57,0-50,22.43-50,50V354c0,72.233,58.766,131,131,131h118c72.233,0,131-58.767,131-131V119.429 C432.5,91.858,410.07,69.429,382.5,69.429z M402.5,354c0,55.691-45.309,101-101,101h-118c-55.691,0-101-45.309-101-101V251.178 c0-11.028,8.972-20,20-20s20,8.972,20,20v80h30V83.143c0-11.028,8.972-20,20-20s20,8.972,20,20v158.035h30V50 c0-11.028,8.972-20,20-20c11.028,0,20,8.972,20,20v191.178h30V83.143c0-11.028,8.972-20,20-20s20,8.972,20,20v158.035h30v-121.75 c0-11.028,8.972-20,20-20s20,8.972,20,20V354z"/> </g> </svg>`, () => {
  137.     //PAGE HTML GOES HERE
  138.     return `<div><h1 style="color:red;">HELLO WORLD</h1></div>`;
  139. });
  140.  
  141. cloneAndModifyNavLink('#google', 'Google', `
  142. <svg xmlns="http://www.w3.org/2000/svg"  viewBox="0 0 50 50" width="50px" height="50px"><path d="M 26 2 C 13.308594 2 3 12.308594 3 25 C 3 37.691406 13.308594 48 26 48 C 35.917969 48 41.972656 43.4375 45.125 37.78125 C 48.277344 32.125 48.675781 25.480469 47.71875 20.9375 L 47.53125 20.15625 L 46.75 20.15625 L 26 20.125 L 25 20.125 L 25 30.53125 L 36.4375 30.53125 C 34.710938 34.53125 31.195313 37.28125 26 37.28125 C 19.210938 37.28125 13.71875 31.789063 13.71875 25 C 13.71875 18.210938 19.210938 12.71875 26 12.71875 C 29.050781 12.71875 31.820313 13.847656 33.96875 15.6875 L 34.6875 16.28125 L 41.53125 9.4375 L 42.25 8.6875 L 41.5 8 C 37.414063 4.277344 31.960938 2 26 2 Z M 26 4 C 31.074219 4 35.652344 5.855469 39.28125 8.84375 L 34.46875 13.65625 C 32.089844 11.878906 29.199219 10.71875 26 10.71875 C 18.128906 10.71875 11.71875 17.128906 11.71875 25 C 11.71875 32.871094 18.128906 39.28125 26 39.28125 C 32.550781 39.28125 37.261719 35.265625 38.9375 29.8125 L 39.34375 28.53125 L 27 28.53125 L 27 22.125 L 45.84375 22.15625 C 46.507813 26.191406 46.066406 31.984375 43.375 36.8125 C 40.515625 41.9375 35.320313 46 26 46 C 14.386719 46 5 36.609375 5 25 C 5 13.390625 14.386719 4 26 4 Z"/></svg>`, () => {
  143.     return `<div><iframe src="https://www.google.com/search?igu=1"></iframe></div>`;
  144. });
  145.  
Advertisement
Comments
  • Comment was deleted
Add Comment
Please, Sign In to add comment
Advertisement