Github commits最后一页

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

当前为 2023-07-04 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Github commits最后一页
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  This will help users get a button to click to end of the github commits page.
// @author       Mutu
// @match        https://github.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=github.com
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';
    let reg = new RegExp("\/commits\/")
    var isInsert = false
    var timer = setInterval(() => {
        if (isInsert) {
            if (reg.test(window.location.pathname)) {
            } else {
                getCommits()
                isInsert = false
            }
        } else {
            if (reg.test(window.location.pathname)) {
                insertBtn()
                isInsert = true
            } else {
                getCommits()
            }
        }
    }, 1000);

    function getCommits() {
        if (document.querySelector(".Details strong")) {
            let commits = document.querySelector(".Details strong").innerText
            sessionStorage.setItem("commits", commits)
        }
    }

    function insertBtn() {
        let commitsStr = sessionStorage.getItem("commits")
        let btnGroup = document.querySelector(".BtnGroup")
        let btnToNext = document.querySelector(".BtnGroup a")
        let btnToEnd = document.createElement('a')
        btnToEnd.className = "btn btn-outline BtnGroup-item"
        let commitsNum = parseInt(commitsStr.replace(/,/, ""), 10)
        btnToEnd.href = btnToNext.href.replace(/\+\d+/g, `+${commitsNum - 34}`)
        btnToEnd.innerText = "Click To End"
        btnGroup.appendChild(btnToEnd)
    }
})();