GitHub Custom Global Navigation

Customize GitHub's new global navigation

当前为 2024-02-15 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name GitHub Custom Global Navigation
  3. // @namespace https://github.com/blakegearin/github-custom-global-navigation
  4. // @version 1.4.2
  5. // @description Customize GitHub's new global navigation
  6. // @author Blake Gearin
  7. // @match *://github.com/*
  8. // @require https://openuserjs.org/src/libs/sizzle/GM_config.js
  9. // @grant GM.getValue
  10. // @grant GM.setValue
  11. // @license MIT
  12. // @icon https://raw.githubusercontent.com/blakegearin/github-custom-global-navigation/main/img/white_logo.svg
  13. // @supportURL https://github.com/blakegearin/github-custom-global-navigation/issues
  14. // ==/UserScript==
  15.  
  16. /*global GM_config*/
  17.  
  18. (function () {
  19. 'use strict';
  20.  
  21. const SILENT = 0;
  22. const QUIET = 1;
  23. const INFO = 2;
  24. const DEBUG = 3;
  25. const VERBOSE = 4;
  26. const TRACE = 5;
  27.  
  28. let CURRENT_LOG_LEVEL = QUIET;
  29.  
  30. const USERSCRIPT_NAME = 'GitHub Custom Global Navigation';
  31.  
  32. function log(level, message, variable = -1) {
  33. if (CURRENT_LOG_LEVEL < level) return;
  34.  
  35. console.log(`${USERSCRIPT_NAME}: ${message}`);
  36. if (variable !== -1) console.log(variable);
  37. }
  38.  
  39. function logError(message, variable = null) {
  40. console.error(`${USERSCRIPT_NAME}: ${message}`);
  41. if (variable) console.log(variable);
  42. }
  43.  
  44. log(TRACE, 'Starting');
  45.  
  46. function updateHeader() {
  47. log(DEBUG, 'updateHeader()');
  48.  
  49. if (CONFIG.backgroundColor !== '') {
  50. HEADER_STYLE.textContent += `
  51. ${SELECTORS.header.self}
  52. {
  53. background-color: ${CONFIG.backgroundColor} !important;
  54. }
  55. `;
  56. }
  57.  
  58. updateHamburgerButton();
  59. updateLogo();
  60.  
  61. if (CONFIG.repositoryHeader.import) importRepositoryHeader();
  62.  
  63. updatePageTitle();
  64. updateSearch();
  65.  
  66. if (CONFIG.divider.remove) removeDivider();
  67.  
  68. if (CONFIG.marketplace.add) createMarketplaceLink();
  69. if (CONFIG.explore.add) createExploreLink();
  70.  
  71. updateLink('issues');
  72. updateLink('pullRequests');
  73.  
  74. if (CONFIG.marketplace.add) updateLink('marketplace');
  75. if (CONFIG.explore.add) updateLink('explore');
  76.  
  77. if (CONFIG.flipIssuesPullRequests) flipIssuesPullRequests();
  78.  
  79. updateCreateNewButton();
  80. updateInboxLink();
  81.  
  82. if (CONFIG.flipCreateInbox) flipCreateInbox();
  83.  
  84. updateAvatar();
  85.  
  86. updateGlobalBar();
  87. updateLocalBar();
  88.  
  89. updateSidebars();
  90.  
  91. modifyThenObserve(() => {
  92. document.body.appendChild(HEADER_STYLE);
  93. });
  94. }
  95.  
  96. function updateHamburgerButton() {
  97. log(DEBUG, 'updateHamburgerButton()');
  98.  
  99. const configKey = 'hamburgerButton';
  100. const elementConfig = CONFIG.hamburgerButton;
  101. log(DEBUG, 'elementConfig', elementConfig);
  102.  
  103. const hamburgerButton = HEADER.querySelector(SELECTORS[configKey]);
  104.  
  105. if (!hamburgerButton) {
  106. logError(`Selector '${SELECTORS[configKey]}' not found`);
  107. return;
  108. }
  109.  
  110. if (elementConfig.remove) {
  111. HEADER_STYLE.textContent += cssHideElement(SELECTORS[configKey]);
  112.  
  113. return;
  114. }
  115. }
  116.  
  117. function updateLogo() {
  118. log(DEBUG, 'updateLogo()');
  119.  
  120. const configKey = 'logo';
  121.  
  122. const elementConfig = CONFIG[configKey];
  123. const elementSelector = SELECTORS[configKey];
  124.  
  125. if (elementConfig.remove) {
  126. HEADER_STYLE.textContent += cssHideElement(elementSelector.topDiv);
  127. }
  128.  
  129. const logo = HEADER.querySelector(elementSelector.svg);
  130.  
  131. if (elementConfig.color !== '') {
  132. HEADER_STYLE.textContent += `
  133. ${elementSelector.svg} path
  134. {
  135. fill: ${elementConfig.color} !important;
  136. }
  137. `;
  138. }
  139.  
  140. if (elementConfig.customSvg !== '') {
  141. const oldSvg = logo;
  142.  
  143. let newSvg;
  144.  
  145. if (isValidURL(elementConfig.customSvg)) {
  146. newSvg = document.createElement('img');
  147. newSvg.src = elementConfig.customSvg;
  148. } else {
  149. const parser = new DOMParser();
  150. const svgDoc = parser.parseFromString(elementConfig.customSvg, 'image/svg+xml');
  151. newSvg = svgDoc.documentElement;
  152. }
  153.  
  154. oldSvg.parentNode.replaceChild(newSvg, oldSvg);
  155. }
  156. }
  157.  
  158. function removePageTitle() {
  159. HEADER_STYLE.textContent += cssHideElement(createId(SELECTORS.pageTitle.id));
  160. }
  161.  
  162. function updatePageTitle() {
  163. log(DEBUG, 'updatePageTitle()');
  164.  
  165. const elementConfig = CONFIG.pageTitle;
  166. log(DEBUG, 'elementConfig', elementConfig);
  167.  
  168. const pageTitle = HEADER.querySelector(SELECTORS.pageTitle.topDiv);
  169.  
  170. if (!pageTitle) {
  171. logError(`Selector '${SELECTORS.pageTitle.topDiv}' not found`);
  172. return;
  173. }
  174.  
  175. pageTitle.setAttribute('id', SELECTORS.pageTitle.id);
  176.  
  177. if (elementConfig.remove) {
  178. removePageTitle();
  179. return;
  180. }
  181.  
  182. if (elementConfig.color !== '') {
  183. HEADER_STYLE.textContent += `
  184. ${SELECTORS.pageTitle.links}
  185. {
  186. color: ${elementConfig.color} !important;
  187. }
  188. `;
  189. }
  190.  
  191. if (elementConfig.hover.color !== '') {
  192. HEADER_STYLE.textContent += `
  193. ${SELECTORS.pageTitle.links}:hover
  194. {
  195. color: ${elementConfig.hover.color} !important;
  196. }
  197. `;
  198. }
  199.  
  200. if (elementConfig.hover.backgroundColor !== '') {
  201. HEADER_STYLE.textContent += `
  202. ${SELECTORS.pageTitle.links}:hover
  203. {
  204. background-color: ${elementConfig.hover.backgroundColor} !important;
  205. }
  206. `;
  207. }
  208. }
  209.  
  210. function updateSearch() {
  211. log(DEBUG, 'updateSearch()');
  212.  
  213. const configKey = 'search';
  214.  
  215. const elementConfig = CONFIG[configKey];
  216. const elementSelector = SELECTORS[configKey];
  217.  
  218. let topDivSelector = elementSelector.id;
  219. const topDiv = HEADER.querySelector(createId(elementSelector.id)) ||
  220. HEADER.querySelector(elementSelector.topDiv);
  221.  
  222. if (!topDiv) {
  223. logError(`Selectors '${createId(elementSelector.id)}' and '${elementSelector.topDiv}' not found`);
  224. return;
  225. }
  226.  
  227. topDiv.setAttribute('id', elementSelector.id);
  228.  
  229. if (elementConfig.remove) {
  230. HEADER_STYLE.textContent += cssHideElement(createId(elementSelector.id));
  231. return;
  232. }
  233.  
  234. if (elementConfig.alignLeft) {
  235. const response = cloneAndLeftAlignElement(createId(topDivSelector), topDivSelector);
  236.  
  237. if (response.length === 0) return;
  238.  
  239. // Also need to hide button due to it showing up on larger screen widths
  240. HEADER_STYLE.textContent += cssHideElement(`${createId(topDivSelector)} ${elementSelector.input}`);
  241.  
  242. HEADER_STYLE.textContent += `
  243. ${createId(topDivSelector)}
  244. {
  245. flex-grow: 1 !important;
  246. }
  247. `;
  248.  
  249. const [cloneId, _cloneElement] = response;
  250.  
  251. topDivSelector = createId(cloneId);
  252.  
  253. HEADER_STYLE.textContent += `
  254. ${topDivSelector}
  255. {
  256. flex: 0 1 auto !important;
  257. justify-content: flex-start !important;
  258. }
  259. `;
  260. }
  261.  
  262. if (elementConfig.width === 'max') {
  263. log(DEBUG, 'elementSelector', elementSelector);
  264.  
  265. HEADER_STYLE.textContent += `
  266. @media (min-width: 1012px) {
  267. ${elementSelector.input}
  268. {
  269. width: auto !important
  270. }
  271.  
  272. ${SELECTORS.header.leftAligned}
  273. {
  274. flex: 0 1 auto !important;
  275. }
  276.  
  277. ${SELECTORS.header.rightAligned}
  278. {
  279. flex: 1 1 auto !important;
  280. justify-content: space-between !important;
  281. }
  282.  
  283. ${createId(topDivSelector)}
  284. {
  285. display: block !important;
  286. }
  287.  
  288. ${elementSelector.topDiv}-whenRegular
  289. {
  290. max-width: none !important;
  291. }
  292. }
  293. `;
  294. } else if (elementConfig.width !== '') {
  295. HEADER_STYLE.textContent += `
  296. @media (min-width: 1012px)
  297. {
  298. ${topDivSelector},
  299. ${elementSelector.input}
  300. {
  301. width: ${elementConfig.width} !important
  302. }
  303. }
  304.  
  305. @media (min-width: 768px)
  306. {
  307. ${topDivSelector},
  308. ${elementSelector.input}
  309. {
  310. --feed-sidebar: 320px;
  311. }
  312. }
  313.  
  314. @media (min-width: 1400px)
  315. {
  316. ${topDivSelector},
  317. ${elementSelector.input}
  318. {
  319. --feed-sidebar: 336px;
  320. }
  321. }
  322. `;
  323. }
  324.  
  325. if (elementConfig.margin.left !== '') {
  326. HEADER_STYLE.textContent += `
  327. @media (min-width: 1012px)
  328. {
  329. ${elementSelector.input}
  330. {
  331. margin-left: ${elementConfig.margin.left} !important
  332. }
  333. }
  334. `;
  335. }
  336.  
  337. if (elementConfig.margin.right!== '') {
  338. HEADER_STYLE.textContent += `
  339. @media (min-width: 1012px)
  340. {
  341. ${elementSelector.input}
  342. {
  343. margin-right: ${elementConfig.margin.right} !important
  344. }
  345. }
  346. `;
  347. }
  348.  
  349. if (elementConfig.rightButton !== 'command palette') {
  350. const commandPaletteButton = HEADER.querySelector(elementSelector.commandPalette);
  351. if (!commandPaletteButton) {
  352. logError(`Selector '${elementSelector.commandPalette}' not found`);
  353. } else {
  354. HEADER_STYLE.textContent += cssHideElement(elementSelector.commandPalette);
  355. }
  356. }
  357.  
  358. const placeholderSpan = HEADER.querySelector(elementSelector.placeholderSpan);
  359.  
  360. if (!placeholderSpan) {
  361. logError(`Selector '${elementSelector.placeholderSpan}' not found`);
  362. return;
  363. }
  364.  
  365. if (elementConfig.placeholder.text !== '') {
  366. // Without this, the placeholder text is overwritten by the shadow DOM
  367. // You may see the following error in the console:
  368. // qbsearch-input-element.ts:421 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'innerHTML')
  369. placeholderSpan.setAttribute('data-target', 'avoidShadowDOM');
  370. placeholderSpan.innerText = elementConfig.placeholder.text;
  371. }
  372.  
  373. if (elementConfig.placeholder.color !== '') {
  374. HEADER_STYLE.textContent += `
  375. ${elementSelector.placeholderSpan}
  376. {
  377. color: ${elementConfig.placeholder.color} !important;
  378. }
  379. `;
  380. }
  381.  
  382. const searchButton = HEADER.querySelector(elementSelector.button);
  383.  
  384. if (!searchButton) {
  385. logError(`Selector '${elementSelector.button}' not found`);
  386. return;
  387. }
  388.  
  389. if (elementConfig.backgroundColor !== '') {
  390. HEADER_STYLE.textContent += `
  391. ${elementSelector.button}
  392. {
  393. background-color: ${elementConfig.backgroundColor} !important;
  394. }
  395. `;
  396. }
  397.  
  398. if (elementConfig.borderColor !== '') {
  399. // There are different buttons at different widths
  400. HEADER_STYLE.textContent += `
  401. ${elementSelector.input} button
  402. {
  403. border-color: ${elementConfig.borderColor} !important;
  404. }
  405. `;
  406. }
  407.  
  408. if (elementConfig.boxShadow !== '') {
  409. HEADER_STYLE.textContent += `
  410. ${elementSelector.button}
  411. {
  412. box-shadow: ${elementConfig.boxShadow} !important;
  413. }
  414. `;
  415. }
  416.  
  417. if (elementConfig.magnifyingGlassIcon.remove) {
  418. HEADER_STYLE.textContent += cssHideElement(elementSelector.magnifyingGlassIcon);
  419. }
  420.  
  421. if (elementConfig.modal.width !== '') {
  422. HEADER_STYLE.textContent += `
  423. ${elementSelector.modal}
  424. {
  425. width: ${elementConfig.modal.width} !important;
  426. }
  427. `;
  428. }
  429.  
  430. if (elementConfig.rightButton === 'slash key') {
  431. HEADER_STYLE.textContent += `
  432. ${elementSelector.placeholderSpan}
  433. {
  434. width: 100% !important;
  435. }
  436. `;
  437.  
  438. const parser = new DOMParser();
  439. const svgDoc = parser.parseFromString(
  440. '<svg xmlns="http://www.w3.org/2000/svg" width="22" height="20" aria-hidden="true"><path fill="none" stroke="#979A9C" opacity=".4" d="M3.5.5h12c1.7 0 3 1.3 3 3v13c0 1.7-1.3 3-3 3h-12c-1.7 0-3-1.3-3-3v-13c0-1.7 1.3-3 3-3z"></path><path fill="#979A9C" d="M11.8 6L8 15.1h-.9L10.8 6h1z"></path></svg>',
  441. 'image/svg+xml',
  442. );
  443. const slashImg = svgDoc.documentElement;
  444. slashImg.alt = 'slash key to search';
  445.  
  446. const placeholderDiv = HEADER.querySelector(elementSelector.placeholderDiv);
  447.  
  448. if (!placeholderDiv) {
  449. logError(`Selector '${elementSelector.placeholderDiv}' not found`);
  450. return;
  451. }
  452.  
  453. HEADER_STYLE.textContent += `
  454. ${elementSelector.placeholderDiv}
  455. {
  456. display: flex !important;
  457. }
  458.  
  459. ${elementSelector.button}
  460. {
  461. padding-inline-start: 8px !important;
  462. }
  463. `;
  464.  
  465. placeholderDiv.appendChild(slashImg);
  466. }
  467. }
  468.  
  469. function removeDivider() {
  470. log(DEBUG, 'removeDivider()');
  471.  
  472. HEADER_STYLE.textContent += `
  473. ${SELECTORS.header.actionsDiv}::before
  474. {
  475. content: none !important;
  476. }
  477. `;
  478. }
  479.  
  480. function updateLink(configKey) {
  481. log(DEBUG, 'updateLink()');
  482.  
  483. const elementConfig = CONFIG[configKey];
  484. const elementSelector = SELECTORS[configKey];
  485.  
  486. let link;
  487. const tooltipElement = SELECTORS.toolTips[configKey];
  488.  
  489. if (tooltipElement) {
  490. link = tooltipElement.previousElementSibling;
  491. } else {
  492. log(DEBUG, `Tooltip for '${configKey}' not found`);
  493.  
  494. const linkId = createId(SELECTORS[configKey].id);
  495. link = HEADER.querySelector(linkId);
  496.  
  497. if (!link) {
  498. logError(`Selector '${linkId}' not found`);
  499.  
  500. return;
  501. }
  502. }
  503.  
  504. let linkSelector = elementSelector.id;
  505. link.setAttribute('id', linkSelector);
  506.  
  507.  
  508. if (elementConfig.remove) {
  509. HEADER_STYLE.textContent += cssHideElement(createId(configKey));
  510.  
  511. return;
  512. }
  513.  
  514. if (!elementConfig.tooltip && SELECTORS.toolTips[configKey]?.id) {
  515. HEADER_STYLE.textContent += cssHideElement(createId(SELECTORS.toolTips[configKey].id));
  516. }
  517.  
  518. if (elementConfig.alignLeft) {
  519. const response = cloneAndLeftAlignElement(createId(elementSelector.id), elementSelector.id);
  520.  
  521. if (response.length === 0) return;
  522.  
  523. const [cloneId, cloneElement] = response;
  524.  
  525. elementSelector[CONFIG_NAME] = {
  526. leftAlignedId: cloneId,
  527. };
  528. link = cloneElement;
  529.  
  530. linkSelector = createId(cloneId);
  531. }
  532.  
  533. const padding = '7px';
  534. link.style.setProperty('padding-left', padding, 'important');
  535. link.style.setProperty('padding-right', padding, 'important');
  536.  
  537. let textContent = elementConfig.text.content;
  538.  
  539. if (elementConfig.icon.remove) {
  540. const svgId = `${configKey}-svg`;
  541. const svg = link.querySelector('svg');
  542.  
  543. if (!svg) {
  544. logError(`Selector '${configKey} svg' not found`);
  545.  
  546. return;
  547. }
  548.  
  549. svg.setAttribute('id', svgId);
  550.  
  551. HEADER_STYLE.textContent += cssHideElement(createId(svgId));
  552. } else {
  553. link.querySelector('svg').style.setProperty('fill', elementConfig.icon.color);
  554. textContent = UNICODE_NON_BREAKING_SPACE + textContent;
  555. }
  556.  
  557. modifyThenObserve(() => {
  558. HEADER.querySelector(createId(elementSelector.textContent))?.remove();
  559. });
  560.  
  561. if (elementConfig.text.content !== '') {
  562. const spanElement = document.createElement('span');
  563. const spanId = `${configKey}-text-content-span`;
  564. spanElement.setAttribute('id', spanId);
  565.  
  566. if (elementConfig.text.color) {
  567. HEADER_STYLE.textContent += `
  568. ${createId(spanId)}
  569. {
  570. color: ${elementConfig.text.color} !important;
  571. }
  572. `;
  573. }
  574.  
  575. const textNode = document.createTextNode(textContent);
  576. spanElement.appendChild(textNode);
  577.  
  578. link.appendChild(spanElement);
  579. }
  580.  
  581. if (!elementConfig.border) {
  582. HEADER_STYLE.textContent += `
  583. ${linkSelector}
  584. {
  585. border: none !important;
  586. }
  587. `;
  588. }
  589.  
  590. if (elementConfig.boxShadow !== '') {
  591. HEADER_STYLE.textContent += `
  592. ${linkSelector}
  593. {
  594. box-shadow: ${elementConfig.boxShadow} !important;
  595. }
  596. `;
  597. }
  598.  
  599. if (elementConfig.hover.backgroundColor !== '') {
  600. HEADER_STYLE.textContent += `
  601. ${linkSelector}:hover
  602. {
  603. background-color: ${elementConfig.hover.backgroundColor} !important;
  604. }
  605. `;
  606. }
  607.  
  608. if (elementConfig.hover.color !== '') {
  609. HEADER_STYLE.textContent += `
  610. ${linkSelector} span:hover
  611. {
  612. color: ${elementConfig.hover.color} !important;
  613. }
  614. `;
  615. }
  616.  
  617. log(DEBUG, `Updates applied to link ${configKey}`, link);
  618. }
  619.  
  620. function cloneAndFlipElements(firstElementSelector, secondElementSelector, firstElementId, secondElementId) {
  621. log(DEBUG, 'cloneAndFlipElements()');
  622.  
  623. const firstElement = HEADER.querySelector(firstElementSelector);
  624.  
  625. if (!firstElement) {
  626. logError(`Selector '${firstElementSelector}' not found`);
  627. return [];
  628. }
  629.  
  630. const secondElement = HEADER.querySelector(secondElementSelector);
  631.  
  632. if (!secondElement) {
  633. logError(`Selector '${secondElementSelector}' not found`);
  634. return [];
  635. }
  636.  
  637. const firstElementClone = firstElement.cloneNode(true);
  638. const secondElementClone = secondElement.cloneNode(true);
  639.  
  640. const firstElementCloneId = `${firstElementId}-clone`;
  641. const secondElementCloneId = `${secondElementId}-clone`;
  642.  
  643. firstElementClone.setAttribute('id', firstElementCloneId);
  644. secondElementClone.setAttribute('id', secondElementCloneId);
  645.  
  646. firstElementClone.style.setProperty('display', 'none');
  647. secondElementClone.style.setProperty('display', 'none');
  648.  
  649. HEADER_STYLE.textContent = HEADER_STYLE.textContent.replace(
  650. new RegExp(escapeRegExp(firstElementSelector), 'g'),
  651. createId(firstElementCloneId),
  652. );
  653.  
  654. HEADER_STYLE.textContent = HEADER_STYLE.textContent.replace(
  655. new RegExp(escapeRegExp(secondElementSelector), 'g'),
  656. createId(secondElementCloneId),
  657. );
  658.  
  659. HEADER_STYLE.textContent += cssHideElement(firstElementSelector);
  660. HEADER_STYLE.textContent += cssHideElement(secondElementSelector);
  661.  
  662. log(VERBOSE, `#${firstElementCloneId}, #${secondElementCloneId}`);
  663. HEADER_STYLE.textContent += `
  664. #${firstElementCloneId},
  665. #${secondElementCloneId}
  666. {
  667. display: flex !important;
  668. }
  669. `;
  670.  
  671. if (secondElement.nextElementSibling === null) {
  672. secondElement.parentNode.appendChild(firstElementClone);
  673. } else {
  674. secondElement.parentNode.insertBefore(firstElementClone, secondElement.nextElementSibling);
  675. }
  676.  
  677. if (firstElement.nextElementSibling === null) {
  678. firstElement.parentNode.appendChild(secondElementClone);
  679. } else{
  680. firstElement.parentNode.insertBefore(secondElementClone, firstElement.nextElementSibling);
  681. }
  682.  
  683. if (firstElementSelector.includes('clone')) {
  684. firstElement.remove();
  685. }
  686.  
  687. if (secondElementSelector.includes('clone')) {
  688. secondElement.remove();
  689. }
  690.  
  691. NEW_ELEMENTS.push(firstElementClone);
  692. NEW_ELEMENTS.push(secondElementClone);
  693.  
  694. return [firstElementClone, secondElementClone];
  695. }
  696.  
  697. function flipIssuesPullRequests() {
  698. log(DEBUG, 'flipIssuesPullRequest()');
  699.  
  700. const issuesId = SELECTORS.issues[CONFIG_NAME]?.leftAlignedId || SELECTORS.issues.id;
  701. log(VERBOSE, 'issuesId', issuesId);
  702.  
  703. const pullRequestsId = SELECTORS.pullRequests[CONFIG_NAME]?.leftAlignedId || SELECTORS.pullRequests.id;
  704. log(VERBOSE, 'pullRequestsId', pullRequestsId);
  705.  
  706. cloneAndFlipElements(
  707. createId(issuesId),
  708. createId(pullRequestsId),
  709. `${issuesId}-flip-div`,
  710. `${pullRequestsId}-flip-div`,
  711. );
  712. }
  713.  
  714. function createOldLink(configKey, svgString) {
  715. const pullRequestsLink = HEADER.querySelector(SELECTORS.pullRequests.link);
  716.  
  717. if (!pullRequestsLink) {
  718. logError(`Selector '${SELECTORS.pullRequests.link}' not found`);
  719. return;
  720. }
  721.  
  722. const clonedLink = pullRequestsLink.cloneNode(true);
  723.  
  724. const linkId = SELECTORS[configKey].id;
  725. clonedLink.setAttribute('id', linkId);
  726.  
  727. const oldSvg = clonedLink.querySelector('svg');
  728.  
  729. const parser = new DOMParser();
  730. const svgDoc = parser.parseFromString(svgString, 'image/svg+xml');
  731. const newSvg = svgDoc.documentElement;
  732.  
  733. oldSvg.parentNode.replaceChild(newSvg, oldSvg);
  734.  
  735. const ariaId = `tooltip-${configKey}`;
  736.  
  737. clonedLink.setAttribute('href', `/${configKey}`);
  738. clonedLink.setAttribute('aria-labelledby', ariaId);
  739. clonedLink.removeAttribute('data-analytics-event');
  740.  
  741. clonedLink.querySelector('span')?.remove();
  742.  
  743. pullRequestsLink.parentNode.appendChild(clonedLink);
  744.  
  745. NEW_ELEMENTS.push(clonedLink);
  746. }
  747.  
  748. function createMarketplaceLink() {
  749. log(DEBUG, 'createMarketplaceLink()');
  750.  
  751. const svgString = `
  752. <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-gift">
  753. <path d="M2 2.75A2.75 2.75 0 0 1 4.75 0c.983 0 1.873.42 2.57 1.232.268.318.497.668.68 1.042.183-.375.411-.725.68-1.044C9.376.42 10.266 0 11.25 0a2.75 2.75 0 0 1 2.45 4h.55c.966 0 1.75.784 1.75 1.75v2c0 .698-.409 1.301-1 1.582v4.918A1.75 1.75 0 0 1 13.25 16H2.75A1.75 1.75 0 0 1 1 14.25V9.332C.409 9.05 0 8.448 0 7.75v-2C0 4.784.784 4 1.75 4h.55c-.192-.375-.3-.8-.3-1.25ZM7.25 9.5H2.5v4.75c0 .138.112.25.25.25h4.5Zm1.5 0v5h4.5a.25.25 0 0 0 .25-.25V9.5Zm0-4V8h5.5a.25.25 0 0 0 .25-.25v-2a.25.25 0 0 0-.25-.25Zm-7 0a.25.25 0 0 0-.25.25v2c0 .138.112.25.25.25h5.5V5.5h-5.5Zm3-4a1.25 1.25 0 0 0 0 2.5h2.309c-.233-.818-.542-1.401-.878-1.793-.43-.502-.915-.707-1.431-.707ZM8.941 4h2.309a1.25 1.25 0 0 0 0-2.5c-.516 0-1 .205-1.43.707-.337.392-.646.975-.879 1.793Z"></path>
  754. </svg>
  755. `;
  756.  
  757. createOldLink('marketplace', svgString);
  758. }
  759.  
  760. function createExploreLink() {
  761. log(DEBUG, 'createExploreLink()');
  762.  
  763. const svgString = `
  764. <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-telescope">
  765. <path d="M14.184 1.143v-.001l1.422 2.464a1.75 1.75 0 0 1-.757 2.451L3.104 11.713a1.75 1.75 0 0 1-2.275-.702l-.447-.775a1.75 1.75 0 0 1 .53-2.32L11.682.573a1.748 1.748 0 0 1 2.502.57Zm-4.709 9.32h-.001l2.644 3.863a.75.75 0 1 1-1.238.848l-1.881-2.75v2.826a.75.75 0 0 1-1.5 0v-2.826l-1.881 2.75a.75.75 0 1 1-1.238-.848l2.049-2.992a.746.746 0 0 1 .293-.253l1.809-.87a.749.749 0 0 1 .944.252ZM9.436 3.92h-.001l-4.97 3.39.942 1.63 5.42-2.61Zm3.091-2.108h.001l-1.85 1.26 1.505 2.605 2.016-.97a.247.247 0 0 0 .13-.151.247.247 0 0 0-.022-.199l-1.422-2.464a.253.253 0 0 0-.161-.119.254.254 0 0 0-.197.038ZM1.756 9.157a.25.25 0 0 0-.075.33l.447.775a.25.25 0 0 0 .325.1l1.598-.769-.83-1.436-1.465 1Z"></path>
  766. </svg>
  767. `;
  768.  
  769. createOldLink('explore', svgString);
  770. }
  771.  
  772. function updateCreateNewButton() {
  773. log(DEBUG, 'updateCreateNewButton()');
  774.  
  775. const configKey = 'create';
  776. const elementSelector = SELECTORS[configKey];
  777. const tooltipElement = SELECTORS.toolTips[configKey];
  778.  
  779. if (!tooltipElement) {
  780. logError(`Selector '${SELECTORS.toolTips[configKey]}' not found`);
  781. return;
  782. }
  783.  
  784. let button = HEADER.querySelector(elementSelector.button);
  785. let oldButtonId = null;
  786.  
  787. if (!button) {
  788. logError(`Selector '${elementSelector.button}' not found`);
  789.  
  790. oldButtonId = `${elementSelector.button}-old`;
  791. button = HEADER.querySelector(oldButtonId);
  792.  
  793. if (!button) {
  794. logError(`Selector '${oldButtonId}' not found`);
  795. return;
  796. }
  797. }
  798.  
  799. const elementConfig = CONFIG[configKey];
  800.  
  801. if (elementConfig.remove) {
  802. HEADER_STYLE.textContent += cssHideElement(elementSelector.topDiv);
  803.  
  804. return;
  805. } else if (!elementConfig.tooltip) {
  806. HEADER_STYLE.textContent += cssHideElement(createId(tooltipElement.id));
  807. }
  808.  
  809. const topDiv = HEADER.querySelector(elementSelector.topDiv);
  810.  
  811. if (!topDiv) {
  812. logError(`Selector '${elementSelector.topDiv}' not found`);
  813. return;
  814. }
  815.  
  816. topDiv.setAttribute('id', elementSelector.id);
  817.  
  818. const buttonLabel = button.querySelector(elementSelector.dropdownIcon);
  819.  
  820. if (elementConfig.plusIcon.remove) {
  821. HEADER_STYLE.textContent += `
  822. ${oldButtonId || elementSelector.button} ${elementSelector.plusIcon}
  823. {
  824. display: none !important
  825. }
  826. `;
  827. } else {
  828.  
  829. if (elementConfig.plusIcon.color !== '') {
  830. HEADER_STYLE.textContent += `
  831. ${elementSelector.plusIcon}
  832. {
  833. color: ${elementConfig.plusIcon.color} !important;
  834. }
  835. `;
  836. }
  837.  
  838. if (elementConfig.plusIcon.hover.color !== '') {
  839. HEADER_STYLE.textContent += `
  840. ${elementSelector.plusIcon.split(' ').join(':hover ')} svg path
  841. {
  842. fill: ${elementConfig.plusIcon.hover.color} !important;
  843. }
  844. `;
  845. }
  846.  
  847. if (elementConfig.plusIcon.marginRight !== '') {
  848. HEADER_STYLE.textContent += `
  849. ${elementSelector.plusIcon}
  850. {
  851. margin-right: ${elementConfig.plusIcon.marginRight} !important;
  852. }
  853. `;
  854. }
  855. }
  856.  
  857. modifyThenObserve(() => {
  858. HEADER.querySelector(createId(SELECTORS[configKey].textContent))?.remove();
  859. });
  860.  
  861. if (elementConfig.text.content !== '') {
  862. // Update the text's font properties to match the others
  863. HEADER_STYLE.textContent += `
  864. ${elementSelector.button}
  865. {
  866. font-size: var(--text-body-size-medium, 0.875rem) !important;
  867. font-weight: var(--base-text-weight-medium, 500) !important;
  868. }
  869. `;
  870.  
  871. const spanElement = document.createElement('span');
  872. spanElement.setAttribute('id', elementSelector.textContent);
  873.  
  874. spanElement.style.setProperty('color', elementConfig.text.color);
  875. spanElement.textContent = elementConfig.text.content;
  876.  
  877. // New span is inserted between the plus sign and dropdown icon
  878. buttonLabel.parentNode.insertBefore(spanElement, buttonLabel);
  879. }
  880.  
  881. if (elementConfig.dropdownIcon.remove) {
  882. HEADER_STYLE.textContent += `
  883. ${elementSelector.dropdownIcon}
  884. {
  885. display: none !important
  886. }
  887. `;
  888. } else {
  889. HEADER_STYLE.textContent += `
  890. ${elementSelector.dropdownIcon}
  891. {
  892. grid-area: initial !important;
  893. }
  894. `;
  895.  
  896. if (elementConfig.dropdownIcon.color !== '') {
  897. HEADER_STYLE.textContent += `
  898. ${elementSelector.dropdownIcon}
  899. {
  900. color: ${elementConfig.dropdownIcon.color} !important;
  901. }
  902. `;
  903. }
  904.  
  905. if (elementConfig.dropdownIcon.hover.color !== '') {
  906. HEADER_STYLE.textContent += `
  907. ${elementSelector.dropdownIcon.split(' ').join(':hover ')} svg path
  908. {
  909. fill: ${elementConfig.dropdownIcon.hover.color} !important;
  910. }
  911. `;
  912. }
  913. }
  914.  
  915. if (!elementConfig.border) {
  916. HEADER_STYLE.textContent += `
  917. ${elementSelector.button}
  918. {
  919. border: none !important;
  920. }
  921. `;
  922. }
  923.  
  924. if (elementConfig.boxShadow !== '') {
  925. HEADER_STYLE.textContent += `
  926. ${elementSelector.button}
  927. {
  928. box-shadow: ${elementConfig.boxShadow} !important;
  929. }
  930. `;
  931. }
  932.  
  933. if (elementConfig.hoverBackgroundColor !== '') {
  934. HEADER_STYLE.textContent += `
  935. ${elementSelector.button}:hover
  936. {
  937. background-color: ${elementConfig.hoverBackgroundColor} !important;
  938. }
  939. `;
  940. }
  941. }
  942.  
  943. function updateInboxLink() {
  944. log(DEBUG, 'updateInboxLink()');
  945.  
  946. const configKey = 'notifications';
  947.  
  948. const elementConfig = CONFIG[configKey];
  949. const elementSelector = SELECTORS[configKey];
  950.  
  951. const notificationIndicator = HEADER.querySelector(createId(elementSelector.id)) ||
  952. HEADER.querySelector(elementSelector.indicator);
  953.  
  954. if (!notificationIndicator) {
  955. logError(`Selectors '${createId(elementSelector.id)}' and '${elementSelector.indicator}' not found`);
  956. return;
  957. }
  958.  
  959. notificationIndicator.setAttribute('id', elementSelector.id);
  960.  
  961. const inboxLink = notificationIndicator.querySelector('a');
  962.  
  963. if (!inboxLink) {
  964. logError(`Selector '${elementSelector.indicator} a' not found`);
  965. return;
  966. }
  967.  
  968. if (elementConfig.remove) {
  969. HEADER_STYLE.textContent += cssHideElement(elementSelector.indicator);
  970. }
  971.  
  972. if (!elementConfig.tooltip) {
  973. HEADER_STYLE.textContent += cssHideElement(createId(SELECTORS.toolTips.notifications.id));
  974. }
  975.  
  976. if (elementConfig.dot.remove) {
  977. HEADER_STYLE.textContent += `
  978. ${elementSelector.dot}
  979. {
  980. content: none !important;
  981. }
  982. `;
  983. } else {
  984. if (elementConfig.dot.color !== '') {
  985. HEADER_STYLE.textContent += `
  986. ${elementSelector.dot}
  987. {
  988. background: ${elementConfig.dot.color} !important;
  989. }
  990. `;
  991. }
  992.  
  993. if (elementConfig.dot.boxShadowColor !== '') {
  994. HEADER_STYLE.textContent += `
  995. ${elementSelector.dot}
  996. {
  997. box-shadow: 0 0 0 calc(var(--base-size-4, 4px)/2) ${elementConfig.dot.boxShadowColor} !important;
  998. }
  999. `;
  1000. }
  1001. }
  1002.  
  1003. if (elementConfig.icon.symbol === 'inbox') {
  1004. if (elementConfig.icon.color !== '') {
  1005. HEADER_STYLE.textContent += `
  1006. ${createId(elementSelector.id)} a svg
  1007. {
  1008. fill: elementConfig.icon.color !important;
  1009. }
  1010. `;
  1011. }
  1012. } else {
  1013. const inboxSvgId = 'inbox-svg';
  1014. const inboxSvg = inboxLink.querySelector('svg');
  1015. inboxSvg.setAttribute('id', inboxSvgId);
  1016.  
  1017. HEADER_STYLE.textContent += cssHideElement(createId(inboxSvgId));
  1018. }
  1019.  
  1020. if (elementConfig.icon.symbol === 'bell') {
  1021. // Bell icon from https://gist.github.com
  1022. const bellSvgId = 'bell-svg';
  1023. const bellSvg = `
  1024. <svg id=${bellSvgId} style="display: none;" aria-hidden='true' height='16' viewBox='0 0 16 16' version='1.1' width='16' data-view-component='true' class='octicon octicon-bell'>
  1025. <path d='M8 16a2 2 0 0 0 1.985-1.75c.017-.137-.097-.25-.235-.25h-3.5c-.138 0-.252.113-.235.25A2 2 0 0 0 8 16ZM3 5a5 5 0 0 1 10 0v2.947c0 .05.015.098.042.139l1.703 2.555A1.519 1.519 0 0 1 13.482 13H2.518a1.516 1.516 0 0 1-1.263-2.36l1.703-2.554A.255.255 0 0 0 3 7.947Zm5-3.5A3.5 3.5 0 0 0 4.5 5v2.947c0 .346-.102.683-.294.97l-1.703 2.556a.017.017 0 0 0-.003.01l.001.006c0 .002.002.004.004.006l.006.004.007.001h10.964l.007-.001.006-.004.004-.006.001-.007a.017.017 0 0 0-.003-.01l-1.703-2.554a1.745 1.745 0 0 1-.294-.97V5A3.5 3.5 0 0 0 8 1.5Z'></path>
  1026. </svg>
  1027. `;
  1028.  
  1029. inboxLink.insertAdjacentHTML('afterbegin', bellSvg);
  1030.  
  1031. HEADER_STYLE.textContent += `
  1032. ${createId(bellSvgId)}
  1033. {
  1034. display: initial !important;
  1035. }
  1036. `;
  1037.  
  1038. if (elementConfig.icon.color !== '') {
  1039. HEADER_STYLE.textContent += `
  1040. ${createId(bellSvgId)} path
  1041. {
  1042. fill: ${elementConfig.icon.color} !important;
  1043. }
  1044. `;
  1045. }
  1046. }
  1047.  
  1048. if (elementConfig.icon.hover.color !== '') {
  1049. HEADER_STYLE.textContent += `
  1050. ${createId(elementSelector.id)} a:hover svg path
  1051. {
  1052. fill: ${elementConfig.icon.hover.color} !important;
  1053. }
  1054. `;
  1055. }
  1056.  
  1057. modifyThenObserve(() => {
  1058. HEADER.querySelector(createId(SELECTORS[configKey].textContent))?.remove();
  1059. });
  1060.  
  1061. if (elementConfig.text.content !== '') {
  1062. const padding = '9px';
  1063.  
  1064. HEADER_STYLE.textContent += `
  1065. ${createId(elementSelector.id)} a
  1066. {
  1067. padding-left: ${padding} !important;
  1068. padding-right: ${padding} !important;
  1069. width: auto !important;
  1070. text-decoration: none !important;
  1071. display: flex !important;
  1072. }
  1073. `;
  1074.  
  1075. let textContent = elementConfig.text.content;
  1076.  
  1077. if (elementConfig.icon !== '') {
  1078. textContent = UNICODE_NON_BREAKING_SPACE + textContent;
  1079. }
  1080.  
  1081. const spanElement = document.createElement('span');
  1082. spanElement.setAttribute('id', elementSelector.textContent);
  1083.  
  1084. // Update the text's font properties to match the others
  1085. spanElement.style.setProperty('font-size', 'var(--text-body-size-medium, 0.875rem)', 'important');
  1086. spanElement.style.setProperty('font-weight', 'var(--base-text-weight-medium, 500)', 'important');
  1087.  
  1088. if (elementConfig.text.color) spanElement.style.setProperty('color', elementConfig.text.color);
  1089.  
  1090. const textNode = document.createTextNode(textContent);
  1091. spanElement.appendChild(textNode);
  1092.  
  1093. inboxLink.appendChild(spanElement);
  1094. }
  1095.  
  1096. if (!elementConfig.border) {
  1097. HEADER_STYLE.textContent += `
  1098. ${createId(elementSelector.id)} a
  1099. {
  1100. border: none !important;
  1101. }
  1102. `;
  1103. }
  1104.  
  1105. if (elementConfig.boxShadow !== '') {
  1106. HEADER_STYLE.textContent += `
  1107. ${createId(elementSelector.id)} a
  1108. {
  1109. box-shadow: ${elementConfig.boxShadow} !important;
  1110. }
  1111. `;
  1112. }
  1113.  
  1114. if (elementConfig.dot.displayOverIcon) {
  1115. HEADER_STYLE.textContent += `
  1116. ${elementSelector.dot}
  1117. {
  1118. top: 5px !important;
  1119. left: 18px !important;
  1120. }
  1121. `;
  1122. }
  1123.  
  1124. if (elementConfig.hoverBackgroundColor !== '') {
  1125. HEADER_STYLE.textContent += `
  1126. ${createId(elementSelector.id)} a:hover
  1127. {
  1128. background-color: ${elementConfig.hoverBackgroundColor} !important;
  1129. }
  1130. `;
  1131. }
  1132.  
  1133. log(DEBUG, `Updates applied to link ${configKey}: `, inboxLink);
  1134. }
  1135.  
  1136. function insertAvatarDropdown() {
  1137. log(DEBUG, 'insertAvatarDropdown()');
  1138.  
  1139. const elementSelector = SELECTORS.avatar;
  1140. const svgSelector = elementSelector.svg;
  1141.  
  1142. if (HEADER.querySelector(createId(svgSelector))) {
  1143. log(VERBOSE, `Selector ${createId(svgSelector)} not found`);
  1144. return;
  1145. }
  1146.  
  1147. const dropdownSvg = `
  1148. <svg id='${svgSelector}' style="display: none;" height="100%" width="100%" fill="#FFFFFF" class="octicon octicon-triangle-down" aria-hidden="true" viewBox="0 0 16 16" version="1.1" data-view-component="true">
  1149. <path d="m4.427 7.427 3.396 3.396a.25.25 0 0 0 .354 0l3.396-3.396A.25.25 0 0 0 11.396 7H4.604a.25.25 0 0 0-.177.427Z"></path>
  1150. </svg>
  1151. `;
  1152.  
  1153. const button = HEADER.querySelector(elementSelector.button);
  1154.  
  1155. if (!button) {
  1156. logError(`Selector '${elementSelector.button}' not found`);
  1157. return;
  1158. }
  1159.  
  1160. const divElement = document.createElement('div');
  1161. divElement.insertAdjacentHTML('afterbegin', dropdownSvg);
  1162.  
  1163. button.appendChild(divElement);
  1164. }
  1165.  
  1166. function updateAvatarButton() {
  1167. log(DEBUG, 'updateAvatarButton()');
  1168.  
  1169. const elementSelector = SELECTORS.sidebars.right;
  1170. const topDivSelector = elementSelector.topDiv;
  1171.  
  1172. const topDiv = HEADER.querySelector(topDivSelector);
  1173.  
  1174. if (!topDiv) {
  1175. log(DEBUG, `Selector ${topDivSelector} not found`);
  1176. return;
  1177. }
  1178.  
  1179. const avatarButton = HEADER.querySelector(SELECTORS.avatar.button);
  1180.  
  1181. if (!avatarButton) {
  1182. log(DEBUG, `Selector ${SELECTORS.avatar.button} not found`);
  1183. return;
  1184. }
  1185.  
  1186. if (topDiv.classList.contains('Overlay--hidden')) {
  1187. if (avatarButton.hasAttribute('data-close-dialog-id')) {
  1188. const dialogId = avatarButton.getAttribute('data-close-dialog-id');
  1189. avatarButton.setAttribute('data-show-dialog-id', dialogId);
  1190.  
  1191. avatarButton.removeAttribute('data-close-dialog-id');
  1192. }
  1193. } else {
  1194. if (avatarButton.hasAttribute('data-show-dialog-id')) {
  1195. const dialogId = avatarButton.getAttribute('data-show-dialog-id');
  1196. avatarButton.setAttribute('data-close-dialog-id', dialogId);
  1197.  
  1198. avatarButton.removeAttribute('data-show-dialog-id');
  1199. }
  1200. }
  1201. }
  1202.  
  1203. function updateAvatar() {
  1204. log(DEBUG, 'updateAvatar()');
  1205.  
  1206. const configKey = 'avatar';
  1207.  
  1208. const elementConfig = CONFIG[configKey];
  1209. const elementSelector = SELECTORS[configKey];
  1210.  
  1211. if (elementConfig.remove) {
  1212. HEADER_STYLE.textContent += cssHideElement(elementSelector.topDiv);
  1213.  
  1214. return;
  1215. }
  1216.  
  1217. if (elementConfig.size !== '') {
  1218. HEADER_STYLE.textContent += `
  1219. ${elementSelector.img}
  1220. {
  1221. height: ${elementConfig.size} !important;
  1222. width: ${elementConfig.size} !important;
  1223. }
  1224. `;
  1225. }
  1226.  
  1227. if (elementConfig.dropdownIcon) {
  1228. insertAvatarDropdown();
  1229.  
  1230. HEADER_STYLE.textContent += `
  1231. ${elementSelector.topDiv}
  1232. {
  1233. background-color: transparent !important;
  1234. }
  1235.  
  1236. ${createId(elementSelector.svg)}
  1237. {
  1238. display: initial !important;
  1239. fill: #FFFFFF;
  1240. height: 16px;
  1241. width: 16px;
  1242. margin-bottom: 1.5px;
  1243. }
  1244.  
  1245. ${elementSelector.button}:hover ${createId(elementSelector.svg)} path
  1246. {
  1247. fill: #FFFFFFB3 !important;
  1248. }
  1249.  
  1250. ${elementSelector.button}
  1251. {
  1252. gap: 0px !important;
  1253. }
  1254. `;
  1255. }
  1256. }
  1257.  
  1258. function flipCreateInbox() {
  1259. log(DEBUG, 'flipCreateInbox()');
  1260.  
  1261. const response = cloneAndFlipElements(
  1262. createId(SELECTORS.create.id),
  1263. createId(SELECTORS.notifications.id),
  1264. `${SELECTORS.create.id}-flip`,
  1265. `${SELECTORS.notifications.id}-flip`,
  1266. );
  1267.  
  1268. if (response.length === 0) return;
  1269.  
  1270. // The dynamic positioning logic of the overlay only seems to work on the original IDs,
  1271. // so must rename the originals elements to avoid a conflict.
  1272. const originalButtonId = `${SELECTORS.create.button}-old`.replace('#', '');
  1273. HEADER.querySelector(SELECTORS.create.button).setAttribute('id', originalButtonId);
  1274.  
  1275. const originalOverlayId = `${SELECTORS.create.overlay}-old`.replace('#', '');
  1276. HEADER.querySelector(SELECTORS.create.overlay).setAttribute('id', originalOverlayId);
  1277. }
  1278.  
  1279. function updateGlobalBar() {
  1280. log(DEBUG, 'updateGlobalBar()');
  1281.  
  1282. const elementConfig = CONFIG.globalBar;
  1283.  
  1284. if (elementConfig.boxShadowColor !== '') {
  1285. HEADER_STYLE.textContent += `
  1286. ${SELECTORS.header.globalBar}
  1287. {
  1288. box-shadow: inset 0 calc(var(--borderWidth-thin, 1px)*-1) ${elementConfig.boxShadowColor} !important;
  1289. }
  1290. `;
  1291. }
  1292.  
  1293. if (elementConfig.rightAligned.gap !== '') {
  1294. HEADER_STYLE.textContent += `
  1295. ${SELECTORS.header.rightAligned}
  1296. {
  1297. gap: ${elementConfig.rightAligned.gap} !important;
  1298. }
  1299. `;
  1300. }
  1301.  
  1302. if (elementConfig.leftAligned.gap !== '') {
  1303. HEADER_STYLE.textContent += `
  1304. ${SELECTORS.header.leftAligned}
  1305. {
  1306. gap: ${elementConfig.leftAligned.gap} !important;
  1307. }
  1308. `;
  1309. }
  1310. }
  1311.  
  1312. function updateLocalBar() {
  1313. log(DEBUG, 'updateLocalBar()');
  1314.  
  1315. const elementConfig = CONFIG.localBar;
  1316.  
  1317. if (elementConfig.backgroundColor !== '') {
  1318. HEADER_STYLE.textContent += `
  1319. ${SELECTORS.header.localBar.topDiv}
  1320. {
  1321. background-color: ${elementConfig.backgroundColor} !important;
  1322. box-shadow: inset 0 calc(var(--borderWidth-thin, 1px)*-1) var(--color-border-default) !important;
  1323. }
  1324. `;
  1325. }
  1326.  
  1327. if (elementConfig.alignCenter) {
  1328. HEADER_STYLE.textContent += `
  1329. ${SELECTORS.header.localBar.underlineNavActions}
  1330. {
  1331. display: initial !important;
  1332. padding-right: 0px !important;
  1333. }
  1334.  
  1335. ${SELECTORS.header.localBar.topDiv} nav
  1336. {
  1337. max-width: 1280px;
  1338. margin-right: auto;
  1339. margin-left: auto;
  1340. }
  1341.  
  1342. @media (min-width: 768px) {
  1343. ${SELECTORS.header.localBar.topDiv} nav
  1344. {
  1345. padding-right: var(--base-size-24, 24px) !important;
  1346. padding-left: var(--base-size-24, 24px) !important;
  1347. }
  1348. }
  1349.  
  1350. @media (min-width: 1012px) {
  1351. ${SELECTORS.header.localBar.topDiv} nav
  1352. {
  1353. padding-right: var(--base-size-32, 32px) !important;
  1354. padding-left: var(--base-size-32, 32px) !important;
  1355. }
  1356. }
  1357. `;
  1358. }
  1359.  
  1360. if (elementConfig.boxShadow.consistentColor) {
  1361. HEADER_STYLE.textContent += `
  1362. .UnderlineNav
  1363. {
  1364. box-shadow: none !important;
  1365. }
  1366. `;
  1367. }
  1368.  
  1369. if (elementConfig.links.color !== '') {
  1370. HEADER_STYLE.textContent += `
  1371. ${SELECTORS.header.localBar.topDiv} a,
  1372. ${SELECTORS.header.localBar.topDiv} a span
  1373. {
  1374. color: ${elementConfig.links.color} !important;
  1375. }
  1376. `;
  1377. }
  1378. }
  1379.  
  1380. function updateSidebars() {
  1381. log(DEBUG, 'updateSidebars()');
  1382.  
  1383. const configKey = 'sidebars';
  1384.  
  1385. const elementConfig = CONFIG[configKey];
  1386. const elementSelector = SELECTORS[configKey];
  1387.  
  1388. if (elementConfig.backdrop.color !== '') {
  1389. HEADER_STYLE.textContent += `
  1390. ${elementSelector.backdrop}
  1391. {
  1392. background: ${CONFIG.sidebars.backdrop.color} !important;
  1393. }
  1394. `;
  1395. }
  1396.  
  1397. if (elementConfig.left.preload && !LEFT_SIDEBAR_PRELOADED) {
  1398. HEADER.querySelector(elementSelector.left.modalDialog).remove();
  1399.  
  1400. window.addEventListener('load', () => {
  1401. HEADER.querySelector(`${SELECTORS.hamburgerButton} button`).click();
  1402. log(INFO, 'Left sidebar preloaded');
  1403. });
  1404.  
  1405. LEFT_SIDEBAR_PRELOADED = true;
  1406. }
  1407.  
  1408. if (elementConfig.right.floatUnderneath) {
  1409. HEADER_STYLE.textContent += `
  1410. ${elementSelector.right.modalDialog}
  1411. {
  1412. border-top-right-radius: 0.75rem !important;
  1413. border-bottom-right-radius: 0.75rem !important;
  1414. bottom: initial !important;
  1415. margin-top: 55px;
  1416. margin-right: 20px;
  1417. }
  1418.  
  1419. ${elementSelector.right.navParentDiv}
  1420. {
  1421. margin-bottom: 0px !important;
  1422. }
  1423.  
  1424. ${elementSelector.right.nav}
  1425. {
  1426. padding-bottom: 0px !important;
  1427. }
  1428. `;
  1429. }
  1430.  
  1431. if (elementConfig.right.preload && !RIGHT_SIDEBAR_PRELOADED) {
  1432. HEADER.querySelector(elementSelector.right.modalDialog).remove();
  1433.  
  1434. window.addEventListener('load', () => {
  1435. HEADER.querySelector(SELECTORS.avatar.button).click();
  1436. log(INFO, 'Right sidebar preloaded');
  1437. });
  1438.  
  1439. RIGHT_SIDEBAR_PRELOADED = true;
  1440. }
  1441.  
  1442. if (elementConfig.right.maxHeight) {
  1443. HEADER_STYLE.textContent += `
  1444. ${elementSelector.right.modalDialog}
  1445. {
  1446. max-height: ${elementConfig.right.maxHeight} !important;
  1447. }
  1448. `;
  1449. }
  1450.  
  1451. if (elementConfig.right.width !== '') {
  1452. HEADER_STYLE.textContent += `
  1453. ${elementSelector.right.modalDialog}.Overlay.Overlay--size-small-portrait
  1454. {
  1455. --overlay-width: ${elementConfig.right.width};
  1456. }
  1457. `;
  1458. }
  1459. }
  1460.  
  1461. function importRepositoryHeader() {
  1462. log(DEBUG, 'importRepositoryHeader()');
  1463.  
  1464. const configKey = 'repositoryHeader';
  1465. const repositoryHeader = document.querySelector(SELECTORS[configKey].id);
  1466.  
  1467. if (!repositoryHeader) {
  1468. // This is expected on pages that aren't repositories
  1469. log(DEBUG, `Selector '${SELECTORS[configKey].id}' not found`);
  1470. return;
  1471. }
  1472.  
  1473. const topRepositoryHeaderElement = document.createElement('div');
  1474. topRepositoryHeaderElement.style.setProperty('display', 'flex');
  1475. topRepositoryHeaderElement.style.setProperty('padding', '0px');
  1476. topRepositoryHeaderElement.style.setProperty('box-shadow', 'none');
  1477.  
  1478. const elementConfig = CONFIG[configKey];
  1479.  
  1480. if (elementConfig.backgroundColor !== '') {
  1481. topRepositoryHeaderElement.style.setProperty('background-color', elementConfig.backgroundColor);
  1482. }
  1483.  
  1484. if (repositoryHeader.hidden) {
  1485. log(VERBOSE, `Selector '${SELECTORS[configKey].id}' is hidden`);
  1486.  
  1487. if (!HEADER.querySelector(SELECTORS.pageTitle.separator)) {
  1488. log(INFO, `Selector '${SELECTORS.pageTitle.separator}' not found, not creating a repository header`);
  1489.  
  1490. return;
  1491. }
  1492.  
  1493. // A repo tab other than Code is being loaded for the first time
  1494. const pageTitle = HEADER.querySelector(SELECTORS.pageTitle.topDiv);
  1495.  
  1496. if (!pageTitle) {
  1497. logError(`Selector '${SELECTORS.pageTitle.topDiv}' not found`);
  1498. return;
  1499. }
  1500.  
  1501. const repositoryHeaderElement = document.createElement('div');
  1502. repositoryHeaderElement.setAttribute('id', TEMP_REPOSITORY_HEADER_FLAG);
  1503. repositoryHeaderElement.classList.add(REPOSITORY_HEADER_CLASS, 'pt-3', 'mb-2', 'px-md-4');
  1504.  
  1505. const clonedPageTitle = pageTitle.cloneNode(true);
  1506. repositoryHeaderElement.appendChild(clonedPageTitle);
  1507.  
  1508. topRepositoryHeaderElement.appendChild(repositoryHeaderElement);
  1509. insertNewGlobalBar(topRepositoryHeaderElement);
  1510. } else if (HEADER.querySelector(createId(TEMP_REPOSITORY_HEADER_FLAG))) {
  1511. log(VERBOSE, `Selector '${createId(TEMP_REPOSITORY_HEADER_FLAG)}' found`);
  1512.  
  1513. // The Code tab is being loaded from another tab which has a temporary header
  1514. const tempRepositoryHeader = HEADER.querySelector(createId(TEMP_REPOSITORY_HEADER_FLAG));
  1515.  
  1516. NEW_ELEMENTS = NEW_ELEMENTS.filter(element => element !== tempRepositoryHeader);
  1517. tempRepositoryHeader.remove();
  1518.  
  1519. insertPermanentRepositoryHeader(topRepositoryHeaderElement, repositoryHeader);
  1520. } else {
  1521. log(
  1522. VERBOSE,
  1523. `${SELECTORS[configKey].id} is hidden and selector '${createId(TEMP_REPOSITORY_HEADER_FLAG)}' not found`,
  1524. );
  1525.  
  1526. // The Code tab being loaded for the first time
  1527. insertPermanentRepositoryHeader(topRepositoryHeaderElement, repositoryHeader);
  1528. }
  1529.  
  1530. updateRepositoryHeaderName();
  1531.  
  1532. if (elementConfig.backgroundColor !== '') {
  1533. HEADER_STYLE.textContent += `
  1534. .${REPOSITORY_HEADER_CLASS}
  1535. {
  1536. background-color: ${elementConfig.backgroundColor} !important;
  1537. }
  1538. `;
  1539. }
  1540.  
  1541. if (elementConfig.alignCenter) {
  1542. HEADER_STYLE.textContent += `
  1543. .${REPOSITORY_HEADER_CLASS}
  1544. {
  1545. max-width: 1280px;
  1546. margin-right: auto;
  1547. margin-left: auto;
  1548. }
  1549.  
  1550. .${REPOSITORY_HEADER_CLASS} div
  1551. {
  1552. padding-left: 0px !important;
  1553. padding-right: 0px !important;
  1554. }
  1555.  
  1556. @media (min-width: 768px) {
  1557. .${REPOSITORY_HEADER_CLASS}
  1558. {
  1559. padding-right: var(--base-size-24, 24px) !important;
  1560. padding-left: var(--base-size-24, 24px) !important;
  1561. }
  1562. }
  1563.  
  1564. @media (min-width: 1012px) {
  1565. .${REPOSITORY_HEADER_CLASS}
  1566. {
  1567. padding-right: var(--base-size-32, 32px) !important;
  1568. padding-left: var(--base-size-32, 32px) !important;
  1569. }
  1570. }
  1571. `;
  1572. }
  1573.  
  1574. if (elementConfig.link.color !== '') {
  1575. HEADER_STYLE.textContent += `
  1576. ${SELECTORS.repositoryHeader.links}
  1577. {
  1578. color: ${elementConfig.link.color} !important;
  1579. }
  1580. `;
  1581. }
  1582.  
  1583. if (elementConfig.link.hover.color !== '') {
  1584. HEADER_STYLE.textContent += `
  1585. ${SELECTORS.repositoryHeader.links}:hover
  1586. {
  1587. color: ${elementConfig.link.hover.color} !important;
  1588. }
  1589. `;
  1590. }
  1591.  
  1592. if (elementConfig.link.hover.backgroundColor !== '') {
  1593. HEADER_STYLE.textContent += `
  1594. ${SELECTORS.repositoryHeader.links}:hover
  1595. {
  1596. background-color: ${elementConfig.link.hover.backgroundColor} !important;
  1597. }
  1598. `;
  1599. }
  1600.  
  1601. if (elementConfig.link.hover.textDecoration !== '') {
  1602. HEADER_STYLE.textContent += `
  1603. ${SELECTORS.repositoryHeader.links}:hover
  1604. {
  1605. text-decoration: ${elementConfig.link.hover.textDecoration} !important;
  1606. }
  1607. `;
  1608. }
  1609.  
  1610. HEADER_STYLE.textContent += `
  1611. .${REPOSITORY_HEADER_CLASS}
  1612. {
  1613. flex: auto !important;
  1614. }
  1615.  
  1616. ${SELECTORS.repositoryHeader.details}
  1617. {
  1618. display: flex;
  1619. align-items: center;
  1620. }
  1621.  
  1622. ${SELECTORS.pageTitle.topDiv}
  1623. {
  1624. flex: 0 1 auto !important;
  1625. height: auto !important;
  1626. min-width: 0 !important;
  1627. }
  1628.  
  1629. @media (min-width: 768px)
  1630. {
  1631. .AppHeader-context .AppHeader-context-compact
  1632. {
  1633. display: none !important;
  1634. }
  1635. }
  1636.  
  1637. .AppHeader-context .AppHeader-context-full
  1638. {
  1639. display: inline-flex !important;
  1640. width: 100% !important;
  1641. min-width: 0 !important;
  1642. max-width: 100% !important;
  1643. overflow: hidden !important;
  1644. }
  1645.  
  1646. .AppHeader-context .AppHeader-context-full ul {
  1647. display: flex;
  1648. flex-direction: row;
  1649. }
  1650.  
  1651. .AppHeader-context .AppHeader-context-full li:first-child {
  1652. flex: 0 100 max-content;
  1653. }
  1654.  
  1655. .AppHeader-context .AppHeader-context-full li {
  1656. display: inline-grid;
  1657. grid-auto-flow: column;
  1658. align-items: center;
  1659. flex: 0 99999 auto;
  1660. }
  1661.  
  1662. .AppHeader-context .AppHeader-context-full ul, .AppHeader .AppHeader-globalBar .AppHeader-context .AppHeader-context-full li {
  1663. list-style: none;
  1664. }
  1665.  
  1666. .AppHeader-context .AppHeader-context-item {
  1667. display: flex;
  1668. align-items: center;
  1669. min-width: 3ch;
  1670. line-height: var(--text-body-lineHeight-medium, 1.4285714286);
  1671. text-decoration: none !important;
  1672. border-radius: var(--borderRadius-medium, 6px);
  1673. padding-inline: var(--control-medium-paddingInline-condensed, 8px);
  1674. padding-block: var(--control-medium-paddingBlock, 6px);
  1675. }
  1676.  
  1677. .AppHeader-context .AppHeader-context-full li:last-child .AppHeader-context-item {
  1678. font-weight: var(--base-text-weight-semibold, 600);
  1679. }
  1680.  
  1681. .AppHeader-context .AppHeader-context-item-separator {
  1682. color: var(--fgColor-muted, var(--color-fg-muted));
  1683. white-space: nowrap;
  1684. }
  1685.  
  1686. ${SELECTORS.header.globalBar}
  1687. {
  1688. padding: 16px !important;
  1689. }
  1690. `;
  1691.  
  1692. if (elementConfig.removePageTitle) removePageTitle();
  1693.  
  1694. return true;
  1695. }
  1696.  
  1697. function insertPermanentRepositoryHeader(topRepositoryHeaderElement, repositoryHeader) {
  1698. log(DEBUG, 'insertPermanentRepositoryHeader()');
  1699.  
  1700. const clonedRepositoryHeader = repositoryHeader.cloneNode(true);
  1701.  
  1702. // This is needed to prevent pop-in via Turbo when navigating between tabs on a repo
  1703. repositoryHeader.removeAttribute('data-turbo-replace');
  1704. clonedRepositoryHeader.removeAttribute('data-turbo-replace');
  1705.  
  1706. repositoryHeader.style.setProperty('display', 'none', 'important');
  1707.  
  1708. clonedRepositoryHeader.classList.add(REPOSITORY_HEADER_SUCCESS_FLAG, REPOSITORY_HEADER_CLASS);
  1709.  
  1710. topRepositoryHeaderElement.appendChild(clonedRepositoryHeader);
  1711.  
  1712. insertNewGlobalBar(topRepositoryHeaderElement);
  1713.  
  1714. clonedRepositoryHeader.firstElementChild.classList.remove('container-xl', 'px-lg-5');
  1715.  
  1716. NEW_ELEMENTS.push(clonedRepositoryHeader);
  1717. }
  1718.  
  1719. function updateRepositoryHeaderName() {
  1720. log(DEBUG, 'updateRepositoryHeaderName()');
  1721.  
  1722. const elementConfig = CONFIG.repositoryHeader;
  1723.  
  1724. const name = document.querySelector(SELECTORS.repositoryHeader.name);
  1725.  
  1726. if (!name) {
  1727. // When not in a repo, this is expected
  1728. log(DEBUG, `Selector '${SELECTORS.repositoryHeader.name}' not found`);
  1729. return;
  1730. }
  1731.  
  1732. name.style.setProperty('display', 'none', 'important');
  1733.  
  1734. const pageTitle = HEADER.querySelector(SELECTORS.pageTitle.topDiv);
  1735.  
  1736. if (!pageTitle) {
  1737. logError(`Selector '${SELECTORS.pageTitle.topDiv}' not found`);
  1738. return;
  1739. }
  1740.  
  1741. const ownerImg = document.querySelector(SELECTORS.repositoryHeader.ownerImg);
  1742.  
  1743. if (!ownerImg) {
  1744. log(INFO, `Selector '${SELECTORS.repositoryHeader.ownerImg}' not found`);
  1745. return;
  1746. }
  1747.  
  1748. const clonedPageTitle = pageTitle.cloneNode(true);
  1749. clonedPageTitle.style.display = '';
  1750.  
  1751. const pageTitleId = `${REPOSITORY_HEADER_CLASS}_pageTitle`;
  1752. clonedPageTitle.setAttribute('id', pageTitleId);
  1753. clonedPageTitle.querySelector('img')?.remove();
  1754.  
  1755. HEADER_STYLE.textContent += `
  1756. ${createId(pageTitleId)}
  1757. {
  1758. display: initial !important;
  1759. }
  1760. `;
  1761.  
  1762. clonedPageTitle.querySelectorAll('svg').forEach(svg => svg.remove());
  1763. clonedPageTitle.querySelectorAll('a[href$="/stargazers"]').forEach(link => link.remove());
  1764.  
  1765. ownerImg.parentNode.insertBefore(clonedPageTitle, ownerImg.nextSibling);
  1766. NEW_ELEMENTS.push(clonedPageTitle);
  1767.  
  1768. if (elementConfig.avatar.remove) {
  1769. ownerImg.remove();
  1770. } else if (elementConfig.avatar.customSvg !== '') {
  1771. if (isValidURL(elementConfig.avatar.customSvg)) {
  1772. ownerImg.src = elementConfig.avatar.customSvg;
  1773. } else {
  1774. const divElement = document.createElement('div');
  1775. divElement.style.setProperty('display', 'flex');
  1776. divElement.style.setProperty('align-items', 'center');
  1777.  
  1778. divElement.innerHTML = elementConfig.avatar.customSvg;
  1779.  
  1780. ownerImg.parentNode.replaceChild(divElement, ownerImg);
  1781. }
  1782. }
  1783.  
  1784. HEADER_STYLE.textContent += cssHideElement(SELECTORS.repositoryHeader.bottomBorder);
  1785. }
  1786.  
  1787. function cloneAndLeftAlignElement(elementSelector, elementId) {
  1788. log(DEBUG, 'cloneAndLeftAlignElement()');
  1789.  
  1790. const leftAlignedDiv = HEADER.querySelector(SELECTORS.header.leftAligned);
  1791.  
  1792. if (!leftAlignedDiv) {
  1793. logError(`Selector '${SELECTORS.header.leftAligned}' not found`);
  1794. return [];
  1795. }
  1796.  
  1797. const element = HEADER.querySelector(elementSelector);
  1798.  
  1799. if (!element) {
  1800. logError(`Selector '${elementSelector}' not found`);
  1801. return [];
  1802. }
  1803.  
  1804. const elementClone = element.cloneNode(true);
  1805. const elementCloneId = `${elementId}-clone`;
  1806.  
  1807. elementClone.setAttribute('id', elementCloneId);
  1808.  
  1809. elementClone.style.setProperty('display', 'none');
  1810.  
  1811. HEADER_STYLE.textContent += cssHideElement(elementSelector);
  1812.  
  1813. HEADER_STYLE.textContent += `
  1814. ${createId(elementCloneId)}
  1815. {
  1816. display: flex !important;
  1817. }
  1818. `;
  1819.  
  1820. leftAlignedDiv.appendChild(elementClone);
  1821.  
  1822. NEW_ELEMENTS.push(elementClone);
  1823.  
  1824. return [elementCloneId, elementClone];
  1825. }
  1826.  
  1827. function insertNewGlobalBar(element) {
  1828. log(DEBUG, 'insertNewGlobalBar()');
  1829.  
  1830. const elementToInsertAfter = HEADER.querySelector(SELECTORS.header.globalBar);
  1831.  
  1832. elementToInsertAfter.parentNode.insertBefore(element, elementToInsertAfter.nextSibling);
  1833. }
  1834.  
  1835. function createId(string) {
  1836. log(TRACE, 'createId()');
  1837.  
  1838. if (string.startsWith('#')) return string;
  1839.  
  1840. if (string.startsWith('.')) {
  1841. logError(`Attempted to create an id from a class: "${string}"`);
  1842. return;
  1843. }
  1844.  
  1845. if (string.startsWith('[')) {
  1846. logError(`Attempted to create an id from an attribute selector: "${string}"`);
  1847. return;
  1848. }
  1849.  
  1850. return `#${string}`;
  1851. }
  1852.  
  1853. function cssHideElement(elementSelector) {
  1854. log(TRACE, 'cssHideElement()');
  1855.  
  1856. return `
  1857. ${elementSelector}
  1858. {
  1859. display: none !important;
  1860. }
  1861. `;
  1862. }
  1863.  
  1864. function isValidURL(string) {
  1865. log(DEBUG, 'isValidURL()');
  1866.  
  1867. const urlPattern = /^(https?:\/\/)?([\w.]+)\.([a-z]{2,6}\.?)(\/[\w.]*)*\/?$/i;
  1868. return urlPattern.test(string);
  1869. }
  1870.  
  1871. function escapeRegExp(string) {
  1872. log(DEBUG, 'escapeRegExp()');
  1873.  
  1874. return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
  1875. }
  1876.  
  1877. function compareObjects(firstObject, secondObject, firstName, secondName) {
  1878. log(DEBUG, 'compareObjects()');
  1879.  
  1880. if (typeof firstObject !== 'object' || typeof secondObject !== 'object') {
  1881. return 'Invalid input. Please provide valid objects.';
  1882. }
  1883.  
  1884. const differences = [];
  1885.  
  1886. function findKeyDifferences(obj1, obj2, path = '') {
  1887. const keys1 = Object.keys(obj1);
  1888. const keys2 = Object.keys(obj2);
  1889.  
  1890. keys1.forEach(key => {
  1891. const nestedPath = path ? `${path}.${key}` : key;
  1892. if (!keys2.includes(key)) {
  1893. differences.push(`Found "${nestedPath}" in ${firstName} but not in ${secondName}`);
  1894. } else if (typeof obj1[key] === 'object' && typeof obj2[key] === 'object') {
  1895. findKeyDifferences(obj1[key], obj2[key], nestedPath);
  1896. }
  1897. });
  1898.  
  1899. keys2.forEach(key => {
  1900. const nestedPath = path ? `${path}.${key}` : key;
  1901. if (!keys1.includes(key)) {
  1902. differences.push(`Found "${nestedPath}" in ${secondName} but not in ${firstName}`);
  1903. }
  1904. });
  1905. }
  1906.  
  1907. findKeyDifferences(firstObject, secondObject);
  1908. return differences.length > 0 ? differences : [];
  1909. }
  1910.  
  1911. // eslint-disable-next-line no-unused-vars
  1912. function checkConfigConsistency(configs) {
  1913. log(DEBUG, 'checkConfigConsistency()');
  1914.  
  1915. const lightDarkDifference = compareObjects(
  1916. configs.happyMedium.light,
  1917. configs.happyMedium.dark,
  1918. 'Happy Medium Light',
  1919. 'Happy Medium Dark',
  1920. );
  1921.  
  1922. if (lightDarkDifference.length > 0) {
  1923. logError('lightDarkDifference', lightDarkDifference);
  1924.  
  1925. return false;
  1926. }
  1927.  
  1928. const typeDifference = compareObjects(
  1929. configs.happyMedium,
  1930. configs.oldSchool,
  1931. 'Happy Medium',
  1932. 'Old School',
  1933. );
  1934.  
  1935. if (typeDifference.length > 0) {
  1936. logError('typeDifference', typeDifference);
  1937.  
  1938. return false;
  1939. }
  1940.  
  1941. return true;
  1942. }
  1943.  
  1944. function updateSelectors() {
  1945. log(DEBUG, 'updateSelectors()');
  1946.  
  1947. const toolTips = Array.from(HEADER.querySelectorAll('tool-tip'));
  1948. SELECTORS.toolTips = {
  1949. create: toolTips.find(
  1950. tooltip => tooltip.textContent.includes('Create new'),
  1951. ),
  1952. pullRequests: toolTips.find(
  1953. tooltip => tooltip.textContent.includes('Pull requests'),
  1954. ),
  1955. issues: toolTips.find(
  1956. tooltip => tooltip.textContent.includes('Issues'),
  1957. ),
  1958. notifications: toolTips.find(
  1959. tooltip => tooltip.getAttribute('data-target') === 'notification-indicator.tooltip',
  1960. ),
  1961. };
  1962. }
  1963.  
  1964. function waitForFeaturePreviewButton() {
  1965. log(VERBOSE, 'waitForFeaturePreviewButton()');
  1966.  
  1967. if (!HEADER) return;
  1968.  
  1969. const liElementId = 'custom-global-navigation-menu-item';
  1970.  
  1971. if (HEADER.querySelector(createId(liElementId))) return;
  1972.  
  1973. const featurePreviewSearch = HEADER.querySelectorAll('[data-analytics-event*="FEATURE_PREVIEW"]');
  1974.  
  1975. if (featurePreviewSearch.length === 1) {
  1976. const featurePreviewButton = featurePreviewSearch[0];
  1977. const featurePreviewLi = featurePreviewButton.parentNode;
  1978.  
  1979. const newLiElement = featurePreviewLi.cloneNode(true);
  1980. newLiElement.setAttribute('id', liElementId);
  1981. newLiElement.removeAttribute('data-targets');
  1982.  
  1983. const newButton = newLiElement.querySelector('button');
  1984. newButton.removeAttribute('id');
  1985. newButton.removeAttribute('data-analytics-event');
  1986. newButton.removeAttribute('data-show-dialog-id');
  1987. newButton.removeAttribute('data-view-component');
  1988. newButton.onclick = () => {
  1989. GMC.open();
  1990.  
  1991. if (GMC.get('on_open') === 'close sidebar') HEADER.querySelector(SELECTORS.sidebars.right.closeButton)?.click();
  1992. };
  1993.  
  1994. const textElement = newLiElement.querySelector('.ActionListItem-label');
  1995. textElement.textContent = GMC.get('menu_item_title');
  1996.  
  1997. const oldSvg = newLiElement.querySelector('svg');
  1998.  
  1999. const menuItemIcon = GMC.get('menu_item_icon');
  2000. if (menuItemIcon === 'logo') {
  2001. const newSvg = document.createElement('img');
  2002. newSvg.setAttribute('height', '16px');
  2003. newSvg.setAttribute('width', '16px');
  2004. newSvg.src = `https://raw.githubusercontent.com/blakegearin/github-custom-global-navigation/main/img/${THEME}_logo.svg`;
  2005.  
  2006. oldSvg.parentNode.replaceChild(newSvg, oldSvg);
  2007. } else {
  2008. let svgString;
  2009.  
  2010. if (menuItemIcon === 'cog') {
  2011. svgString = `
  2012. <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-gear">
  2013. <path d="M8 0a8.2 8.2 0 0 1 .701.031C9.444.095 9.99.645 10.16 1.29l.288 1.107c.018.066.079.158.212.224.231.114.454.243.668.386.123.082.233.09.299.071l1.103-.303c.644-.176 1.392.021 1.82.63.27.385.506.792.704 1.218.315.675.111 1.422-.364 1.891l-.814.806c-.049.048-.098.147-.088.294.016.257.016.515 0 .772-.01.147.038.246.088.294l.814.806c.475.469.679 1.216.364 1.891a7.977 7.977 0 0 1-.704 1.217c-.428.61-1.176.807-1.82.63l-1.102-.302c-.067-.019-.177-.011-.3.071a5.909 5.909 0 0 1-.668.386c-.133.066-.194.158-.211.224l-.29 1.106c-.168.646-.715 1.196-1.458 1.26a8.006 8.006 0 0 1-1.402 0c-.743-.064-1.289-.614-1.458-1.26l-.289-1.106c-.018-.066-.079-.158-.212-.224a5.738 5.738 0 0 1-.668-.386c-.123-.082-.233-.09-.299-.071l-1.103.303c-.644.176-1.392-.021-1.82-.63a8.12 8.12 0 0 1-.704-1.218c-.315-.675-.111-1.422.363-1.891l.815-.806c.05-.048.098-.147.088-.294a6.214 6.214 0 0 1 0-.772c.01-.147-.038-.246-.088-.294l-.815-.806C.635 6.045.431 5.298.746 4.623a7.92 7.92 0 0 1 .704-1.217c.428-.61 1.176-.807 1.82-.63l1.102.302c.067.019.177.011.3-.071.214-.143.437-.272.668-.386.133-.066.194-.158.211-.224l.29-1.106C6.009.645 6.556.095 7.299.03 7.53.01 7.764 0 8 0Zm-.571 1.525c-.036.003-.108.036-.137.146l-.289 1.105c-.147.561-.549.967-.998 1.189-.173.086-.34.183-.5.29-.417.278-.97.423-1.529.27l-1.103-.303c-.109-.03-.175.016-.195.045-.22.312-.412.644-.573.99-.014.031-.021.11.059.19l.815.806c.411.406.562.957.53 1.456a4.709 4.709 0 0 0 0 .582c.032.499-.119 1.05-.53 1.456l-.815.806c-.081.08-.073.159-.059.19.162.346.353.677.573.989.02.03.085.076.195.046l1.102-.303c.56-.153 1.113-.008 1.53.27.161.107.328.204.501.29.447.222.85.629.997 1.189l.289 1.105c.029.109.101.143.137.146a6.6 6.6 0 0 0 1.142 0c.036-.003.108-.036.137-.146l.289-1.105c.147-.561.549-.967.998-1.189.173-.086.34-.183.5-.29.417-.278.97-.423 1.529-.27l1.103.303c.109.029.175-.016.195-.045.22-.313.411-.644.573-.99.014-.031.021-.11-.059-.19l-.815-.806c-.411-.406-.562-.957-.53-1.456a4.709 4.709 0 0 0 0-.582c-.032-.499.119-1.05.53-1.456l.815-.806c.081-.08.073-.159.059-.19a6.464 6.464 0 0 0-.573-.989c-.02-.03-.085-.076-.195-.046l-1.102.303c-.56.153-1.113.008-1.53-.27a4.44 4.44 0 0 0-.501-.29c-.447-.222-.85-.629-.997-1.189l-.289-1.105c-.029-.11-.101-.143-.137-.146a6.6 6.6 0 0 0-1.142 0ZM11 8a3 3 0 1 1-6 0 3 3 0 0 1 6 0ZM9.5 8a1.5 1.5 0 1 0-3.001.001A1.5 1.5 0 0 0 9.5 8Z"></path>
  2014. </svg>
  2015. `;
  2016. } else if (menuItemIcon === 'compass') {
  2017. svgString = `
  2018. <svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 512 512">
  2019. <!--! Font Awesome Free 6.4.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2023 Fonticons, Inc. -->
  2020. <path d="M464 256A208 208 0 1 0 48 256a208 208 0 1 0 416 0zM0 256a256 256 0 1 1 512 0A256 256 0 1 1 0 256zm306.7 69.1L162.4 380.6c-19.4 7.5-38.5-11.6-31-31l55.5-144.3c3.3-8.5 9.9-15.1 18.4-18.4l144.3-55.5c19.4-7.5 38.5 11.6 31 31L325.1 306.7c-3.2 8.5-9.9 15.1-18.4 18.4zM288 256a32 32 0 1 0 -64 0 32 32 0 1 0 64 0z"/>
  2021. </svg>
  2022. `;
  2023. }
  2024.  
  2025. const parser = new DOMParser();
  2026. const svgDoc = parser.parseFromString(svgString, 'image/svg+xml');
  2027. const newSvg = svgDoc.documentElement;
  2028.  
  2029. oldSvg.parentNode.replaceChild(newSvg, oldSvg);
  2030. }
  2031.  
  2032. const parentUl = featurePreviewLi.parentNode;
  2033. const settingsLi = HEADER.querySelector('a[href="/settings/profile"]').parentNode;
  2034.  
  2035. parentUl.insertBefore(newLiElement, settingsLi.nextSibling);
  2036.  
  2037. const divider = featurePreviewLi.parentNode.querySelector('.ActionList-sectionDivider');
  2038. const newDivider = divider.cloneNode(true);
  2039.  
  2040. parentUl.insertBefore(newDivider, settingsLi.nextSibling);
  2041. } else {
  2042. setTimeout(waitForFeaturePreviewButton, 100);
  2043. }
  2044. }
  2045.  
  2046. function generateCustomConfig() {
  2047. log(DEBUG, 'generateCustomConfig()');
  2048.  
  2049. const customConfig = {
  2050. light: {},
  2051. dark: {},
  2052. };
  2053.  
  2054. function recursivelyGenerateCustomConfig(obj, customObj, themePrefix, parentKey = '') {
  2055. for (const key in obj) {
  2056. const currentKey = parentKey ? `${parentKey}.${key}` : key;
  2057. if (typeof obj[key] === 'object') {
  2058. customObj[key] = {};
  2059. recursivelyGenerateCustomConfig(obj[key], customObj[key], themePrefix, currentKey);
  2060. } else {
  2061. const gmcKey = `${themePrefix}_${currentKey.replace(/\./g, '_')}`;
  2062.  
  2063. if (gmcKey in GMC.fields) {
  2064. customObj[key] = GMC.get(gmcKey);
  2065. } else {
  2066. logError(`GMC field not found for key: ${gmcKey}`);
  2067. return;
  2068. }
  2069. }
  2070. }
  2071. }
  2072.  
  2073. recursivelyGenerateCustomConfig(configs.happyMedium.light, customConfig.light, 'light');
  2074. recursivelyGenerateCustomConfig(configs.happyMedium.dark, customConfig.dark, 'dark');
  2075.  
  2076. return customConfig;
  2077. }
  2078.  
  2079. function setTheme() {
  2080. log(DEBUG, 'setTheme()');
  2081.  
  2082. const dataColorMode = document.querySelector('html').getAttribute('data-color-mode');
  2083.  
  2084. if (dataColorMode === 'auto') {
  2085. if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
  2086. THEME = 'dark';
  2087. }
  2088. } else if (dataColorMode === 'dark') {
  2089. THEME = 'dark';
  2090. } else if (dataColorMode !== 'light') {
  2091. logError('Unknown color mode');
  2092. }
  2093.  
  2094. log(VERBOSE, `THEME: ${THEME}`);
  2095. }
  2096.  
  2097. function gmcInitialized() {
  2098. log(DEBUG, 'gmcInitialized()');
  2099.  
  2100. updateLogLevel();
  2101.  
  2102. log(QUIET, 'Running');
  2103.  
  2104. GMC.css.basic = '';
  2105.  
  2106. startObserving();
  2107. }
  2108.  
  2109. function gmcAddSavedSpan(div) {
  2110. log(DEBUG, 'gmcAddSavedSpan()');
  2111.  
  2112. const savedDiv = document.createElement('div');
  2113. savedDiv.setAttribute('id', 'gmc-saved');
  2114.  
  2115. const iconSpan = document.createElement('span');
  2116. iconSpan.style = 'margin-right: 4px;';
  2117.  
  2118. iconSpan.innerHTML = `
  2119. <svg aria-hidden="true" focusable="false" role="img" class="octicon octicon-check-circle-fill" viewBox="0 0 12 12" width="12" height="12" fill="currentColor" style="display: inline-block;user-select: none;vertical-align: text-bottom;">
  2120. <path d="M6 0a6 6 0 1 1 0 12A6 6 0 0 1 6 0Zm-.705 8.737L9.63 4.403 8.392 3.166 5.295 6.263l-1.7-1.702L2.356 5.8l2.938 2.938Z"></path>
  2121. </svg>
  2122. `;
  2123.  
  2124. const textSpan = document.createElement('span');
  2125. textSpan.innerText = 'Saved';
  2126.  
  2127. savedDiv.appendChild(iconSpan);
  2128. savedDiv.appendChild(textSpan);
  2129.  
  2130. div.insertBefore(savedDiv, div.firstChild);
  2131. }
  2132.  
  2133. function gmcAddNewIssueButton(div) {
  2134. log(DEBUG, 'gmcAddNewIssueButton()');
  2135.  
  2136. const small = document.createElement('small');
  2137. small.classList.add('left-aligned');
  2138. small.setAttribute('title', 'Submit bug or feature request');
  2139.  
  2140. const link = document.createElement('a');
  2141. link.href = 'https://github.com/blakegearin/github-custom-global-navigation/issues';
  2142. link.innerText = 'submit bug or feature request';
  2143.  
  2144. small.appendChild(link);
  2145.  
  2146. div.insertBefore(small, div.firstChild);
  2147. }
  2148.  
  2149. function gmcOpened() {
  2150. log(DEBUG, 'gmcOpened()');
  2151.  
  2152. function updateCheckboxes() {
  2153. log(DEBUG, 'updateCheckboxes()');
  2154.  
  2155. const checkboxes = document.querySelectorAll('#gmc-frame input[type="checkbox"]');
  2156.  
  2157. if (checkboxes.length > 0) {
  2158. checkboxes.forEach(checkbox => {
  2159. checkbox.classList.add('gmc-checkbox');
  2160. });
  2161. } else {
  2162. setTimeout(updateCheckboxes, 100);
  2163. }
  2164. }
  2165.  
  2166. updateCheckboxes();
  2167.  
  2168. const configVars = document.querySelectorAll('.config_var');
  2169.  
  2170. configVars.forEach(configVar => {
  2171. const label = configVar.querySelector('.field_label');
  2172. const input = configVar.querySelector('input');
  2173.  
  2174. if (label && input && input.type === 'text') label.style.lineHeight = '33px';
  2175.  
  2176. const select = configVar.querySelector('select');
  2177.  
  2178. if (label && select) label.style.lineHeight = '33px';
  2179. });
  2180.  
  2181. modifyThenObserve(() => {
  2182. document.querySelector('#gmc-frame .reset_holder').remove();
  2183.  
  2184. const buttonHolderSelector = '#gmc-frame_buttons_holder';
  2185. const parentDiv = document.querySelector(buttonHolderSelector);
  2186.  
  2187. if (!parentDiv) {
  2188. logError(`Selector ${buttonHolderSelector} not found`);
  2189. return;
  2190. }
  2191.  
  2192. gmcAddSavedSpan(parentDiv);
  2193. gmcAddNewIssueButton(parentDiv);
  2194. });
  2195.  
  2196. document.querySelector('#gmc').classList.remove('hidden');
  2197. }
  2198.  
  2199. function gmcRefreshTab() {
  2200. location.reload();
  2201. }
  2202.  
  2203. function gmcRunScript() {
  2204. applyCustomizations(true);
  2205. }
  2206.  
  2207. function updateLogLevel() {
  2208. CURRENT_LOG_LEVEL = {
  2209. 'silent': SILENT,
  2210. 'quiet': QUIET,
  2211. 'debug': DEBUG,
  2212. 'verbose': VERBOSE,
  2213. 'trace': TRACE,
  2214. }[GMC.get('log_level')];
  2215. }
  2216.  
  2217. function gmcSaved() {
  2218. log(DEBUG, 'gmcSaved()');
  2219.  
  2220. const gmcSaved = document.getElementById('gmc-saved');
  2221.  
  2222. gmcSaved.style.display = 'block';
  2223.  
  2224. setTimeout(
  2225. () => gmcSaved.style.display = 'none',
  2226. 2750,
  2227. );
  2228.  
  2229. updateLogLevel();
  2230.  
  2231. switch (GMC.get('on_save')) {
  2232. case 'refresh tab':
  2233. gmcRefreshTab();
  2234. break;
  2235. case 'refresh tab and close':
  2236. gmcRefreshTab();
  2237. GMC.close();
  2238. break;
  2239. case 'run script':
  2240. gmcRunScript();
  2241. break;
  2242. case 'run script and close':
  2243. gmcRunScript();
  2244. GMC.close();
  2245. break;
  2246. }
  2247. }
  2248.  
  2249. function gmcClosed() {
  2250. log(DEBUG, 'gmcClosed()');
  2251.  
  2252. switch (GMC.get('on_close')) {
  2253. case 'refresh tab':
  2254. gmcRefreshTab();
  2255. break;
  2256. case 'run script':
  2257. gmcRunScript();
  2258. break;
  2259. }
  2260.  
  2261. document.querySelector('#gmc').classList.add('hidden');
  2262. }
  2263.  
  2264. function gmcClearCustom() {
  2265. log(DEBUG, 'gmcClearCustom()');
  2266.  
  2267. const confirmed = confirm('Are you sure you want to clear your custom configuration? This is irreversible.');
  2268.  
  2269. if (confirmed) {
  2270. const currentType = GMC.get('type');
  2271. GMC.reset();
  2272. GMC.save();
  2273.  
  2274. GMC.set('type', currentType);
  2275. GMC.save();
  2276. }
  2277. }
  2278.  
  2279. function configsToGMC(config, path = []) {
  2280. log(DEBUG, 'configsToGMC()');
  2281.  
  2282. for (const key in config) {
  2283. if (typeof config[key] === 'object' && !Array.isArray(config[key])) {
  2284. configsToGMC(config[key], path.concat(key));
  2285. } else {
  2286. const fieldName = path.concat(key).join('_');
  2287. const fieldValue = config[key];
  2288.  
  2289. log(VERBOSE, 'fieldName', fieldName);
  2290. GMC.set(fieldName, fieldValue);
  2291. }
  2292. }
  2293. }
  2294.  
  2295. function gmcApplyCustomHappyMediumConfig() {
  2296. log(DEBUG, 'gmcApplyCustomHappyMediumConfig()');
  2297.  
  2298. const confirmed = confirm('Are you sure you want to overwrite your custom configuration with Happy Medium? This is irreversible.');
  2299.  
  2300. if (confirmed) {
  2301. configsToGMC(configs.happyMedium);
  2302. GMC.save();
  2303. }
  2304. }
  2305.  
  2306. function gmcApplyCustomOldSchoolConfig() {
  2307. log(DEBUG, 'gmcApplyCustomOldSchoolConfig()');
  2308.  
  2309. const confirmed = confirm('Are you sure you want to overwrite your custom configuration with Old School? This is irreversible.');
  2310.  
  2311. if (confirmed) {
  2312. configsToGMC(configs.oldSchool);
  2313. GMC.save();
  2314. }
  2315. }
  2316.  
  2317. function gmcBuildStyle() {
  2318. log(DEBUG, 'gmcBuildStyle()');
  2319.  
  2320. const headerIdPartials = [
  2321. 'hamburgerButton_remove_var',
  2322. 'logo_remove_var',
  2323. 'pageTitle_remove_var',
  2324. 'search_remove_var',
  2325. 'divider_remove_var',
  2326. 'create_remove_var',
  2327. 'issues_remove_var',
  2328. 'pullRequests_remove_var',
  2329. 'marketplace_add_var',
  2330. 'explore_add_var',
  2331. 'notifications_remove_var',
  2332. 'light_avatar_remove_var',
  2333. 'dark_avatar_remove_var',
  2334. 'globalBar_boxShadowColor_var',
  2335. 'localBar_backgroundColor_var',
  2336. 'sidebars_backdrop_color_var',
  2337. 'repositoryHeader_import_var',
  2338. 'flipCreateInbox_var',
  2339. 'flipIssuesPullRequests_var',
  2340. ];
  2341.  
  2342. const sectionSelectors = headerIdPartials
  2343. .map(varName => `#gmc-frame .config_var[id*='${varName}']`)
  2344. .join(',\n');
  2345.  
  2346. const gmcFrameStyle = document.createElement('style');
  2347. gmcFrameStyle.textContent += `
  2348. /* Modal */
  2349.  
  2350. #gmc
  2351. {
  2352. display: inline-flex !important;
  2353. justify-content: center !important;
  2354. align-items: center !important;
  2355. position: fixed !important;
  2356. top: 0 !important;
  2357. left: 0 !important;
  2358. width: 100vw !important;
  2359. height: 100vh !important;
  2360. z-index: 9999;
  2361. background: none !important;
  2362.  
  2363. pointer-events: none;
  2364. }
  2365.  
  2366. #gmc.hidden
  2367. {
  2368. display: none !important;
  2369. }
  2370.  
  2371. #gmc-frame
  2372. {
  2373. font-family: -apple-system,BlinkMacSystemFont,"Segoe UI","Noto Sans",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji";
  2374. text-align: left;
  2375.  
  2376. inset: initial !important;
  2377. border: none !important;
  2378. max-height: initial !important;
  2379. max-width: initial !important;
  2380. opacity: 1 !important;
  2381. position: static !important;
  2382. z-index: initial !important;
  2383.  
  2384. width: 85% !important;
  2385. height: 75% !important;
  2386. overflow-y: auto !important;
  2387.  
  2388. border: none !important;
  2389. border-radius: 0.375rem !important;
  2390.  
  2391. pointer-events: auto;
  2392. }
  2393.  
  2394. #gmc-frame_wrapper
  2395. {
  2396. display: flow-root !important;
  2397. padding: 2rem !important;
  2398. }
  2399.  
  2400. /* Sections */
  2401.  
  2402. #gmc-frame #gmc-frame_section_0
  2403. {
  2404. width: 100%;
  2405. border-radius: 6px;
  2406. display: table;
  2407. }
  2408.  
  2409. #gmc-frame #gmc-frame_section_1,
  2410. #gmc-frame #gmc-frame_section_2,
  2411. #gmc-frame #gmc-frame_section_3,
  2412. #gmc-frame #gmc-frame_section_4
  2413. {
  2414. margin-top: 2rem;
  2415. width: 49%;
  2416. box-sizing: border-box;
  2417. }
  2418.  
  2419. #gmc-frame #gmc-frame_section_1
  2420. {
  2421. border-radius: 6px;
  2422. float: left;
  2423. }
  2424.  
  2425. #gmc-frame #gmc-frame_section_2
  2426. {
  2427. border-radius: 6px;
  2428. float: right;
  2429. }
  2430.  
  2431. #gmc-frame #gmc-frame_section_3
  2432. {
  2433. width: 49%;
  2434. margin-top: 2rem;
  2435. box-sizing: border-box;
  2436. border-radius: 6px;
  2437. float: left;
  2438. }
  2439.  
  2440. #gmc-frame #gmc-frame_section_4
  2441. {
  2442. display: inline-grid;
  2443. width: 49%;
  2444. margin-top: 2rem;
  2445. box-sizing: border-box;
  2446. border-radius: 6px;
  2447. float: right
  2448. }
  2449.  
  2450. #gmc-frame #gmc-frame_section_3 .config_var:not(:last-child),
  2451. #gmc-frame #gmc-frame_section_4 .config_var:not(:last-child)
  2452. {
  2453. padding-bottom: 1rem;
  2454. }
  2455.  
  2456. /* Fields */
  2457.  
  2458. #gmc-frame .config_header
  2459. {
  2460. font-size: 2em;
  2461. font-weight: 400;
  2462. line-height: 1.25;
  2463.  
  2464. padding-bottom: 0.3em;
  2465. margin-bottom: 16px;
  2466. }
  2467.  
  2468. #gmc-frame #gmc-frame_type_var
  2469. {
  2470. display: inline-flex;
  2471. }
  2472.  
  2473. #gmc-frame .section_header
  2474. {
  2475. font-size: 1.5em;
  2476. font-weight: 600;
  2477. line-height: 1.25;
  2478.  
  2479. margin-bottom: 16px;
  2480. padding: 1rem 1.5rem;
  2481. }
  2482.  
  2483. #gmc-frame .section_desc,
  2484. #gmc-frame h3
  2485. {
  2486. background: none;
  2487. border: none;
  2488. font-size: 1.25em;
  2489.  
  2490. margin-bottom: 16px;
  2491. font-weight: 600;
  2492. line-height: 1.25;
  2493. text-align: left;
  2494. }
  2495.  
  2496. #gmc-frame .config_var
  2497. {
  2498. padding: 0rem 1.5rem;
  2499. margin-bottom: 1rem;
  2500. display: flex;
  2501. }
  2502.  
  2503. ${sectionSelectors}
  2504. {
  2505. display: flow;
  2506. padding-top: 1rem;
  2507. }
  2508.  
  2509. #gmc-frame .config_var[id*='flipCreateInbox_var'],
  2510. #gmc-frame .config_var[id*='flipIssuesPullRequests_var']
  2511. {
  2512. display: flex;
  2513. }
  2514.  
  2515. #gmc-frame .field_label
  2516. {
  2517. font-weight: 600;
  2518. margin-right: 0.5rem;
  2519. }
  2520.  
  2521. #gmc-frame .field_label,
  2522. #gmc-frame .gmc-label
  2523. {
  2524. width: 15vw;
  2525. }
  2526.  
  2527. #gmc-frame .radio_label:not(:last-child)
  2528. {
  2529. margin-right: 4rem;
  2530. }
  2531.  
  2532. #gmc-frame .radio_label
  2533. {
  2534. line-height: 17px;
  2535. }
  2536.  
  2537. #gmc-frame .gmc-label
  2538. {
  2539. display: table-caption;
  2540. line-height: 17px;
  2541. }
  2542.  
  2543. #gmc-frame input[type="radio"]
  2544. {
  2545. appearance: none;
  2546. border-style: solid;
  2547. cursor: pointer;
  2548. height: 1rem;
  2549. place-content: center;
  2550. position: relative;
  2551. width: 1rem;
  2552. border-radius: 624rem;
  2553. transition: background-color 0s ease 0s, border-color 80ms cubic-bezier(0.33, 1, 0.68, 1) 0s;
  2554. margin-right: 0.5rem;
  2555. flex: none;
  2556. }
  2557.  
  2558. #gmc-frame input[type="checkbox"]
  2559. {
  2560. appearance: none;
  2561. border-style: solid;
  2562. border-width: 1px;
  2563. cursor: pointer;
  2564. place-content: center;
  2565. position: relative;
  2566. height: 17px;
  2567. width: 17px;
  2568. border-radius: 3px;
  2569. transition: background-color 0s ease 0s, border-color 80ms cubic-bezier(0.33, 1, 0.68, 1) 0s;
  2570. }
  2571.  
  2572. #gmc-frame #gmc-frame_field_type
  2573. {
  2574. display: flex;
  2575. }
  2576.  
  2577. #gmc-frame input[type="radio"]:checked
  2578. {
  2579. border-width: 0.25rem;
  2580. }
  2581.  
  2582. #gmc-frame input[type="radio"]:checked,
  2583. #gmc-frame .gmc-checkbox:checked
  2584. {
  2585. border-color: #2f81f7;
  2586. }
  2587.  
  2588. #gmc-frame .gmc-checkbox:checked
  2589. {
  2590. background-color: #2f81f7;
  2591. }
  2592.  
  2593. #gmc-frame .gmc-checkbox:checked::before
  2594. {
  2595. visibility: visible;
  2596. transition: visibility 0s linear 0s;
  2597. }
  2598.  
  2599. #gmc-frame .gmc-checkbox::before,
  2600. #gmc-frame .gmc-checkbox:indeterminate::before
  2601. {
  2602. animation: 80ms cubic-bezier(0.65, 0, 0.35, 1) 80ms 1 normal forwards running checkmarkIn;
  2603. }
  2604.  
  2605. #gmc-frame .gmc-checkbox::before
  2606. {
  2607. width: 1rem;
  2608. height: 1rem;
  2609. visibility: hidden;
  2610. content: "";
  2611. background-color: #FFFFFF;
  2612. clip-path: inset(1rem 0 0 0);
  2613. -webkit-mask-image: url("data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTIiIGhlaWdodD0iOSIgdmlld0JveD0iMCAwIDEyIDkiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBkPSJNMTEuNzgwMyAwLjIxOTYyNUMxMS45MjEgMC4zNjA0MjcgMTIgMC41NTEzMDUgMTIgMC43NTAzMTNDMTIgMC45NDkzMjEgMTEuOTIxIDEuMTQwMTkgMTEuNzgwMyAxLjI4MUw0LjUxODYgOC41NDA0MkM0LjM3Nzc1IDguNjgxIDQuMTg2ODIgOC43NiAzLjk4Nzc0IDguNzZDMy43ODg2NyA4Ljc2IDMuNTk3NzMgOC42ODEgMy40NTY4OSA4LjU0MDQyTDAuMjAxNjIyIDUuMjg2MkMwLjA2ODkyNzcgNS4xNDM4MyAtMC4wMDMzMDkwNSA0Ljk1NTU1IDAuMDAwMTE2NDkzIDQuNzYwOThDMC4wMDM1NTIwNSA0LjU2NjQzIDAuMDgyMzg5NCA0LjM4MDgxIDAuMjIwMDMyIDQuMjQzMjFDMC4zNTc2NjUgNC4xMDU2MiAwLjU0MzM1NSA0LjAyNjgxIDAuNzM3OTcgNC4wMjMzOEMwLjkzMjU4NCA0LjAxOTk0IDEuMTIwOTMgNC4wOTIxNyAxLjI2MzM0IDQuMjI0ODJMMy45ODc3NCA2Ljk0ODM1TDEwLjcxODYgMC4yMTk2MjVDMTAuODU5NSAwLjA3ODk5MjMgMTEuMDUwNCAwIDExLjI0OTUgMEMxMS40NDg1IDAgMTEuNjM5NSAwLjA3ODk5MjMgMTEuNzgwMyAwLjIxOTYyNVoiIGZpbGw9IndoaXRlIi8+Cjwvc3ZnPgo=");
  2614. -webkit-mask-size: 75%;
  2615. -webkit-mask-repeat: no-repeat;
  2616. -webkit-mask-position: center center;
  2617. display: block;
  2618. }
  2619.  
  2620. #gmc-frame .gmc-checkbox
  2621. {
  2622. appearance: none;
  2623. border-style: solid;
  2624. border-width: 1px;
  2625. cursor: pointer;
  2626.  
  2627. height: var(--base-size-16,16px);
  2628. margin: 0.125rem 0px 0px;
  2629. place-content: center;
  2630. position: relative;
  2631. width: var(--base-size-16,16px);
  2632. border-radius: 3px;
  2633. transition: background-color 0s ease 0s, border-color 80ms cubic-bezier(0.33, 1, 0.68, 1) 0s;
  2634. }
  2635.  
  2636. #gmc-frame input
  2637. {
  2638. color: fieldtext;
  2639. letter-spacing: normal;
  2640. word-spacing: normal;
  2641. text-transform: none;
  2642. text-indent: 0px;
  2643. text-shadow: none;
  2644. display: inline-block;
  2645. text-align: start;
  2646. appearance: auto;
  2647. -webkit-rtl-ordering: logical;
  2648. }
  2649.  
  2650. #gmc-frame .gmc-checkbox:checked
  2651. {
  2652. transition: background-color 0s ease 0s, border-color 80ms cubic-bezier(0.32, 0, 0.67, 0) 0ms;
  2653. }
  2654.  
  2655. #gmc-frame input[type="text"],
  2656. #gmc-frame textarea,
  2657. #gmc-frame select
  2658. {
  2659. padding: 5px 12px;
  2660. border-radius: 6px;
  2661. }
  2662.  
  2663. #gmc-frame input[type="text"]:focus,
  2664. #gmc-frame textarea:focus,
  2665. #gmc-frame select:focus
  2666. {
  2667. border-color: #2f81f7;
  2668. outline: 1px solid #2f81f7;
  2669. }
  2670.  
  2671. #gmc-frame svg
  2672. {
  2673. height: 17px;
  2674. width: 17px;
  2675. margin-left: 0.5rem;
  2676. }
  2677.  
  2678. #gmc small
  2679. {
  2680. font-size: x-small;
  2681. font-weight: 600;
  2682. margin-left: 3px;
  2683. }
  2684.  
  2685. /* Button bar */
  2686.  
  2687. #gmc-frame #gmc-frame_buttons_holder
  2688. {
  2689. position: fixed;
  2690. width: 85%;
  2691. text-align: right;
  2692.  
  2693. left: 50%;
  2694. bottom: 2%;
  2695. transform: translate(-50%, 0%);
  2696. padding: 1rem;
  2697.  
  2698. border-radius: 0.375rem;
  2699.  
  2700. display: flex;
  2701. align-items: center;
  2702. }
  2703.  
  2704. #gmc-frame #gmc-frame_buttons_holder .left-aligned
  2705. {
  2706. order: 1;
  2707. margin-right: auto;
  2708. }
  2709.  
  2710. #gmc-frame #gmc-frame_buttons_holder > *
  2711. {
  2712. order: 2;
  2713. }
  2714.  
  2715. #gmc-frame .saveclose_buttons
  2716. {
  2717. margin-left: 0.5rem;
  2718. }
  2719.  
  2720. #gmc-frame [type=button],
  2721. #gmc-frame .saveclose_buttons
  2722. {
  2723. position: relative;
  2724. display: inline-block;
  2725. padding: 5px 16px;
  2726. font-size: 14px;
  2727. font-weight: 500;
  2728. line-height: 20px;
  2729. white-space: nowrap;
  2730. vertical-align: middle;
  2731. cursor: pointer;
  2732. -webkit-user-select: none;
  2733. user-select: none;
  2734. border: 1px solid;
  2735. border-radius: 6px;
  2736. -webkit-appearance: none;
  2737. appearance: none;
  2738.  
  2739. font-family: -apple-system,BlinkMacSystemFont,"Segoe UI","Noto Sans",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji";
  2740. }
  2741.  
  2742. @keyframes fadeOut
  2743. {
  2744. from {
  2745. opacity: 1;
  2746. }
  2747. to {
  2748. opacity: 0;
  2749. }
  2750. }
  2751.  
  2752. #gmc-saved
  2753. {
  2754. display: none;
  2755. margin-right: 10px;
  2756. animation: fadeOut 0.75s ease 2s forwards;
  2757. }
  2758. `;
  2759.  
  2760. if (THEME === 'light') {
  2761. gmcFrameStyle.textContent += `
  2762. #gmc-frame
  2763. {
  2764. background-color: #F6F8FA;
  2765. color: #1F2328;
  2766. box-shadow: 0 0 0 1px #D0D7DE, 0 16px 32px rgba(1,4,9,0.2) !important;
  2767. }
  2768.  
  2769. #gmc-frame .section_header_holder
  2770. {
  2771. background-color: #FFFFFF;
  2772. border: 1px solid #D0D7DE;
  2773. }
  2774.  
  2775. #gmc-frame_buttons_holder
  2776. {
  2777. background-color: #FFFFFF;
  2778. box-shadow: 0 0 0 1px #D0D7DE, 0 16px 32px rgba(1,4,9,0.2) !important;
  2779. }
  2780.  
  2781. #gmc-frame input[type="text"],
  2782. #gmc-frame textarea,
  2783. #gmc-frame select
  2784. {
  2785. border: 1px solid #D0D7DE;
  2786. }
  2787.  
  2788. #gmc-frame select
  2789. {
  2790. background-color: #F6F8FA;
  2791. }
  2792.  
  2793. #gmc-frame select:hover
  2794. {
  2795. background-color: #F3F4F6;
  2796. border-color: #1F232826;
  2797. }
  2798.  
  2799. #gmc-frame input[type="text"],
  2800. #gmc-frame textarea
  2801. {
  2802. background-color: #F6F8FA;
  2803. color: #1F2328;
  2804. }
  2805.  
  2806. #gmc-frame input[type="text"]:focus,
  2807. #gmc-frame textarea:focus
  2808. {
  2809. background-color: #FFFFFF;
  2810. }
  2811.  
  2812. #gmc-frame [type=button],
  2813. #gmc-frame .saveclose_buttons
  2814. {
  2815. background-color: #f6f8fa;
  2816. border-color: #1f232826;
  2817. box-shadow: 0 1px 0 rgba(31,35,40,0.04), inset 0 1px 0 rgba(255,255,255,0.25);
  2818. color: #24292f;
  2819. }
  2820.  
  2821. #gmc-frame [type=button]:hover,
  2822. #gmc-frame .saveclose_buttons:hover
  2823. {
  2824. background-color: #f3f4f6;
  2825. border-color: #1f232826;
  2826. }
  2827.  
  2828. #gmc-frame .gmc-checkbox
  2829. {
  2830. border-color: #6E7781;
  2831. }
  2832.  
  2833. #gmc-frame input[type="radio"]
  2834. {
  2835. color: #6E7781;
  2836. }
  2837.  
  2838. #gmc-frame svg
  2839. {
  2840. fill: #000000;
  2841. }
  2842.  
  2843. #gmc-frame .section_header
  2844. {
  2845. border-bottom: 1px solid #D0D7DE;
  2846. }
  2847.  
  2848. ${sectionSelectors}
  2849. {
  2850. border-top: 1px solid #D0D7DE;
  2851. }
  2852.  
  2853. #gmc-frame #gmc-frame_section_3 .config_var:not(:last-child),
  2854. #gmc-frame #gmc-frame_section_4 .config_var:not(:last-child)
  2855. {
  2856. border-bottom: 1px solid #D0D7DE;
  2857. }
  2858.  
  2859. #gmc-frame #gmc-frame_saveBtn
  2860. {
  2861. background-color: #1F883D;
  2862. border-color: rgba(31, 35, 40, 0.15);
  2863. box-shadow: rgba(31, 35, 40, 0.1) 0px 1px 0px;
  2864. color: #FFFFFF;
  2865. }
  2866.  
  2867. #gmc-frame #gmc-frame_saveBtn:hover
  2868. {
  2869. background-color: rgb(26, 127, 55);
  2870. }
  2871.  
  2872. #gmc-frame #gmc-frame_section_4
  2873. {
  2874. border: 1px solid #FF818266;
  2875. }
  2876.  
  2877. #gmc-frame #gmc-frame_section_4 input
  2878. {
  2879. background-color: #F6F8FA;
  2880. border-color: #1F232826;
  2881. box-shadow: 0 1px 0 rgba(31,35,40,0.04), inset 0 1px 0 rgba(255,255,255,0.25);
  2882. color: #CF222E;
  2883. }
  2884.  
  2885. #gmc-frame #gmc-frame_section_4 input:hover
  2886. {
  2887. background-color: #A40E26;
  2888. border-color: #1F232826;
  2889. box-shadow: 0 1px 0 rgba(31,35,40,0.04);
  2890. color: #ffffff;
  2891. }
  2892.  
  2893. #gmc-saved
  2894. {
  2895. color: #1a7f37;
  2896. }
  2897.  
  2898. #gmc-saved svg path
  2899. {
  2900. fill: #1a7f37;
  2901. }
  2902. `;
  2903. } else if (THEME === 'dark') {
  2904. gmcFrameStyle.textContent += `
  2905. #gmc-frame
  2906. {
  2907. background-color: #161B22;
  2908. color: #E6EDF3;
  2909. box-shadow: 0 0 0 1px #30363D, 0 16px 32px #010409 !important;
  2910. }
  2911.  
  2912. #gmc-frame .section_header_holder
  2913. {
  2914. background-color: #0D1117;
  2915. border: 1px solid #30363D;
  2916. }
  2917.  
  2918. #gmc-frame_buttons_holder
  2919. {
  2920. background-color: #161B22;
  2921. box-shadow: 0 0 0 1px #30363D, 0 16px 32px #010409 !important;
  2922. }
  2923.  
  2924. #gmc-frame input[type="text"],
  2925. #gmc-frame textarea,
  2926. #gmc-frame select
  2927. {
  2928. border: 1px solid #5B626C;
  2929. }
  2930.  
  2931. #gmc-frame input[type="text"],
  2932. #gmc-frame textarea
  2933. {
  2934. background-color: #010409;
  2935. color: #FFFFFF;
  2936. }
  2937.  
  2938. #gmc-frame [type=button]:hover,
  2939. #gmc-frame .saveclose_buttons:hover
  2940. {
  2941. background-color: #30363d;
  2942. border-color: #8b949e;
  2943. }
  2944.  
  2945. #gmc-frame .gmc-checkbox
  2946. {
  2947. border-color: #6E7681;
  2948. }
  2949.  
  2950. #gmc-frame input[type="radio"]
  2951. {
  2952. color: #6D7681;
  2953. }
  2954.  
  2955. #gmc-frame input[type="text"]:focus,
  2956. textarea:focus
  2957. {
  2958. background-color: #0D1117;
  2959. }
  2960.  
  2961. #gmc-frame [type=button],
  2962. #gmc-frame .saveclose_buttons
  2963. {
  2964. color: #c9d1d9;
  2965. background-color: #21262d;
  2966. border-color: #f0f6fc1a;
  2967. }
  2968.  
  2969. #gmc-frame svg
  2970. {
  2971. fill: #E6EDF3;
  2972. }
  2973.  
  2974. #gmc-frame .section_header
  2975. {
  2976. border-bottom: 1px solid #30363D;
  2977. }
  2978.  
  2979. ${sectionSelectors}
  2980. {
  2981. border-top: 1px solid #30363D;
  2982. }
  2983.  
  2984. #gmc-frame #gmc-frame_section_3 .config_var:not(:last-child),
  2985. #gmc-frame #gmc-frame_section_4 .config_var:not(:last-child)
  2986. {
  2987. padding-bottom: 1rem;
  2988. border-bottom: 1px solid #30363D;
  2989. }
  2990.  
  2991. #gmc-frame #gmc-frame_saveBtn
  2992. {
  2993. background-color: #238636;
  2994. border-color: #F0F6FC1A;
  2995. box-shadow: 0 0 transparent;
  2996. color: #FFFFFF;
  2997. }
  2998.  
  2999. #gmc-frame #gmc-frame_saveBtn:hover
  3000. {
  3001. background-color: #2EA043;
  3002. border-color: #F0F6FC1A;
  3003. }
  3004.  
  3005. #gmc-frame #gmc-frame_section_4
  3006. {
  3007. border: 1px solid #f8514966;
  3008. }
  3009.  
  3010. #gmc-frame #gmc-frame_section_4 input
  3011. {
  3012. background-color: #21262D;
  3013. border-color: #F0F6FC1A;
  3014. }
  3015.  
  3016. #gmc-frame #gmc-frame_section_4 input
  3017. {
  3018. color: #F85149;
  3019. }
  3020.  
  3021. #gmc-frame #gmc-frame_section_4 input:hover
  3022. {
  3023. background-color: #DA3633;
  3024. border-color: #F85149;
  3025. color: #FFFFFF;
  3026. }
  3027.  
  3028. #gmc-saved
  3029. {
  3030. color: #3FB950;
  3031. }
  3032.  
  3033. #gmc-saved svg path
  3034. {
  3035. fill: #3FB950;
  3036. }
  3037. `;
  3038. }
  3039.  
  3040. document.head.appendChild(gmcFrameStyle);
  3041. }
  3042.  
  3043. function gmcBuildFrame() {
  3044. log(DEBUG, 'gmcBuildFrame()');
  3045.  
  3046. const body = document.querySelector('body');
  3047. const gmcDiv = document.createElement('div');
  3048.  
  3049. gmcDiv.setAttribute('id', 'gmc');
  3050. gmcDiv.classList.add('hidden');
  3051.  
  3052. body.appendChild(gmcDiv);
  3053.  
  3054. const gmcFrameDiv = document.createElement('div');
  3055. gmcFrameDiv.setAttribute('id', 'gmc-frame');
  3056.  
  3057. gmcDiv.appendChild(gmcFrameDiv);
  3058.  
  3059. gmcBuildStyle();
  3060.  
  3061. return gmcFrameDiv;
  3062. }
  3063.  
  3064. function applyCustomizations(refresh = false) {
  3065. log(DEBUG, 'applyCustomizations()');
  3066.  
  3067. log(DEBUG, 'refresh', refresh);
  3068.  
  3069. HEADER = document.querySelector(SELECTORS.header.self);
  3070.  
  3071. if (!HEADER) return 'continue';
  3072.  
  3073. const featurePreviewButton = document.querySelector(SELECTORS.avatar.button);
  3074.  
  3075. if (!featurePreviewButton) {
  3076. logError(`Selector ${SELECTORS.avatar.button} not found`);
  3077. return 'break';
  3078. }
  3079.  
  3080. featurePreviewButton.addEventListener('click', waitForFeaturePreviewButton);
  3081.  
  3082. CONFIG_NAME = {
  3083. 'Off': 'off',
  3084. 'Happy Medium': 'happyMedium',
  3085. 'Old School': 'oldSchool',
  3086. 'Custom': 'custom',
  3087. }[GMC.get('type')];
  3088.  
  3089. if (CONFIG_NAME === 'off') return 'break';
  3090.  
  3091. if (CONFIG_NAME === 'custom') configs.custom = generateCustomConfig();
  3092.  
  3093. CONFIG = configs[CONFIG_NAME][THEME];
  3094.  
  3095. log(VERBOSE, 'CONFIG', CONFIG);
  3096.  
  3097. const headerSuccessFlag = 'customizedHeader';
  3098.  
  3099. const foundHeaderSuccessFlag = document.getElementById(headerSuccessFlag);
  3100. log(DEBUG, 'foundHeaderSuccessFlag', foundHeaderSuccessFlag);
  3101.  
  3102. const configurationApplied = HEADER.classList.contains(CONFIG_NAME);
  3103.  
  3104. if (!configurationApplied && (foundHeaderSuccessFlag === null || refresh)) {
  3105. updateSelectors();
  3106.  
  3107. if (refresh) {
  3108. modifyThenObserve(() => {
  3109. document.querySelector(createId(SELECTORS.header.style))?.remove();
  3110. HEADER_STYLE.textContent = '';
  3111.  
  3112. HEADER.classList.remove(OLD_CONFIG_NAME);
  3113. NEW_ELEMENTS.forEach((element) => element.remove());
  3114. });
  3115. }
  3116.  
  3117. if (CONFIG_NAME === 'oldSchool') {
  3118. HEADER_STYLE.textContent += `
  3119. @media (max-width: 767.98px)
  3120. {
  3121. action-menu
  3122. {
  3123. display: none !important;
  3124. }
  3125. }
  3126. `;
  3127. }
  3128.  
  3129. HEADER_UPDATES_COUNT++;
  3130. updateHeader();
  3131.  
  3132. HEADER.setAttribute('id', headerSuccessFlag);
  3133. HEADER.classList.add(CONFIG_NAME);
  3134.  
  3135. OLD_CONFIG_NAME = CONFIG_NAME;
  3136.  
  3137. log(QUIET, 'Complete');
  3138.  
  3139. return 'break';
  3140. } else {
  3141. if (CONFIG.avatar.dropdownIcon) insertAvatarDropdown();
  3142. if (CONFIG.avatar.canCloseSidebar) updateAvatarButton();
  3143.  
  3144. if (CONFIG.repositoryHeader.import) {
  3145. // When starting in a repository tab like Issues, the proper repository header
  3146. // (including Unwatch, Star, and Fork) is not present per GitHub's design.
  3147. // If page title is removed, the page will be missing any location context in the header.
  3148. // To improve this experience, a temporary repository header is created with the
  3149. // page title or breadcrumbs.
  3150. // The proper repository header replaces the temporary one when navigating to the Code tab.
  3151. if (
  3152. !document.querySelector(SELECTORS.repositoryHeader.id)?.hidden &&
  3153. (
  3154. document.querySelector(createId(TEMP_REPOSITORY_HEADER_FLAG)) ||
  3155. !document.querySelector(`.${REPOSITORY_HEADER_SUCCESS_FLAG}`)
  3156. )
  3157. ) {
  3158. const updated = importRepositoryHeader();
  3159.  
  3160. if (updated) {
  3161. HEADER_UPDATES_COUNT++;
  3162. log(QUIET, 'Repository header updated');
  3163. } else {
  3164. IDLE_MUTATION_COUNT++;
  3165. }
  3166.  
  3167. return 'break';
  3168. }
  3169. }
  3170. }
  3171.  
  3172. if (CONFIG.avatar.dropdownIcon) insertAvatarDropdown();
  3173. }
  3174.  
  3175. function startObserving() {
  3176. log(DEBUG, 'startObserving()');
  3177.  
  3178. OBSERVER.observe(
  3179. document.body,
  3180. {
  3181. childList: true,
  3182. subtree: true,
  3183. },
  3184. );
  3185. }
  3186.  
  3187. function modifyThenObserve(callback) {
  3188. log(DEBUG, 'modifyThenObserve()');
  3189. OBSERVER.disconnect();
  3190.  
  3191. callback();
  3192.  
  3193. startObserving();
  3194. }
  3195.  
  3196. function observeAndModify(mutationsList) {
  3197. log(VERBOSE, 'observeAndModify()');
  3198.  
  3199. if (IDLE_MUTATION_COUNT > MAX_IDLE_MUTATIONS) {
  3200. // This is a failsafe to prevent infinite loops
  3201. logError('MAX_IDLE_MUTATIONS exceeded');
  3202. OBSERVER.disconnect();
  3203.  
  3204. return;
  3205. } else if (HEADER_UPDATES_COUNT >= MAX_HEADER_UPDATES) {
  3206. // This is a failsafe to prevent infinite loops
  3207. logError('MAX_HEADER_UPDATES exceeded');
  3208. OBSERVER.disconnect();
  3209.  
  3210. return;
  3211. }
  3212.  
  3213. for (const mutation of mutationsList) {
  3214. // Use header id to determine if updates have already been applied
  3215. if (mutation.type !== 'childList') return;
  3216.  
  3217. log(TRACE, 'mutation', mutation);
  3218.  
  3219. const outcome = applyCustomizations();
  3220.  
  3221. log(DEBUG, 'outcome', outcome);
  3222.  
  3223. if (outcome === 'continue') continue;
  3224. if (outcome === 'break') break;
  3225. }
  3226. }
  3227.  
  3228. const UNICODE_NON_BREAKING_SPACE = '\u00A0';
  3229. const REPOSITORY_HEADER_SUCCESS_FLAG = 'permCustomizedRepositoryHeader';
  3230. const TEMP_REPOSITORY_HEADER_FLAG = 'tempCustomizedRepositoryHeader';
  3231. const REPOSITORY_HEADER_CLASS = 'customizedRepositoryHeader';
  3232. const MAX_IDLE_MUTATIONS = 1000;
  3233. const MAX_HEADER_UPDATES = 100;
  3234.  
  3235. let CONFIG;
  3236. let CONFIG_NAME;
  3237. let OLD_CONFIG_NAME;
  3238. let HEADER;
  3239.  
  3240. let HEADER_STYLE = document.createElement('style');
  3241. let THEME = 'light';
  3242. let NEW_ELEMENTS = [];
  3243. let LEFT_SIDEBAR_PRELOADED = false;
  3244. let RIGHT_SIDEBAR_PRELOADED = false;
  3245. let IDLE_MUTATION_COUNT = 0;
  3246. let HEADER_UPDATES_COUNT = 0;
  3247. let SELECTORS = {
  3248. header: {
  3249. self: 'header.AppHeader',
  3250. actionsDiv: '.AppHeader-actions',
  3251. globalBar: '.AppHeader-globalBar',
  3252. localBar: {
  3253. topDiv: '.AppHeader-localBar',
  3254. underlineNavActions: '.UnderlineNav-actions',
  3255. },
  3256. leftAligned: '.AppHeader-globalBar-start',
  3257. rightAligned: '.AppHeader-globalBar-end',
  3258. style: 'customHeaderStyle',
  3259. },
  3260. logo: {
  3261. topDiv: '.AppHeader-globalBar-start .AppHeader-logo',
  3262. svg: '.AppHeader-logo svg',
  3263. },
  3264. hamburgerButton: '.AppHeader-globalBar-start deferred-side-panel',
  3265. pageTitle: {
  3266. id: 'custom-page-title',
  3267. topDiv: '.AppHeader-context',
  3268. links: '.AppHeader-context a',
  3269. separator: '.AppHeader-context-item-separator',
  3270. },
  3271. search: {
  3272. id: 'search-div',
  3273. topDiv: '.AppHeader-search',
  3274. input: '.search-input',
  3275. button: '[data-target="qbsearch-input.inputButton"]',
  3276. magnifyingGlassIcon: '.AppHeader-search-control label',
  3277. commandPalette: '#AppHeader-commandPalette-button',
  3278. placeholderSpan: '#qb-input-query',
  3279. placeholderDiv: '.AppHeader-search-control .overflow-hidden',
  3280. modal: '[data-target="qbsearch-input.queryBuilderContainer"]',
  3281. },
  3282. create: {
  3283. id: 'create-div',
  3284. topDiv: 'action-menu',
  3285. button: '#global-create-menu-button',
  3286. overlay: '#global-create-menu-overlay',
  3287. plusIcon: '#global-create-menu-button .Button-visual.Button-leadingVisual',
  3288. dropdownIcon: '#global-create-menu-button .Button-label',
  3289. textContent: 'create-text-content-span',
  3290. },
  3291. issues: {
  3292. id: 'issues',
  3293. textContent: 'issues-text-content-span',
  3294. },
  3295. pullRequests: {
  3296. id: 'pullRequests',
  3297. link: '.AppHeader-globalBar-end .AppHeader-actions a[href="/pulls"]',
  3298. textContent: 'pullRequests-text-content-span',
  3299. },
  3300. marketplace: {
  3301. id: 'marketplace',
  3302. link: '.AppHeader-globalBar-end .AppHeader-actions a[href="/marketplace"]',
  3303. textContent: 'marketplace-text-content-span',
  3304. },
  3305. explore: {
  3306. id: 'explore',
  3307. link: '.AppHeader-globalBar-end .AppHeader-actions a[href="/explore"]',
  3308. textContent: 'explore-text-content-span',
  3309. },
  3310. notifications: {
  3311. id: 'custom-notifications',
  3312. indicator: 'notification-indicator',
  3313. dot: '.AppHeader-button.AppHeader-button--hasIndicator::before',
  3314. textContent: 'textContent-text-content-spa',
  3315. },
  3316. avatar: {
  3317. topDiv: '.AppHeader-user',
  3318. button: '.AppHeader-user button',
  3319. img: '.AppHeader-user button img.avatar',
  3320. svg: 'avatar-dropdown',
  3321. },
  3322. repositoryHeader: {
  3323. id: '#repository-container-header',
  3324. ownerImg: `.${REPOSITORY_HEADER_CLASS} img`,
  3325. name: `.${REPOSITORY_HEADER_CLASS} strong`,
  3326. links: `.${REPOSITORY_HEADER_CLASS} nav[role="navigation"] a`,
  3327. details: '#repository-details-container',
  3328. bottomBorder: `.${REPOSITORY_HEADER_CLASS} .border-bottom.mx-xl-5`,
  3329. },
  3330. sidebars: {
  3331. backdrop: 'dialog.Overlay.SidePanel::backdrop',
  3332. left: {
  3333. modalDialog: '.Overlay--placement-left',
  3334. },
  3335. right: {
  3336. modalDialog: '.AppHeader-user .Overlay--placement-right',
  3337. backdrop: '.AppHeader-user .Overlay--placement-right ::backdrop',
  3338. closeButton: '.AppHeader-user .Overlay--placement-right .Overlay-closeButton.close-button',
  3339. navParentDiv: '.AppHeader-user .Overlay--placement-right div.Overlay-body > div',
  3340. nav: '.AppHeader-user .Overlay--placement-right nav',
  3341. },
  3342. },
  3343. };
  3344.  
  3345. HEADER_STYLE.setAttribute('id', SELECTORS.header.style);
  3346.  
  3347. setTheme();
  3348.  
  3349. const oldSchoolColor = '#F0F6FC';
  3350. const oldSchoolHoverColor = '#FFFFFFB3';
  3351. const oldSchoolHoverBackgroundColor = 'transparent';
  3352. let configs = {
  3353. happyMedium: {
  3354. light: {
  3355. backgroundColor: '',
  3356. hamburgerButton: {
  3357. remove: false,
  3358. },
  3359. logo: {
  3360. remove: false,
  3361. color: '',
  3362. customSvg: '',
  3363. },
  3364. pageTitle: {
  3365. remove: false,
  3366. color: '',
  3367. hover: {
  3368. backgroundColor: '',
  3369. color: '',
  3370. },
  3371. },
  3372. search: {
  3373. remove: false,
  3374. backgroundColor: '',
  3375. borderColor: '',
  3376. boxShadow: '',
  3377. alignLeft: false,
  3378. width: 'max',
  3379. margin: {
  3380. left: '',
  3381. right: '',
  3382. },
  3383. magnifyingGlassIcon: {
  3384. remove: false,
  3385. },
  3386. placeholder: {
  3387. text: '',
  3388. color: '',
  3389. },
  3390. rightButton: 'command palette',
  3391. modal: {
  3392. width: '',
  3393. },
  3394. },
  3395. divider: {
  3396. remove: true,
  3397. },
  3398. flipCreateInbox: false,
  3399. create: {
  3400. remove: false,
  3401. border: true,
  3402. tooltip: false,
  3403. boxShadow: '',
  3404. hoverBackgroundColor: '',
  3405. plusIcon: {
  3406. remove: false,
  3407. color: '',
  3408. marginRight: '0.25rem',
  3409. hover: {
  3410. color: '',
  3411. },
  3412. },
  3413. text: {
  3414. content: 'Create',
  3415. color: '',
  3416. },
  3417. dropdownIcon: {
  3418. remove: false,
  3419. color: '',
  3420. hover: {
  3421. color: '',
  3422. },
  3423. },
  3424. },
  3425. flipIssuesPullRequests: true,
  3426. issues: {
  3427. remove: false,
  3428. border: true,
  3429. tooltip: false,
  3430. alignLeft: false,
  3431. boxShadow: '',
  3432. icon: {
  3433. remove: false,
  3434. color: '',
  3435. },
  3436. text: {
  3437. content: 'Issues',
  3438. color: '',
  3439. },
  3440. hover: {
  3441. backgroundColor: '',
  3442. color: '',
  3443. },
  3444. },
  3445. pullRequests: {
  3446. remove: false,
  3447. border: true,
  3448. tooltip: false,
  3449. alignLeft: false,
  3450. boxShadow: '',
  3451. icon: {
  3452. remove: false,
  3453. color: '',
  3454. },
  3455. text: {
  3456. content: 'Pull requests',
  3457. color: '',
  3458. },
  3459. hover: {
  3460. backgroundColor: '',
  3461. color: '',
  3462. },
  3463. },
  3464. marketplace: {
  3465. add: false,
  3466. border: false,
  3467. alignLeft: false,
  3468. boxShadow: '',
  3469. icon: {
  3470. remove: false,
  3471. color: '',
  3472. },
  3473. text: {
  3474. content: 'Marketplace',
  3475. color: '',
  3476. },
  3477. hover: {
  3478. backgroundColor: '',
  3479. color: '',
  3480. },
  3481. },
  3482. explore: {
  3483. add: false,
  3484. border: false,
  3485. alignLeft: false,
  3486. boxShadow: '',
  3487. icon: {
  3488. remove: false,
  3489. color: '',
  3490. },
  3491. text: {
  3492. content: 'Explore',
  3493. color: '',
  3494. },
  3495. hover: {
  3496. backgroundColor: '',
  3497. color: '',
  3498. },
  3499. },
  3500. notifications: {
  3501. remove: false,
  3502. border: true,
  3503. tooltip: false,
  3504. boxShadow: '',
  3505. hoverBackgroundColor: '',
  3506. icon: {
  3507. symbol: 'bell', // Accepts 'inbox', 'bell', or ''
  3508. color: '',
  3509. hover: {
  3510. color: '',
  3511. },
  3512. },
  3513. text: {
  3514. content: 'Inbox',
  3515. color: '',
  3516. },
  3517. dot: {
  3518. remove: false,
  3519. boxShadowColor: '',
  3520. color: '',
  3521. displayOverIcon: true,
  3522. },
  3523. },
  3524. avatar: {
  3525. remove: false,
  3526. size: '',
  3527. dropdownIcon: false,
  3528. canCloseSidebar: true,
  3529. },
  3530. globalBar: {
  3531. boxShadowColor: '',
  3532. leftAligned: {
  3533. gap: '',
  3534. },
  3535. rightAligned: {
  3536. gap: '',
  3537. },
  3538. },
  3539. localBar: {
  3540. backgroundColor: '#F6F8FA',
  3541. alignCenter: false,
  3542. boxShadow: {
  3543. consistentColor: true,
  3544. },
  3545. links: {
  3546. color: '',
  3547. },
  3548. },
  3549. sidebars: {
  3550. backdrop: {
  3551. color: 'transparent',
  3552. },
  3553. left: {
  3554. preload: true,
  3555. },
  3556. right: {
  3557. preload: true,
  3558. floatUnderneath: false,
  3559. width: '',
  3560. maxHeight: '',
  3561. },
  3562. },
  3563. repositoryHeader: {
  3564. import: true,
  3565. alignCenter: false,
  3566. removePageTitle: true,
  3567. backgroundColor: '#F6F8FA',
  3568. avatar: {
  3569. remove: false,
  3570. customSvg: '',
  3571. },
  3572. link: {
  3573. color: '',
  3574. hover: {
  3575. backgroundColor: 'transparent',
  3576. color: 'var(--color-accent-fg)',
  3577. textDecoration: 'underline',
  3578. },
  3579. },
  3580. },
  3581. },
  3582. dark: {
  3583. backgroundColor: '',
  3584. hamburgerButton: {
  3585. remove: false,
  3586. },
  3587. logo: {
  3588. remove: false,
  3589. color: '',
  3590. customSvg: '',
  3591. },
  3592. pageTitle: {
  3593. remove: false,
  3594. color: '',
  3595. hover: {
  3596. backgroundColor: '',
  3597. color: '',
  3598. },
  3599. },
  3600. search: {
  3601. remove: false,
  3602. backgroundColor: '',
  3603. borderColor: '',
  3604. boxShadow: '',
  3605. alignLeft: false,
  3606. width: 'max',
  3607. margin: {
  3608. left: '',
  3609. right: '',
  3610. },
  3611. magnifyingGlassIcon: {
  3612. remove: false,
  3613. },
  3614. placeholder: {
  3615. text: '',
  3616. color: '',
  3617. },
  3618. rightButton: 'command palette',
  3619. modal: {
  3620. width: '',
  3621. },
  3622. },
  3623. divider: {
  3624. remove: true,
  3625. },
  3626. flipCreateInbox: false,
  3627. create: {
  3628. remove: false,
  3629. border: true,
  3630. tooltip: false,
  3631. boxShadow: '',
  3632. hoverBackgroundColor: '',
  3633. plusIcon: {
  3634. remove: false,
  3635. color: '',
  3636. marginRight: '0.25rem',
  3637. hover: {
  3638. color: '',
  3639. },
  3640. },
  3641. text: {
  3642. content: 'Create',
  3643. color: '',
  3644. },
  3645. dropdownIcon: {
  3646. remove: false,
  3647. color: '',
  3648. hover: {
  3649. color: '',
  3650. },
  3651. },
  3652. },
  3653. flipIssuesPullRequests: true,
  3654. issues: {
  3655. remove: false,
  3656. border: true,
  3657. tooltip: false,
  3658. alignLeft: false,
  3659. boxShadow: '',
  3660. icon: {
  3661. remove: false,
  3662. color: '',
  3663. },
  3664. text: {
  3665. content: 'Issues',
  3666. color: '',
  3667. },
  3668. hover: {
  3669. backgroundColor: '',
  3670. color: '',
  3671. },
  3672. },
  3673. pullRequests: {
  3674. remove: false,
  3675. border: true,
  3676. tooltip: false,
  3677. alignLeft: false,
  3678. boxShadow: '',
  3679. icon: {
  3680. remove: false,
  3681. color: '',
  3682. },
  3683. text: {
  3684. content: 'Pull requests',
  3685. color: '',
  3686. },
  3687. hover: {
  3688. backgroundColor: '',
  3689. color: '',
  3690. },
  3691. },
  3692. marketplace: {
  3693. add: false,
  3694. border: false,
  3695. alignLeft: false,
  3696. boxShadow: '',
  3697. icon: {
  3698. remove: false,
  3699. color: '',
  3700. },
  3701. text: {
  3702. content: 'Marketplace',
  3703. color: '',
  3704. },
  3705. hover: {
  3706. backgroundColor: '',
  3707. color: '',
  3708. },
  3709. },
  3710. explore: {
  3711. add: false,
  3712. border: false,
  3713. alignLeft: false,
  3714. boxShadow: '',
  3715. icon: {
  3716. remove: false,
  3717. color: '',
  3718. },
  3719. text: {
  3720. content: 'Explore',
  3721. color: '',
  3722. },
  3723. hover: {
  3724. backgroundColor: '',
  3725. color: '',
  3726. },
  3727. },
  3728. notifications: {
  3729. remove: false,
  3730. border: true,
  3731. tooltip: false,
  3732. boxShadow: '',
  3733. hoverBackgroundColor: '',
  3734. icon: {
  3735. symbol: 'bell', // Accepts 'inbox', 'bell', or ''
  3736. color: '',
  3737. hover: {
  3738. color: '',
  3739. },
  3740. },
  3741. text: {
  3742. content: 'Inbox',
  3743. color: '',
  3744. },
  3745. dot: {
  3746. remove: false,
  3747. boxShadowColor: '',
  3748. color: '',
  3749. displayOverIcon: true,
  3750. },
  3751. },
  3752. avatar: {
  3753. remove: false,
  3754. size: '',
  3755. dropdownIcon: false,
  3756. canCloseSidebar: true,
  3757. },
  3758. globalBar: {
  3759. boxShadowColor: '',
  3760. leftAligned: {
  3761. gap: '',
  3762. },
  3763. rightAligned: {
  3764. gap: '',
  3765. },
  3766. },
  3767. localBar: {
  3768. backgroundColor: '#02040A',
  3769. alignCenter: false,
  3770. boxShadow: {
  3771. consistentColor: true,
  3772. },
  3773. links: {
  3774. color: '',
  3775. },
  3776. },
  3777. sidebars: {
  3778. backdrop: {
  3779. color: 'transparent',
  3780. },
  3781. left: {
  3782. preload: true,
  3783. },
  3784. right: {
  3785. preload: true,
  3786. floatUnderneath: false,
  3787. width: '',
  3788. maxHeight: '',
  3789. },
  3790. },
  3791. repositoryHeader: {
  3792. import: true,
  3793. alignCenter: false,
  3794. removePageTitle: true,
  3795. backgroundColor: '#02040A',
  3796. avatar: {
  3797. remove: false,
  3798. customSvg: '',
  3799. },
  3800. link: {
  3801. color: '#6AAFF9',
  3802. hover: {
  3803. backgroundColor: 'transparent',
  3804. color: 'var(--color-accent-fg)',
  3805. textDecoration: 'underline',
  3806. },
  3807. },
  3808. },
  3809. },
  3810. },
  3811. oldSchool: {
  3812. light: {
  3813. backgroundColor: '#161C20',
  3814. hamburgerButton: {
  3815. remove: true,
  3816. },
  3817. logo: {
  3818. remove: false,
  3819. color: '#e6edf3',
  3820. customSvg: '',
  3821. },
  3822. pageTitle: {
  3823. remove: true,
  3824. color: oldSchoolColor,
  3825. hover: {
  3826. backgroundColor: oldSchoolHoverBackgroundColor,
  3827. color: oldSchoolHoverColor,
  3828. },
  3829. },
  3830. search: {
  3831. remove: false,
  3832. backgroundColor: '#494D54',
  3833. borderColor: '#30363d',
  3834. boxShadow: 'none',
  3835. alignLeft: true,
  3836. width: 'calc(var(--feed-sidebar) - 67px)',
  3837. margin: {
  3838. left: '',
  3839. right: '',
  3840. },
  3841. magnifyingGlassIcon: {
  3842. remove: true,
  3843. },
  3844. placeholder: {
  3845. text: 'Search or jump to...',
  3846. color: '#B3B3B5',
  3847. },
  3848. rightButton: 'slash key',
  3849. modal: {
  3850. width: '450px',
  3851. },
  3852. },
  3853. divider: {
  3854. remove: true,
  3855. },
  3856. flipCreateInbox: true,
  3857. create: {
  3858. remove: false,
  3859. border: false,
  3860. tooltip: false,
  3861. boxShadow: 'none',
  3862. hoverBackgroundColor: oldSchoolHoverBackgroundColor,
  3863. plusIcon: {
  3864. remove: false,
  3865. color: oldSchoolColor,
  3866. marginRight: '0px',
  3867. hover: {
  3868. color: oldSchoolHoverColor,
  3869. },
  3870. },
  3871. text: {
  3872. content: '',
  3873. color: '',
  3874. },
  3875. dropdownIcon: {
  3876. remove: false,
  3877. color: oldSchoolColor,
  3878. hover: {
  3879. color: oldSchoolHoverColor,
  3880. },
  3881. },
  3882. },
  3883. flipIssuesPullRequests: true,
  3884. issues: {
  3885. remove: false,
  3886. border: false,
  3887. tooltip: false,
  3888. alignLeft: true,
  3889. boxShadow: 'none',
  3890. icon: {
  3891. remove: true,
  3892. color: '',
  3893. },
  3894. text: {
  3895. content: 'Issues',
  3896. color: oldSchoolColor,
  3897. },
  3898. hover: {
  3899. backgroundColor: oldSchoolHoverBackgroundColor,
  3900. color: oldSchoolHoverColor,
  3901. },
  3902. },
  3903. pullRequests: {
  3904. remove: false,
  3905. border: false,
  3906. tooltip: false,
  3907. alignLeft: true,
  3908. boxShadow: 'none',
  3909. icon: {
  3910. remove: true,
  3911. color: '',
  3912. },
  3913. text: {
  3914. content: 'Pull requests',
  3915. color: oldSchoolColor,
  3916. },
  3917. hover: {
  3918. backgroundColor: oldSchoolHoverBackgroundColor,
  3919. color: oldSchoolHoverColor,
  3920. },
  3921. },
  3922. marketplace: {
  3923. add: true,
  3924. border: false,
  3925. tooltip: false,
  3926. alignLeft: true,
  3927. boxShadow: 'none',
  3928. icon: {
  3929. remove: true,
  3930. color: '',
  3931. },
  3932. text: {
  3933. content: 'Marketplace',
  3934. color: oldSchoolColor,
  3935. },
  3936. hover: {
  3937. backgroundColor: oldSchoolHoverBackgroundColor,
  3938. color: oldSchoolHoverColor,
  3939. },
  3940. },
  3941. explore: {
  3942. add: true,
  3943. border: false,
  3944. tooltip: false,
  3945. alignLeft: true,
  3946. boxShadow: 'none',
  3947. icon: {
  3948. remove: true,
  3949. color: '',
  3950. },
  3951. text: {
  3952. content: 'Explore',
  3953. color: oldSchoolColor,
  3954. },
  3955. hover: {
  3956. backgroundColor: oldSchoolHoverBackgroundColor,
  3957. color: oldSchoolHoverColor,
  3958. },
  3959. },
  3960. notifications: {
  3961. remove: false,
  3962. border: false,
  3963. tooltip: false,
  3964. boxShadow: 'none',
  3965. hoverBackgroundColor: oldSchoolHoverBackgroundColor,
  3966. icon: {
  3967. symbol: 'bell',
  3968. color: oldSchoolColor,
  3969. hover: {
  3970. color: oldSchoolHoverColor,
  3971. },
  3972. },
  3973. text: {
  3974. content: '',
  3975. color: '',
  3976. },
  3977. dot: {
  3978. remove: false,
  3979. boxShadowColor: '#161C20',
  3980. color: '#2f81f7',
  3981. displayOverIcon: true,
  3982. },
  3983. },
  3984. avatar: {
  3985. remove: false,
  3986. size: '24px',
  3987. dropdownIcon: true,
  3988. canCloseSidebar: true,
  3989. },
  3990. globalBar: {
  3991. boxShadowColor: '#21262D',
  3992. leftAligned: {
  3993. gap: '0.75rem',
  3994. },
  3995. rightAligned: {
  3996. gap: '2px',
  3997. },
  3998. },
  3999. localBar: {
  4000. backgroundColor: '#FAFBFD',
  4001. alignCenter: true,
  4002. boxShadow: {
  4003. consistentColor: true,
  4004. },
  4005. links: {
  4006. color: '',
  4007. },
  4008. },
  4009. sidebars: {
  4010. backdrop: {
  4011. color: oldSchoolHoverBackgroundColor,
  4012. },
  4013. left: {
  4014. preload: true,
  4015. },
  4016. right: {
  4017. preload: true,
  4018. floatUnderneath: true,
  4019. width: '',
  4020. maxHeight: '50vh',
  4021. },
  4022. },
  4023. repositoryHeader: {
  4024. import: true,
  4025. alignCenter: true,
  4026. removePageTitle: true,
  4027. backgroundColor: '#FAFBFD',
  4028. avatar: {
  4029. remove: false,
  4030. customSvg: '<svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-repo mr-1 color-fg-muted"><path d="M2 2.5A2.5 2.5 0 0 1 4.5 0h8.75a.75.75 0 0 1 .75.75v12.5a.75.75 0 0 1-.75.75h-2.5a.75.75 0 0 1 0-1.5h1.75v-2h-8a1 1 0 0 0-.714 1.7.75.75 0 1 1-1.072 1.05A2.495 2.495 0 0 1 2 11.5Zm10.5-1h-8a1 1 0 0 0-1 1v6.708A2.486 2.486 0 0 1 4.5 9h8ZM5 12.25a.25.25 0 0 1 .25-.25h3.5a.25.25 0 0 1 .25.25v3.25a.25.25 0 0 1-.4.2l-1.45-1.087a.249.249 0 0 0-.3 0L5.4 15.7a.25.25 0 0 1-.4-.2Z"></path></svg>',
  4031. },
  4032. link: {
  4033. color: '#2F81F7',
  4034. hover: {
  4035. backgroundColor: 'transparent',
  4036. color: '#0969da',
  4037. textDecoration: 'underline',
  4038. },
  4039. },
  4040. },
  4041. },
  4042. dark: {
  4043. backgroundColor: '#161C20',
  4044. hamburgerButton: {
  4045. remove: true,
  4046. },
  4047. logo: {
  4048. remove: false,
  4049. color: '#e6edf3',
  4050. customSvg: '',
  4051. },
  4052. pageTitle: {
  4053. remove: true,
  4054. color: oldSchoolColor,
  4055. hover: {
  4056. backgroundColor: oldSchoolHoverBackgroundColor,
  4057. color: oldSchoolHoverColor,
  4058. },
  4059. },
  4060. search: {
  4061. remove: false,
  4062. backgroundColor: '#0E1217',
  4063. borderColor: '#30363d',
  4064. boxShadow: 'none',
  4065. alignLeft: true,
  4066. width: 'calc(var(--feed-sidebar) - 67px)',
  4067. margin: {
  4068. left: '',
  4069. right: '',
  4070. },
  4071. magnifyingGlassIcon: {
  4072. remove: true,
  4073. },
  4074. placeholder: {
  4075. text: 'Search or jump to...',
  4076. color: '#B3B3B5',
  4077. },
  4078. rightButton: 'slash key',
  4079. modal: {
  4080. width: '450px',
  4081. },
  4082. },
  4083. divider: {
  4084. remove: true,
  4085. },
  4086. flipCreateInbox: true,
  4087. create: {
  4088. remove: false,
  4089. border: false,
  4090. tooltip: false,
  4091. boxShadow: 'none',
  4092. hoverBackgroundColor: oldSchoolHoverBackgroundColor,
  4093. plusIcon: {
  4094. remove: false,
  4095. color: oldSchoolColor,
  4096. marginRight: '0px',
  4097. hover: {
  4098. color: oldSchoolHoverColor,
  4099. },
  4100. },
  4101. text: {
  4102. content: '',
  4103. color: '',
  4104. },
  4105. dropdownIcon: {
  4106. remove: false,
  4107. color: oldSchoolColor,
  4108. hover: {
  4109. color: oldSchoolHoverColor,
  4110. },
  4111. },
  4112. },
  4113. flipIssuesPullRequests: true,
  4114. issues: {
  4115. remove: false,
  4116. border: false,
  4117. tooltip: false,
  4118. alignLeft: true,
  4119. boxShadow: 'none',
  4120. icon: {
  4121. remove: true,
  4122. color: '',
  4123. },
  4124. text: {
  4125. content: 'Issues',
  4126. color: oldSchoolColor,
  4127. },
  4128. hover: {
  4129. backgroundColor: oldSchoolHoverBackgroundColor,
  4130. color: oldSchoolHoverColor,
  4131. },
  4132. },
  4133. pullRequests: {
  4134. remove: false,
  4135. border: false,
  4136. tooltip: false,
  4137. alignLeft: true,
  4138. boxShadow: 'none',
  4139. icon: {
  4140. remove: true,
  4141. color: '',
  4142. },
  4143. text: {
  4144. content: 'Pull requests',
  4145. color: oldSchoolColor,
  4146. },
  4147. hover: {
  4148. backgroundColor: oldSchoolHoverBackgroundColor,
  4149. color: oldSchoolHoverColor,
  4150. },
  4151. },
  4152. marketplace: {
  4153. add: true,
  4154. border: false,
  4155. alignLeft: true,
  4156. boxShadow: 'none',
  4157. icon: {
  4158. remove: true,
  4159. color: '',
  4160. },
  4161. text: {
  4162. content: 'Marketplace',
  4163. color: oldSchoolColor,
  4164. },
  4165. hover: {
  4166. backgroundColor: oldSchoolHoverBackgroundColor,
  4167. color: oldSchoolHoverColor,
  4168. },
  4169. },
  4170. explore: {
  4171. add: true,
  4172. border: false,
  4173. alignLeft: true,
  4174. boxShadow: 'none',
  4175. icon: {
  4176. remove: true,
  4177. color: '',
  4178. },
  4179. text: {
  4180. content: 'Explore',
  4181. color: oldSchoolColor,
  4182. },
  4183. hover: {
  4184. backgroundColor: oldSchoolHoverBackgroundColor,
  4185. color: oldSchoolHoverColor,
  4186. },
  4187. },
  4188. notifications: {
  4189. remove: false,
  4190. border: false,
  4191. tooltip: false,
  4192. boxShadow: 'none',
  4193. hoverBackgroundColor: oldSchoolHoverBackgroundColor,
  4194. icon: {
  4195. symbol: 'bell',
  4196. color: oldSchoolColor,
  4197. hover: {
  4198. color: oldSchoolHoverColor,
  4199. },
  4200. },
  4201. text: {
  4202. content: '',
  4203. color: '',
  4204. },
  4205. dot: {
  4206. remove: false,
  4207. boxShadowColor: '#161C20',
  4208. color: '#2f81f7',
  4209. displayOverIcon: true,
  4210. },
  4211. },
  4212. avatar: {
  4213. remove: false,
  4214. size: '24px',
  4215. dropdownIcon: true,
  4216. canCloseSidebar: true,
  4217. },
  4218. globalBar: {
  4219. boxShadowColor: '#21262D',
  4220. leftAligned: {
  4221. gap: '0.75rem',
  4222. },
  4223. rightAligned: {
  4224. gap: '2px',
  4225. },
  4226. },
  4227. localBar: {
  4228. backgroundColor: '#0D1117',
  4229. alignCenter: true,
  4230. boxShadow: {
  4231. consistentColor: true,
  4232. },
  4233. links: {
  4234. color: '#e6edf3',
  4235. },
  4236. },
  4237. sidebars: {
  4238. backdrop: {
  4239. color: oldSchoolHoverBackgroundColor,
  4240. },
  4241. left: {
  4242. preload: true,
  4243. },
  4244. right: {
  4245. preload: true,
  4246. floatUnderneath: true,
  4247. width: '',
  4248. maxHeight: '50vh',
  4249. },
  4250. },
  4251. repositoryHeader: {
  4252. import: true,
  4253. alignCenter: true,
  4254. removePageTitle: true,
  4255. backgroundColor: '#0D1116',
  4256. avatar: {
  4257. remove: false,
  4258. customSvg: '<svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-repo mr-1 color-fg-muted"><path d="M2 2.5A2.5 2.5 0 0 1 4.5 0h8.75a.75.75 0 0 1 .75.75v12.5a.75.75 0 0 1-.75.75h-2.5a.75.75 0 0 1 0-1.5h1.75v-2h-8a1 1 0 0 0-.714 1.7.75.75 0 1 1-1.072 1.05A2.495 2.495 0 0 1 2 11.5Zm10.5-1h-8a1 1 0 0 0-1 1v6.708A2.486 2.486 0 0 1 4.5 9h8ZM5 12.25a.25.25 0 0 1 .25-.25h3.5a.25.25 0 0 1 .25.25v3.25a.25.25 0 0 1-.4.2l-1.45-1.087a.249.249 0 0 0-.3 0L5.4 15.7a.25.25 0 0 1-.4-.2Z"></path></svg>',
  4259. },
  4260. link: {
  4261. color: '#58A6FF',
  4262. hover: {
  4263. backgroundColor: 'transparent',
  4264. color: '#2F81F7',
  4265. textDecoration: 'underline',
  4266. },
  4267. },
  4268. },
  4269. },
  4270. },
  4271. };
  4272.  
  4273. // For testing purposes
  4274. // if (!checkConfigConsistency(configs)) return;
  4275.  
  4276. let OBSERVER = new MutationObserver(observeAndModify);
  4277.  
  4278. let GMC = new GM_config({
  4279. id: 'gmc-frame',
  4280. title: `
  4281. Custom Global Navigation
  4282. <small>
  4283. <a
  4284. href="https://github.com/blakegearin/github-custom-global-navigation"
  4285. target="_blank"
  4286. >
  4287. source
  4288. </a>
  4289. </small>
  4290. `,
  4291. events: {
  4292. init: gmcInitialized,
  4293. open: gmcOpened,
  4294. save: gmcSaved,
  4295. close: gmcClosed,
  4296. },
  4297. frame: gmcBuildFrame(),
  4298. fields: {
  4299. type: {
  4300. section: [
  4301. `
  4302. Configuration Type
  4303. <small>
  4304. <a
  4305. href="https://github.com/blakegearin/github-custom-global-navigation#configurations"
  4306. target="_blank"
  4307. >
  4308. learn more
  4309. </a>
  4310. </small>
  4311. `,
  4312. ],
  4313. type: 'radio',
  4314. options: [
  4315. 'Off',
  4316. 'Happy Medium',
  4317. 'Old School',
  4318. 'Custom',
  4319. ],
  4320. default: 'Old School',
  4321. },
  4322. light_backgroundColor: {
  4323. label: 'Background color',
  4324. section: [
  4325. 'Custom Light',
  4326. ],
  4327. type: 'text',
  4328. default: '',
  4329. },
  4330. light_hamburgerButton_remove: {
  4331. label: '<h3>Hamburger button</h3><div class="gmc-label">Remove</div>',
  4332. type: 'checkbox',
  4333. default: false,
  4334. },
  4335. light_logo_remove: {
  4336. label: '<h3>Logo</h3><div class="gmc-label">Remove</div>',
  4337. type: 'checkbox',
  4338. default: false,
  4339. },
  4340. light_logo_color: {
  4341. label: 'Color',
  4342. type: 'text',
  4343. default: '',
  4344. },
  4345. light_logo_customSvg: {
  4346. label: 'Custom SVG (URL or text)',
  4347. type: 'textarea',
  4348. default: '',
  4349. },
  4350. light_pageTitle_remove: {
  4351. label: '<h3>Page title</h3><div class="gmc-label">Remove</div>',
  4352. type: 'checkbox',
  4353. default: false,
  4354. },
  4355. light_pageTitle_color: {
  4356. label: 'Color',
  4357. type: 'text',
  4358. default: '',
  4359. },
  4360. light_pageTitle_hover_backgroundColor: {
  4361. label: 'Hover background color',
  4362. type: 'text',
  4363. default: '',
  4364. },
  4365. light_pageTitle_hover_color: {
  4366. label: 'Hover color',
  4367. type: 'text',
  4368. default: '',
  4369. },
  4370. light_search_remove: {
  4371. label: '<h3>Search</h3><div class="gmc-label">Remove</div>',
  4372. type: 'checkbox',
  4373. default: false,
  4374. },
  4375. light_search_backgroundColor: {
  4376. label: 'Background color',
  4377. type: 'text',
  4378. default: '',
  4379. },
  4380. light_search_borderColor: {
  4381. label: 'Border color',
  4382. type: 'text',
  4383. default: '',
  4384. },
  4385. light_search_boxShadow: {
  4386. label: 'Box shadow',
  4387. type: 'text',
  4388. default: '',
  4389. },
  4390. light_search_alignLeft: {
  4391. label: 'Left aligned',
  4392. type: 'checkbox',
  4393. default: false,
  4394. },
  4395. light_search_width: {
  4396. label: 'Width',
  4397. type: 'text',
  4398. default: '',
  4399. },
  4400. light_search_margin_left: {
  4401. label: 'Margin left',
  4402. type: 'text',
  4403. default: '',
  4404. },
  4405. light_search_margin_right: {
  4406. label: 'Margin right',
  4407. type: 'text',
  4408. default: '',
  4409. },
  4410. light_search_magnifyingGlassIcon_remove: {
  4411. label: 'Magnifying glass icon remove',
  4412. type: 'checkbox',
  4413. default: false,
  4414. },
  4415. light_search_placeholder_text: {
  4416. label: 'Placeholder text',
  4417. type: 'text',
  4418. default: '',
  4419. },
  4420. light_search_placeholder_color: {
  4421. label: 'Placeholder color',
  4422. type: 'text',
  4423. default: '',
  4424. },
  4425. light_search_rightButton: {
  4426. label: 'Right button',
  4427. type: 'select',
  4428. options: [
  4429. 'none',
  4430. 'command palette',
  4431. 'slash key',
  4432. ],
  4433. default: 'command palette',
  4434. },
  4435. light_search_modal_width: {
  4436. label: 'Modal width',
  4437. type: 'text',
  4438. default: '',
  4439. },
  4440. light_divider_remove: {
  4441. label: '<h3>Divider</h3><div class="gmc-label">Remove</div>',
  4442. type: 'checkbox',
  4443. default: false,
  4444. },
  4445. light_flipCreateInbox: {
  4446. label: 'Flip the order of Create and Notifications',
  4447. type: 'checkbox',
  4448. default: false,
  4449. },
  4450. light_create_remove: {
  4451. label: '<h3>Create button</h3><div class="gmc-label">Remove</div>',
  4452. type: 'checkbox',
  4453. default: false,
  4454. },
  4455. light_create_border: {
  4456. label: 'Border',
  4457. type: 'checkbox',
  4458. default: true,
  4459. },
  4460. light_create_tooltip: {
  4461. label: 'Tooltip',
  4462. type: 'checkbox',
  4463. default: true,
  4464. },
  4465. light_create_boxShadow: {
  4466. label: 'Box shadow',
  4467. type: 'text',
  4468. default: '',
  4469. },
  4470. light_create_hoverBackgroundColor: {
  4471. label: 'Hover background color',
  4472. type: 'text',
  4473. default: '',
  4474. },
  4475. light_create_plusIcon_remove: {
  4476. label: 'Plus icon remove',
  4477. type: 'checkbox',
  4478. default: false,
  4479. },
  4480. light_create_plusIcon_color: {
  4481. label: 'Plus icon color',
  4482. type: 'text',
  4483. default: '',
  4484. },
  4485. light_create_plusIcon_marginRight: {
  4486. label: 'Plus icon margin right',
  4487. type: 'text',
  4488. default: '',
  4489. },
  4490. light_create_plusIcon_hover_color: {
  4491. label: 'Plus icon hover color',
  4492. type: 'text',
  4493. default: '',
  4494. },
  4495. light_create_text_content: {
  4496. label: 'Text content',
  4497. type: 'text',
  4498. default: '',
  4499. },
  4500. light_create_text_color: {
  4501. label: 'Text color',
  4502. type: 'text',
  4503. default: '',
  4504. },
  4505. light_create_dropdownIcon_remove: {
  4506. label: 'Dropdown icon remove',
  4507. type: 'checkbox',
  4508. default: false,
  4509. },
  4510. light_create_dropdownIcon_color: {
  4511. label: 'Dropdown icon color',
  4512. type: 'text',
  4513. default: '',
  4514. },
  4515. light_create_dropdownIcon_hover_color: {
  4516. label: 'Dropdown icon hover color',
  4517. type: 'text',
  4518. default: '',
  4519. },
  4520. light_flipIssuesPullRequests: {
  4521. label: 'Flip the order of Issues and Pull requests',
  4522. type: 'checkbox',
  4523. default: false,
  4524. },
  4525. light_issues_remove: {
  4526. label: '<h3>Issues button</h3><div class="gmc-label">Remove</div>',
  4527. type: 'checkbox',
  4528. default: false,
  4529. },
  4530. light_issues_border: {
  4531. label: 'Border',
  4532. type: 'checkbox',
  4533. default: true,
  4534. },
  4535. light_issues_tooltip: {
  4536. label: 'Tooltip',
  4537. type: 'checkbox',
  4538. default: true,
  4539. },
  4540. light_issues_alignLeft: {
  4541. label: 'Align left',
  4542. type: 'checkbox',
  4543. default: false,
  4544. },
  4545. light_issues_boxShadow: {
  4546. label: 'Box shadow',
  4547. type: 'text',
  4548. default: '',
  4549. },
  4550. light_issues_icon_remove: {
  4551. label: 'Icon remove',
  4552. type: 'checkbox',
  4553. default: false,
  4554. },
  4555. light_issues_icon_color: {
  4556. label: 'Icon color',
  4557. type: 'text',
  4558. default: '',
  4559. },
  4560. light_issues_text_content: {
  4561. label: 'Text content',
  4562. type: 'text',
  4563. default: '',
  4564. },
  4565. light_issues_text_color: {
  4566. label: 'Text color',
  4567. type: 'text',
  4568. default: '',
  4569. },
  4570. light_issues_hover_backgroundColor: {
  4571. label: 'Hover background color',
  4572. type: 'text',
  4573. default: '',
  4574. },
  4575. light_issues_hover_color: {
  4576. label: 'Hover color',
  4577. type: 'text',
  4578. default: '',
  4579. },
  4580. light_pullRequests_remove: {
  4581. label: '<h3>Pull requests button</h3><div class="gmc-label">Remove</div>',
  4582. type: 'checkbox',
  4583. default: false,
  4584. },
  4585. light_pullRequests_border: {
  4586. label: 'Border',
  4587. type: 'checkbox',
  4588. default: true,
  4589. },
  4590. light_pullRequests_tooltip: {
  4591. label: 'Tooltip',
  4592. type: 'checkbox',
  4593. default: true,
  4594. },
  4595. light_pullRequests_alignLeft: {
  4596. label: 'Align left',
  4597. type: 'checkbox',
  4598. default: false,
  4599. },
  4600. light_pullRequests_boxShadow: {
  4601. label: 'Box shadow',
  4602. type: 'text',
  4603. default: '',
  4604. },
  4605. light_pullRequests_icon_remove: {
  4606. label: 'Icon remove',
  4607. type: 'checkbox',
  4608. default: false,
  4609. },
  4610. light_pullRequests_icon_color: {
  4611. label: 'Icon color',
  4612. type: 'text',
  4613. default: '',
  4614. },
  4615. light_pullRequests_text_content: {
  4616. label: 'Text content',
  4617. type: 'text',
  4618. default: '',
  4619. },
  4620. light_pullRequests_text_color: {
  4621. label: 'Text color',
  4622. type: 'text',
  4623. default: '',
  4624. },
  4625. light_pullRequests_hover_backgroundColor: {
  4626. label: 'Hover background color',
  4627. type: 'text',
  4628. default: '',
  4629. },
  4630. light_pullRequests_hover_color: {
  4631. label: 'Hover color',
  4632. type: 'text',
  4633. default: '',
  4634. },
  4635. light_marketplace_add: {
  4636. label: '<h3>Marketplace</h3><div class="gmc-label">Add</div>',
  4637. type: 'checkbox',
  4638. default: false,
  4639. },
  4640. light_marketplace_border: {
  4641. label: 'Border',
  4642. type: 'checkbox',
  4643. default: true,
  4644. },
  4645. light_marketplace_alignLeft: {
  4646. label: 'Align left',
  4647. type: 'checkbox',
  4648. default: false,
  4649. },
  4650. light_marketplace_boxShadow: {
  4651. label: 'Box shadow',
  4652. type: 'text',
  4653. default: '',
  4654. },
  4655. light_marketplace_icon_remove: {
  4656. label: 'Icon remove',
  4657. type: 'checkbox',
  4658. default: false,
  4659. },
  4660. light_marketplace_icon_color: {
  4661. label: 'Icon color',
  4662. type: 'text',
  4663. default: '',
  4664. },
  4665. light_marketplace_text_content: {
  4666. label: 'Text content',
  4667. type: 'text',
  4668. default: '',
  4669. },
  4670. light_marketplace_text_color: {
  4671. label: 'Text color',
  4672. type: 'text',
  4673. default: '',
  4674. },
  4675. light_marketplace_hover_backgroundColor: {
  4676. label: 'Hover background color',
  4677. type: 'text',
  4678. default: '',
  4679. },
  4680. light_marketplace_hover_color: {
  4681. label: 'Hover color',
  4682. type: 'text',
  4683. default: '',
  4684. },
  4685. light_explore_add: {
  4686. label: '<h3>Explore</h3><div class="gmc-label">Add</div>',
  4687. type: 'checkbox',
  4688. default: false,
  4689. },
  4690. light_explore_border: {
  4691. label: 'Border',
  4692. type: 'checkbox',
  4693. default: true,
  4694. },
  4695. light_explore_alignLeft: {
  4696. label: 'Align left',
  4697. type: 'checkbox',
  4698. default: false,
  4699. },
  4700. light_explore_boxShadow: {
  4701. label: 'Box shadow',
  4702. type: 'text',
  4703. default: '',
  4704. },
  4705. light_explore_icon_remove: {
  4706. label: 'Icon remove',
  4707. type: 'checkbox',
  4708. default: false,
  4709. },
  4710. light_explore_icon_color: {
  4711. label: 'Icon color',
  4712. type: 'text',
  4713. default: '',
  4714. },
  4715. light_explore_text_content: {
  4716. label: 'Text content',
  4717. type: 'text',
  4718. default: '',
  4719. },
  4720. light_explore_text_color: {
  4721. label: 'Text color',
  4722. type: 'text',
  4723. default: '',
  4724. },
  4725. light_explore_hover_backgroundColor: {
  4726. label: 'Hover background color',
  4727. type: 'text',
  4728. default: '',
  4729. },
  4730. light_explore_hover_color: {
  4731. label: 'Hover color',
  4732. type: 'text',
  4733. default: '',
  4734. },
  4735. light_notifications_remove: {
  4736. label: '<h3>Notifications button</h3><div class="gmc-label">Remove</div>',
  4737. type: 'checkbox',
  4738. default: false,
  4739. },
  4740. light_notifications_border: {
  4741. label: 'Border',
  4742. type: 'checkbox',
  4743. default: true,
  4744. },
  4745. light_notifications_tooltip: {
  4746. label: 'Tooltip',
  4747. type: 'checkbox',
  4748. default: true,
  4749. },
  4750. light_notifications_boxShadow: {
  4751. label: 'Box shadow',
  4752. type: 'text',
  4753. default: '',
  4754. },
  4755. light_notifications_hoverBackgroundColor: {
  4756. label: 'Hover background color',
  4757. type: 'text',
  4758. default: '',
  4759. },
  4760. light_notifications_icon_symbol: {
  4761. label: 'Icon symbol',
  4762. type: 'select',
  4763. options: [
  4764. 'none',
  4765. 'inbox',
  4766. 'bell',
  4767. ],
  4768. default: 'inbox',
  4769. },
  4770. light_notifications_icon_color: {
  4771. label: 'Icon color',
  4772. type: 'text',
  4773. default: '',
  4774. },
  4775. light_notifications_icon_hover_color: {
  4776. label: 'Icon hover color',
  4777. type: 'text',
  4778. default: '',
  4779. },
  4780. light_notifications_text_content: {
  4781. label: 'Text content',
  4782. type: 'text',
  4783. default: '',
  4784. },
  4785. light_notifications_text_color: {
  4786. label: 'Text color',
  4787. type: 'text',
  4788. default: '',
  4789. },
  4790. light_notifications_dot_remove: {
  4791. label: 'Dot remove',
  4792. type: 'checkbox',
  4793. default: false,
  4794. },
  4795. light_notifications_dot_boxShadowColor: {
  4796. label: 'Dot hover color',
  4797. type: 'text',
  4798. default: '',
  4799. },
  4800. light_notifications_dot_color: {
  4801. label: 'Dot color',
  4802. type: 'text',
  4803. default: '',
  4804. },
  4805. light_notifications_dot_displayOverIcon: {
  4806. label: 'Dot display over icon',
  4807. type: 'checkbox',
  4808. default: false,
  4809. },
  4810. light_avatar_remove: {
  4811. label: '<h3>Avatar</h3><div class="gmc-label">Remove</div>',
  4812. type: 'checkbox',
  4813. default: false,
  4814. },
  4815. light_avatar_size: {
  4816. label: 'Size',
  4817. type: 'text',
  4818. default: '',
  4819. },
  4820. light_avatar_dropdownIcon: {
  4821. label: 'Dropdown icon',
  4822. type: 'checkbox',
  4823. default: false,
  4824. },
  4825. light_avatar_canCloseSidebar: {
  4826. label: 'Can close sidebar',
  4827. type: 'checkbox',
  4828. default: false,
  4829. },
  4830. light_globalBar_boxShadowColor: {
  4831. label: '<h3>Global bar</h3><div class="gmc-label">Box shadow color</div>',
  4832. type: 'text',
  4833. default: '',
  4834. },
  4835. light_globalBar_leftAligned_gap: {
  4836. label: 'Left aligned gap',
  4837. type: 'text',
  4838. default: '',
  4839. },
  4840. light_globalBar_rightAligned_gap: {
  4841. label: 'Right aligned gap',
  4842. type: 'text',
  4843. default: '',
  4844. },
  4845. light_localBar_backgroundColor: {
  4846. label: '<h3>Local bar</h3><div class="gmc-label">Background color</div>',
  4847. type: 'text',
  4848. default: '',
  4849. },
  4850. light_localBar_alignCenter: {
  4851. label: 'Align center',
  4852. type: 'checkbox',
  4853. default: false,
  4854. },
  4855. light_localBar_boxShadow_consistentColor: {
  4856. label: 'Box shadow consistent color',
  4857. type: 'checkbox',
  4858. default: false,
  4859. },
  4860. light_localBar_links_color: {
  4861. label: 'Links color',
  4862. type: 'text',
  4863. default: '',
  4864. },
  4865. light_sidebars_backdrop_color: {
  4866. label: '<h3>Sidebars</h3><div class="gmc-label">Backdrop color</div>',
  4867. type: 'text',
  4868. default: '',
  4869. },
  4870. light_sidebars_left_preload: {
  4871. label: 'Left preload',
  4872. type: 'checkbox',
  4873. default: false,
  4874. },
  4875. light_sidebars_right_preload: {
  4876. label: 'Right preload',
  4877. type: 'checkbox',
  4878. default: false,
  4879. },
  4880. light_sidebars_right_floatUnderneath: {
  4881. label: 'Right float underneath',
  4882. type: 'checkbox',
  4883. default: false,
  4884. },
  4885. light_sidebars_right_width: {
  4886. label: 'Right width',
  4887. type: 'text',
  4888. default: '',
  4889. },
  4890. light_sidebars_right_maxHeight: {
  4891. label: 'Right max height',
  4892. type: 'text',
  4893. default: '',
  4894. },
  4895. light_repositoryHeader_import: {
  4896. label: '<h3>Repository header</h3><div class="gmc-label">Import</div>',
  4897. type: 'checkbox',
  4898. default: false,
  4899. },
  4900. light_repositoryHeader_alignCenter: {
  4901. label: 'Align center',
  4902. type: 'checkbox',
  4903. default: false,
  4904. },
  4905. light_repositoryHeader_removePageTitle: {
  4906. label: 'Remove page title',
  4907. type: 'checkbox',
  4908. default: false,
  4909. },
  4910. light_repositoryHeader_backgroundColor: {
  4911. label: 'Background color',
  4912. type: 'text',
  4913. default: '',
  4914. },
  4915. light_repositoryHeader_avatar_remove: {
  4916. label: 'Avatar remove',
  4917. type: 'checkbox',
  4918. default: false,
  4919. },
  4920. light_repositoryHeader_avatar_customSvg: {
  4921. label: 'Custom SVG (URL or text)',
  4922. type: 'textarea',
  4923. default: '',
  4924. },
  4925. light_repositoryHeader_link_color: {
  4926. label: 'Link color',
  4927. type: 'text',
  4928. default: '',
  4929. },
  4930. light_repositoryHeader_link_hover_backgroundColor: {
  4931. label: 'Link hover background color',
  4932. type: 'text',
  4933. default: '',
  4934. },
  4935. light_repositoryHeader_link_hover_color: {
  4936. label: 'Link hover color',
  4937. type: 'text',
  4938. default: '',
  4939. },
  4940. light_repositoryHeader_link_hover_textDecoration: {
  4941. label: 'Link hover text decoration',
  4942. type: 'text',
  4943. default: '',
  4944. },
  4945. dark_backgroundColor: {
  4946. label: 'Background color',
  4947. section: [
  4948. 'Custom Dark',
  4949. ],
  4950. type: 'text',
  4951. default: '',
  4952. },
  4953. dark_hamburgerButton_remove: {
  4954. label: '<h3>Hamburger button</h3><div class="gmc-label">Remove</div>',
  4955. type: 'checkbox',
  4956. default: false,
  4957. },
  4958. dark_logo_remove: {
  4959. label: '<h3>Logo</h3><div class="gmc-label">Remove</div>',
  4960. type: 'checkbox',
  4961. default: false,
  4962. },
  4963. dark_logo_color: {
  4964. label: 'Color',
  4965. type: 'text',
  4966. default: '',
  4967. },
  4968. dark_logo_customSvg: {
  4969. label: 'Custom SVG (URL or text)',
  4970. type: 'textarea',
  4971. default: '',
  4972. },
  4973. dark_pageTitle_remove: {
  4974. label: '<h3>Page title</h3><div class="gmc-label">Remove</div>',
  4975. type: 'checkbox',
  4976. default: false,
  4977. },
  4978. dark_pageTitle_color: {
  4979. label: 'Color',
  4980. type: 'text',
  4981. default: '',
  4982. },
  4983. dark_pageTitle_hover_backgroundColor: {
  4984. label: 'Hover background color',
  4985. type: 'text',
  4986. default: '',
  4987. },
  4988. dark_pageTitle_hover_color: {
  4989. label: 'Hover color',
  4990. type: 'text',
  4991. default: '',
  4992. },
  4993. dark_search_remove: {
  4994. label: '<h3>Search</h3><div class="gmc-label">Remove</div>',
  4995. type: 'checkbox',
  4996. default: false,
  4997. },
  4998. dark_search_backgroundColor: {
  4999. label: 'Background color',
  5000. type: 'text',
  5001. default: '',
  5002. },
  5003. dark_search_borderColor: {
  5004. label: 'Border color',
  5005. type: 'text',
  5006. default: '',
  5007. },
  5008. dark_search_boxShadow: {
  5009. label: 'Box shadow',
  5010. type: 'text',
  5011. default: '',
  5012. },
  5013. dark_search_alignLeft: {
  5014. label: 'Left aligned',
  5015. type: 'checkbox',
  5016. default: false,
  5017. },
  5018. dark_search_width: {
  5019. label: 'Width',
  5020. type: 'text',
  5021. default: '',
  5022. },
  5023. dark_search_margin_left: {
  5024. label: 'Margin left',
  5025. type: 'text',
  5026. default: '',
  5027. },
  5028. dark_search_margin_right: {
  5029. label: 'Margin right',
  5030. type: 'text',
  5031. default: '',
  5032. },
  5033. dark_search_magnifyingGlassIcon_remove: {
  5034. label: 'Magnifying glass icon remove',
  5035. type: 'checkbox',
  5036. default: false,
  5037. },
  5038. dark_search_placeholder_text: {
  5039. label: 'Placeholder text',
  5040. type: 'text',
  5041. default: '',
  5042. },
  5043. dark_search_placeholder_color: {
  5044. label: 'Placeholder color',
  5045. type: 'text',
  5046. default: '',
  5047. },
  5048. dark_search_rightButton: {
  5049. label: 'Right button',
  5050. type: 'select',
  5051. options: [
  5052. 'none',
  5053. 'command palette',
  5054. 'slash key',
  5055. ],
  5056. default: 'command palette',
  5057. },
  5058. dark_search_modal_width: {
  5059. label: 'Modal width',
  5060. type: 'text',
  5061. default: '',
  5062. },
  5063. dark_divider_remove: {
  5064. label: '<h3>Divider</h3><div class="gmc-label">Remove</div>',
  5065. type: 'checkbox',
  5066. default: false,
  5067. },
  5068. dark_flipCreateInbox: {
  5069. label: 'Flip the order of Create and Notifications',
  5070. type: 'checkbox',
  5071. default: false,
  5072. },
  5073. dark_create_remove: {
  5074. label: '<h3>Create button</h3><div class="gmc-label">Remove</div>',
  5075. type: 'checkbox',
  5076. default: false,
  5077. },
  5078. dark_create_border: {
  5079. label: 'Border',
  5080. type: 'checkbox',
  5081. default: true,
  5082. },
  5083. dark_create_tooltip: {
  5084. label: 'Tooltip',
  5085. type: 'checkbox',
  5086. default: true,
  5087. },
  5088. dark_create_boxShadow: {
  5089. label: 'Box shadow',
  5090. type: 'text',
  5091. default: '',
  5092. },
  5093. dark_create_hoverBackgroundColor: {
  5094. label: 'Hover background color',
  5095. type: 'text',
  5096. default: '',
  5097. },
  5098. dark_create_plusIcon_remove: {
  5099. label: 'Plus icon remove',
  5100. type: 'checkbox',
  5101. default: false,
  5102. },
  5103. dark_create_plusIcon_color: {
  5104. label: 'Plus icon color',
  5105. type: 'text',
  5106. default: '',
  5107. },
  5108. dark_create_plusIcon_marginRight: {
  5109. label: 'Plus icon margin right',
  5110. type: 'text',
  5111. default: '',
  5112. },
  5113. dark_create_plusIcon_hover_color: {
  5114. label: 'Plus icon hover color',
  5115. type: 'text',
  5116. default: '',
  5117. },
  5118. dark_create_text_content: {
  5119. label: 'Text content',
  5120. type: 'text',
  5121. default: '',
  5122. },
  5123. dark_create_text_color: {
  5124. label: 'Text color',
  5125. type: 'text',
  5126. default: '',
  5127. },
  5128. dark_create_dropdownIcon_remove: {
  5129. label: 'Dropdown icon remove',
  5130. type: 'checkbox',
  5131. default: false,
  5132. },
  5133. dark_create_dropdownIcon_color: {
  5134. label: 'Dropdown icon color',
  5135. type: 'text',
  5136. default: '',
  5137. },
  5138. dark_create_dropdownIcon_hover_color: {
  5139. label: 'Dropdown icon hover color',
  5140. type: 'text',
  5141. default: '',
  5142. },
  5143. dark_flipIssuesPullRequests: {
  5144. label: 'Flip the order of Issues and Pull requests',
  5145. type: 'checkbox',
  5146. default: false,
  5147. },
  5148. dark_issues_remove: {
  5149. label: '<h3>Issues button</h3><div class="gmc-label">Remove</div>',
  5150. type: 'checkbox',
  5151. default: false,
  5152. },
  5153. dark_issues_border: {
  5154. label: 'Border',
  5155. type: 'checkbox',
  5156. default: true,
  5157. },
  5158. dark_issues_tooltip: {
  5159. label: 'Tooltip',
  5160. type: 'checkbox',
  5161. default: true,
  5162. },
  5163. dark_issues_boxShadow: {
  5164. label: 'Box shadow',
  5165. type: 'text',
  5166. default: '',
  5167. },
  5168. dark_issues_alignLeft: {
  5169. label: 'Align left',
  5170. type: 'checkbox',
  5171. default: false,
  5172. },
  5173. dark_issues_icon_remove: {
  5174. label: 'Icon remove',
  5175. type: 'checkbox',
  5176. default: false,
  5177. },
  5178. dark_issues_icon_color: {
  5179. label: 'Icon color',
  5180. type: 'text',
  5181. default: '',
  5182. },
  5183. dark_issues_text_content: {
  5184. label: 'Text content',
  5185. type: 'text',
  5186. default: '',
  5187. },
  5188. dark_issues_text_color: {
  5189. label: 'Text color',
  5190. type: 'text',
  5191. default: '',
  5192. },
  5193. dark_issues_hover_backgroundColor: {
  5194. label: 'Hover background color',
  5195. type: 'text',
  5196. default: '',
  5197. },
  5198. dark_issues_hover_color: {
  5199. label: 'Hover color',
  5200. type: 'text',
  5201. default: '',
  5202. },
  5203. dark_pullRequests_remove: {
  5204. label: '<h3>Pull requests button</h3><div class="gmc-label">Remove</div>',
  5205. type: 'checkbox',
  5206. default: false,
  5207. },
  5208. dark_pullRequests_border: {
  5209. label: 'Border',
  5210. type: 'checkbox',
  5211. default: true,
  5212. },
  5213. dark_pullRequests_tooltip: {
  5214. label: 'Tooltip',
  5215. type: 'checkbox',
  5216. default: true,
  5217. },
  5218. dark_pullRequests_alignLeft: {
  5219. label: 'Align left',
  5220. type: 'checkbox',
  5221. default: false,
  5222. },
  5223. dark_pullRequests_boxShadow: {
  5224. label: 'Box shadow',
  5225. type: 'text',
  5226. default: '',
  5227. },
  5228. dark_pullRequests_icon_remove: {
  5229. label: 'Icon remove',
  5230. type: 'checkbox',
  5231. default: false,
  5232. },
  5233. dark_pullRequests_icon_color: {
  5234. label: 'Icon color',
  5235. type: 'text',
  5236. default: '',
  5237. },
  5238. dark_pullRequests_text_content: {
  5239. label: 'Text content',
  5240. type: 'text',
  5241. default: '',
  5242. },
  5243. dark_pullRequests_text_color: {
  5244. label: 'Text color',
  5245. type: 'text',
  5246. default: '',
  5247. },
  5248. dark_pullRequests_hover_backgroundColor: {
  5249. label: 'Hover background color',
  5250. type: 'text',
  5251. default: '',
  5252. },
  5253. dark_pullRequests_hover_color: {
  5254. label: 'Hover color',
  5255. type: 'text',
  5256. default: '',
  5257. },
  5258. dark_marketplace_add: {
  5259. label: '<h3>Marketplace</h3><div class="gmc-label">Add</div>',
  5260. type: 'checkbox',
  5261. default: false,
  5262. },
  5263. dark_marketplace_border: {
  5264. label: 'Border',
  5265. type: 'checkbox',
  5266. default: true,
  5267. },
  5268. dark_marketplace_alignLeft: {
  5269. label: 'Align left',
  5270. type: 'checkbox',
  5271. default: false,
  5272. },
  5273. dark_marketplace_boxShadow: {
  5274. label: 'Box shadow',
  5275. type: 'text',
  5276. default: '',
  5277. },
  5278. dark_marketplace_icon_remove: {
  5279. label: 'Icon remove',
  5280. type: 'checkbox',
  5281. default: false,
  5282. },
  5283. dark_marketplace_icon_color: {
  5284. label: 'Icon color',
  5285. type: 'text',
  5286. default: '',
  5287. },
  5288. dark_marketplace_text_content: {
  5289. label: 'Text content',
  5290. type: 'text',
  5291. default: '',
  5292. },
  5293. dark_marketplace_text_color: {
  5294. label: 'Text color',
  5295. type: 'text',
  5296. default: '',
  5297. },
  5298. dark_marketplace_hover_backgroundColor: {
  5299. label: 'Hover background color',
  5300. type: 'text',
  5301. default: '',
  5302. },
  5303. dark_marketplace_hover_color: {
  5304. label: 'Hover color',
  5305. type: 'text',
  5306. default: '',
  5307. },
  5308. dark_explore_add: {
  5309. label: '<h3>Explore</h3><div class="gmc-label">Add</div>',
  5310. type: 'checkbox',
  5311. default: false,
  5312. },
  5313. dark_explore_border: {
  5314. label: 'Border',
  5315. type: 'checkbox',
  5316. default: true,
  5317. },
  5318. dark_explore_alignLeft: {
  5319. label: 'Align left',
  5320. type: 'checkbox',
  5321. default: false,
  5322. },
  5323. dark_explore_boxShadow: {
  5324. label: 'Box shadow',
  5325. type: 'text',
  5326. default: '',
  5327. },
  5328. dark_explore_icon_remove: {
  5329. label: 'Icon remove',
  5330. type: 'checkbox',
  5331. default: false,
  5332. },
  5333. dark_explore_icon_color: {
  5334. label: 'Icon color',
  5335. type: 'text',
  5336. default: '',
  5337. },
  5338. dark_explore_text_content: {
  5339. label: 'Text content',
  5340. type: 'text',
  5341. default: '',
  5342. },
  5343. dark_explore_text_color: {
  5344. label: 'Text color',
  5345. type: 'text',
  5346. default: '',
  5347. },
  5348. dark_explore_hover_backgroundColor: {
  5349. label: 'Hover background color',
  5350. type: 'text',
  5351. default: '',
  5352. },
  5353. dark_explore_hover_color: {
  5354. label: 'Hover color',
  5355. type: 'text',
  5356. default: '',
  5357. },
  5358. dark_notifications_remove: {
  5359. label: '<h3>Notifications button</h3><div class="gmc-label">Remove</div>',
  5360. type: 'checkbox',
  5361. default: false,
  5362. },
  5363. dark_notifications_border: {
  5364. label: 'Border',
  5365. type: 'checkbox',
  5366. default: true,
  5367. },
  5368. dark_notifications_tooltip: {
  5369. label: 'Tooltip',
  5370. type: 'checkbox',
  5371. default: true,
  5372. },
  5373. dark_notifications_boxShadow: {
  5374. label: 'Box shadow',
  5375. type: 'text',
  5376. default: '',
  5377. },
  5378. dark_notifications_hoverBackgroundColor: {
  5379. label: 'Hover background color',
  5380. type: 'text',
  5381. default: '',
  5382. },
  5383. dark_notifications_icon_symbol: {
  5384. label: 'Icon symbol',
  5385. type: 'select',
  5386. options: [
  5387. 'none',
  5388. 'inbox',
  5389. 'bell',
  5390. ],
  5391. default: 'inbox',
  5392. },
  5393. dark_notifications_icon_color: {
  5394. label: 'Icon color',
  5395. type: 'text',
  5396. default: '',
  5397. },
  5398. dark_notifications_icon_hover_color: {
  5399. label: 'Icon hover color',
  5400. type: 'text',
  5401. default: '',
  5402. },
  5403. dark_notifications_text_content: {
  5404. label: 'Text content',
  5405. type: 'text',
  5406. default: '',
  5407. },
  5408. dark_notifications_text_color: {
  5409. label: 'Text color',
  5410. type: 'text',
  5411. default: '',
  5412. },
  5413. dark_notifications_dot_remove: {
  5414. label: 'Dot remove',
  5415. type: 'checkbox',
  5416. default: false,
  5417. },
  5418. dark_notifications_dot_boxShadowColor: {
  5419. label: 'Dot hover color',
  5420. type: 'text',
  5421. default: '',
  5422. },
  5423. dark_notifications_dot_color: {
  5424. label: 'Dot color',
  5425. type: 'text',
  5426. default: '',
  5427. },
  5428. dark_notifications_dot_displayOverIcon: {
  5429. label: 'Dot display over icon',
  5430. type: 'checkbox',
  5431. default: false,
  5432. },
  5433. dark_avatar_remove: {
  5434. label: '<h3>Avatar</h3><div class="gmc-label">Remove</div>',
  5435. type: 'checkbox',
  5436. default: false,
  5437. },
  5438. dark_avatar_size: {
  5439. label: 'Size',
  5440. type: 'text',
  5441. default: '',
  5442. },
  5443. dark_avatar_dropdownIcon: {
  5444. label: 'Dropdown icon',
  5445. type: 'checkbox',
  5446. default: false,
  5447. },
  5448. dark_avatar_canCloseSidebar: {
  5449. label: 'Can close sidebar',
  5450. type: 'checkbox',
  5451. default: false,
  5452. },
  5453. dark_globalBar_boxShadowColor: {
  5454. label: '<h3>Global bar</h3><div class="gmc-label">Box shadow color</div>',
  5455. type: 'text',
  5456. default: '',
  5457. },
  5458. dark_globalBar_leftAligned_gap: {
  5459. label: 'Left aligned gap',
  5460. type: 'text',
  5461. default: '',
  5462. },
  5463. dark_globalBar_rightAligned_gap: {
  5464. label: 'Right aligned gap',
  5465. type: 'text',
  5466. default: '',
  5467. },
  5468. dark_localBar_backgroundColor: {
  5469. label: '<h3>Local bar</h3><div class="gmc-label">Background color</div>',
  5470. type: 'text',
  5471. default: '',
  5472. },
  5473. dark_localBar_alignCenter: {
  5474. label: 'Align center',
  5475. type: 'checkbox',
  5476. default: false,
  5477. },
  5478. dark_localBar_boxShadow_consistentColor: {
  5479. label: 'Box shadow consistent color',
  5480. type: 'checkbox',
  5481. default: false,
  5482. },
  5483. dark_localBar_links_color: {
  5484. label: 'Links color',
  5485. type: 'text',
  5486. default: '',
  5487. },
  5488. dark_sidebars_backdrop_color: {
  5489. label: '<h3>Sidebars</h3><div class="gmc-label">Backdrop color</div>',
  5490. type: 'text',
  5491. default: '',
  5492. },
  5493. dark_sidebars_left_preload: {
  5494. label: 'Left preload',
  5495. type: 'checkbox',
  5496. default: false,
  5497. },
  5498. dark_sidebars_right_preload: {
  5499. label: 'Right preload',
  5500. type: 'checkbox',
  5501. default: false,
  5502. },
  5503. dark_sidebars_right_floatUnderneath: {
  5504. label: 'Right float underneath',
  5505. type: 'checkbox',
  5506. default: false,
  5507. },
  5508. dark_sidebars_right_width: {
  5509. label: 'Right width',
  5510. type: 'text',
  5511. default: '',
  5512. },
  5513. dark_sidebars_right_maxHeight: {
  5514. label: 'Right max height',
  5515. type: 'text',
  5516. default: '',
  5517. },
  5518. dark_repositoryHeader_import: {
  5519. label: '<h3>Repository header</h3><div class="gmc-label">Import</div>',
  5520. type: 'checkbox',
  5521. default: false,
  5522. },
  5523. dark_repositoryHeader_alignCenter: {
  5524. label: 'Align enter',
  5525. type: 'checkbox',
  5526. default: false,
  5527. },
  5528. dark_repositoryHeader_removePageTitle: {
  5529. label: 'Remove page title',
  5530. type: 'checkbox',
  5531. default: false,
  5532. },
  5533. dark_repositoryHeader_backgroundColor: {
  5534. label: 'Background color',
  5535. type: 'text',
  5536. default: '',
  5537. },
  5538. dark_repositoryHeader_avatar_remove: {
  5539. label: 'Avatar remove',
  5540. type: 'checkbox',
  5541. default: false,
  5542. },
  5543. dark_repositoryHeader_avatar_customSvg: {
  5544. label: 'Custom SVG (URL or text)',
  5545. type: 'textarea',
  5546. default: '',
  5547. },
  5548. dark_repositoryHeader_link_color: {
  5549. label: 'Link color',
  5550. type: 'text',
  5551. default: '',
  5552. },
  5553. dark_repositoryHeader_link_hover_backgroundColor: {
  5554. label: 'Link hover background color',
  5555. type: 'text',
  5556. default: '',
  5557. },
  5558. dark_repositoryHeader_link_hover_color: {
  5559. label: 'Link hover color',
  5560. type: 'text',
  5561. default: '',
  5562. },
  5563. dark_repositoryHeader_link_hover_textDecoration: {
  5564. label: 'Link hover text decoration',
  5565. type: 'text',
  5566. default: '',
  5567. },
  5568. on_save: {
  5569. label: 'On save',
  5570. section: ['Settings'],
  5571. type: 'select',
  5572. options: [
  5573. 'do nothing',
  5574. 'refresh tab',
  5575. 'refresh tab and close',
  5576. 'run script',
  5577. 'run script and close',
  5578. ],
  5579. default: 'do nothing',
  5580. },
  5581. on_close: {
  5582. label: 'On close',
  5583. type: 'select',
  5584. options: [
  5585. 'do nothing',
  5586. 'refresh tab',
  5587. 'run script',
  5588. ],
  5589. default: 'do nothing',
  5590. },
  5591. on_open: {
  5592. label: 'On open',
  5593. type: 'select',
  5594. options: [
  5595. 'do nothing',
  5596. 'close sidebar',
  5597. ],
  5598. default: 'close sidebar',
  5599. },
  5600. menu_item_title: {
  5601. label: 'Menu item title',
  5602. type: 'text',
  5603. default: 'Custom global navigation',
  5604. },
  5605. menu_item_icon: {
  5606. label: 'Menu item icon',
  5607. type: 'select',
  5608. options: [
  5609. 'logo',
  5610. 'compass',
  5611. 'cog',
  5612. ],
  5613. default: 'logo',
  5614. },
  5615. log_level: {
  5616. label: 'Log level',
  5617. type: 'select',
  5618. options: [
  5619. 'silent',
  5620. 'quiet',
  5621. 'debug',
  5622. 'verbose',
  5623. 'trace',
  5624. ],
  5625. default: 'quiet',
  5626. },
  5627. clear_custom_config: {
  5628. label: 'Clear Custom',
  5629. section: ['Danger Zone'],
  5630. type: 'button',
  5631. click: gmcClearCustom,
  5632. },
  5633. apply_happyMedium_config: {
  5634. label: 'Overwrite Custom with Happy Medium',
  5635. type: 'button',
  5636. click: gmcApplyCustomHappyMediumConfig,
  5637. },
  5638. apply_oldSchool_config: {
  5639. label: 'Overwrite Custom with Old School',
  5640. type: 'button',
  5641. click: gmcApplyCustomOldSchoolConfig,
  5642. },
  5643. },
  5644. });
  5645. })();