GitHub Custom Global Navigation

Customize GitHub's new global navigation

当前为 2024-01-30 提交的版本,查看 最新版本

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