Merge issues and PR tabs

Merge the issues and PRs tabs of the repositories in a single one

Από την 24/05/2023. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name          Merge issues and PR tabs
// @description   Merge the issues and PRs tabs of the repositories in a single one
// @author        Deuchnord
// @version       1.0.3
// @namespace     https://deuchnord.fr/userscipts#github.com/merge-prs-issues-tabs
// @match         https://github.com/*/*
// @icon          https://github.githubassets.com/favicons/favicon.svg
// @license       AGPL-3.0
// @grant         none
// ==/UserScript==

(function () {

  function parseMultiplier(nAsStr) {
    switch (true) {
      case nAsStr.endsWith("k"):
        return Number(nAsStr.slice(0, -1)) * 1000;

      case nAsStr.endsWith("M"):
        return Number(nAsStr.slice(0, -1)) * 1000000;

      case nAsStr.endsWith("G"):
        return Number(nAsStr.slice(0, -1)) * 1000000000;
    }

    return Number(nAsStr);
  }

  let sumIssPrs = null;

  setInterval(function () {

    let issuesTab = document.getElementById("issues-tab");
    let prsTab = document.getElementById("pull-requests-tab");

    let nIssues = parseMultiplier(issuesTab.children[2].innerText);
    let nPrs = parseMultiplier(prsTab.children[2].innerText);

    if (sumIssPrs == nIssues) {
      return;
    }

    sumIssPrs = nIssues + nPrs;
    let multiplier = 1;

    let displayedNum = sumIssPrs;

    while (displayedNum >= 1000) {
      displayedNum /= 1000;
      multiplier *= 1000;
    }

    switch (multiplier) {
      case 1:
        multiplier = "";
        break;
      case 1000:
        multiplier = "k";
        break;
      case 1000000:
        multiplier = "M";
        break;
      case 1000000000:
        multiplier = "G";
        break;
    }

    let href = new URL(issuesTab.href);

    issuesTab.href = `${href.pathname}?q=is:open`;
    issuesTab.children[1].innerText = "Issues & pull requests";
    issuesTab.children[2].innerText = `${displayedNum}${multiplier}`;
    issuesTab.children[2].removeAttribute("hidden");

    prsTab.style.display = "none";

  }, 250);

})();