mod github layout

Temporarily improve github project layout

  1. // ==UserScript==
  2. // @name mod github layout
  3. // @name:zh-CN 调整github新布局
  4. // @version 0.0.3
  5. // @namespace https://github.com/Ahaochan/Tampermonkey
  6. // @match *://*.github.com/*/*
  7. // @description Temporarily improve github project layout
  8. // @description:zh-CN 该插件用于临时改善github新版本布局
  9. // ==/UserScript==
  10. ((document)=>{
  11. const menuSelector = 'nav.js-repo-nav';
  12. let menu = document.querySelector(menuSelector).parentNode;
  13. let progressBar = document.querySelector('.progress-pjax-loader > span');
  14. if(menu && initoPlugin()) {
  15. tickLoaded = true;
  16. console.log('插件初始化完成,此插件临时改善新版github布局\n2020-06-24\n-by-灰铁炼成樱花');
  17. let lastMesh = document.location.href;
  18. setInterval(async () => {
  19. const newMesh = document.location.href;
  20. if(lastMesh !== newMesh) {
  21. lastMesh = newMesh;
  22. await isLoaded();
  23. initoPlugin();
  24. }
  25. }, 100);
  26. }
  27.  
  28. function initoPlugin() {
  29. const removeColorClass = 'bg-gray-light';
  30. menu.classList.add('container-xl');
  31. menu.classList.remove(removeColorClass);
  32. menu.childNodes.forEach((node) => {
  33. node.nodeType === 1 && node.classList.remove(removeColorClass);
  34. });
  35. const content = document.querySelector('.gutter-condensed > div:nth-child(2)');
  36. if(content) {
  37. TabfindPubLinks(content);
  38. return true;
  39. }
  40. }
  41.  
  42. function TabfindPubLinks(content) {
  43. let pubLinks = content.querySelectorAll('a.text-small');
  44. for (let i = 0, l = pubLinks.length; i < l; i++) {
  45. let el = pubLinks[i];
  46. let text = el.innerText;
  47. let match = text.match(/\d+.*releases/);
  48. if(match) {
  49. const link = el.getAttribute('href');
  50. let pubNum = parseInt(text.match(/\d+/)[0]);
  51. if(pubNum > 0) {
  52. pubNum += 1;
  53. }
  54. const insertTmp =
  55. `
  56. <li class='d-flex'>
  57. <a class="js-selected-navigation-item UnderlineNav-item hx_underlinenav-item no-wrap js-responsive-underlinenav-item" data-tab-item="insights-tab" data-ga-click="Repository, Navigation click, Insights tab" href="${link}">
  58. <svg height="16" class="octicon octicon-play UnderlineNav-octicon d-none d-sm-inline mt="1" viewBox="0 0 16 16" version="1.1" width="16" aria-hidden="true"><path fill-rule="evenodd" d="M2.5 7.775V2.75a.25.25 0 01.25-.25h5.025a.25.25 0 01.177.073l6.25 6.25a.25.25 0 010 .354l-5.025 5.025a.25.25 0 01-.354 0l-6.25-6.25a.25.25 0 01-.073-.177zm-1.5 0V2.75C1 1.784 1.784 1 2.75 1h5.025c.464 0 .91.184 1.238.513l6.25 6.25a1.75 1.75 0 010 2.474l-5.026 5.026a1.75 1.75 0 01-2.474 0l-6.25-6.25A1.75 1.75 0 011 7.775zM6 5a1 1 0 100 2 1 1 0 000-2z"></path></svg>
  59. <span>Release</span>
  60. <span class="Counter">${pubNum.toString()}</span>
  61. </a>
  62. </li>
  63. `;
  64. const beforeTab = menu.querySelector('.UnderlineNav > ul');
  65. beforeTab && beforeTab.insertAdjacentHTML('beforeend', insertTmp);
  66. break;
  67. }
  68. }
  69. }
  70.  
  71. async function isLoaded() {
  72. let checkTimer = 0;
  73. return new Promise((resolve) => {
  74. checkTimer = setInterval(() => {
  75. menu = document.querySelector(menuSelector).parentNode;
  76. if(progressBar.offsetWidth >= document.body.clientWidth) {
  77. resolve();
  78. clearInterval(checkTimer);
  79. }
  80. }, 100);
  81. })
  82. }
  83. })(document);

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址