Greasy Fork 还支持 简体中文。

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