Greasy Fork 还支持 简体中文。

GitHub Custom Global Navigation

Customize GitHub's new global navigation

目前為 2024-01-31 提交的版本,檢視 最新版本

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