Find the initial Github commit

This will help users get a button to click to end of the github commits page.

Verze ze dne 20. 02. 2025. Zobrazit nejnovější verzi.

  1. // ==UserScript==
  2. // @name Find the initial Github commit
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2.1
  5. // @description This will help users get a button to click to end of the github commits page.
  6. // @author Mutu,aspen138
  7. // @match https://github.com/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=github.com
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15. let reg = new RegExp("\/commits\/")
  16. var isInsert = false
  17. var timer = setInterval(() => {
  18. if (isInsert) {
  19. if (reg.test(window.location.pathname)) {
  20. } else {
  21. getCommits()
  22. isInsert = false
  23. }
  24. } else {
  25. if (reg.test(window.location.pathname)) {
  26. insertBtn()
  27. isInsert = true
  28. } else {
  29. getCommits()
  30. }
  31. }
  32. }, 1000);
  33.  
  34. function getCommits() {
  35. // Attempt to find the span that displays the commit count
  36. let commitSpan = document.querySelector("span.fgColor-default.custom-highlight");
  37. if (commitSpan) {
  38. // Example innerText might be "90 Commits", so remove "Commits" and trim extra space
  39. let commitText = commitSpan.innerText.replace("Commits", "").trim();
  40. //let commitNumber = parseInt(commitText, 10);
  41.  
  42. // Store just the numeric portion in sessionStorage
  43. sessionStorage.setItem("commits", commitText);
  44. }
  45. }
  46.  
  47. function insertBtn() {
  48. // Get the total commit count from sessionStorage
  49. let commitsStr = sessionStorage.getItem("commits");
  50. let commitsNum = parseInt(commitsStr.replace(/,/, ""), 10);
  51. console.log("commitsNum=",commitsNum);
  52. // Select the container that holds the pagination buttons
  53. let btnGroup = document.querySelector(".Box-sc-g0xbh4-0.prc-ButtonGroup-ButtonGroup-vcMeG");
  54. if (!btnGroup) return; // Guard clause if the container isn't found
  55.  
  56. // Select the "Next" pagination link
  57. let btnToNext = document.querySelector("[data-testid='pagination-next-button']");
  58. if (!btnToNext) return; // Guard clause if there's no "Next" button
  59.  
  60. // Create the wrapper div
  61. let newDiv = document.createElement("div");
  62.  
  63. // Create the new "Click To End" anchor
  64. let btnToEnd = document.createElement("a");
  65. btnToEnd.type = "button";
  66. btnToEnd.tabIndex = 0;
  67. btnToEnd.setAttribute("data-testid", "pagination-last-button");
  68. btnToEnd.className = "prc-Button-ButtonBase-c50BI fgColor-accent text-normal";
  69. btnToEnd.setAttribute("data-loading", "false");
  70. btnToEnd.setAttribute("data-size", "medium");
  71. btnToEnd.setAttribute("data-variant", "invisible");
  72. btnToEnd.href = btnToNext.href.replace(/\+\d+/g, `+${commitsNum-4}`);
  73.  
  74. // Construct the inner span structure to match the new button style
  75. let spanContent = document.createElement("span");
  76. spanContent.setAttribute("data-component", "buttonContent");
  77. spanContent.className = "prc-Button-ButtonContent-HKbr-";
  78.  
  79. let spanText = document.createElement("span");
  80. spanText.setAttribute("data-component", "text");
  81. spanText.className = "prc-Button-Label-pTQ3x";
  82. spanText.innerText = "Click To End";
  83.  
  84. // Assemble all parts
  85. spanContent.appendChild(spanText);
  86. btnToEnd.appendChild(spanContent);
  87. newDiv.appendChild(btnToEnd);
  88. console.log("newDiv=",newDiv);
  89. btnGroup.appendChild(newDiv);
  90. console.log("btnGroup=", btnGroup);
  91. }
  92. })();