GitHub Make Tooltips

A userscript converts title tooltips into Github Tooltips

Από την 08/07/2019. Δείτε την τελευταία έκδοση.

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

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το 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        GitHub Make Tooltips
// @version     1.0.5
// @description A userscript converts title tooltips into Github Tooltips
// @license     MIT
// @author      StylishThemes
// @namespace   https://github.com/StylishThemes
// @include     https://github.com/*
// @run-at      document-idle
// @grant       GM_addStyle
// @icon        https://avatars3.githubusercontent.com/u/6145677?v=3&s=200
// ==/UserScript==
/* jshint esnext:true, unused:true */
(() => {
  "use strict";

  GM_addStyle(".news .alert, .news .alert .body { overflow: visible !important; }");

  function init() {
    let indx = 0;
    const els = document.querySelector("body").querySelectorAll("[title]");
    const regex = /(link|time-ago|relative-time)/gi;
    const len = els.length;

    // loop with delay to allow user interaction
    function loop() {
      let el, txt, direction,
        // max number of DOM modifications per loop
        max = 0;
      while (max < 20 && indx < len) {
        if (indx >= len) {
          return;
        }
        el = els[indx];
        if (!regex.test(el.nodeName) && !el.classList.contains("tooltipped")) {
          txt = el.title || "";
          // Change direction of star & fork tooltips - fixes #30
          direction = el.classList.contains("btn-with-count") ?
            "tooltipped-s" :
            "tooltipped-n";
          el.classList.add(...["tooltipped", direction]);
          if (txt.length > 45) {
            el.classList.add("tooltipped-multiline");
          }
          el.setAttribute("aria-label", txt);
          el.removeAttribute("title");
          max++;
        }
        indx++;
      }
      if (indx < len) {
        setTimeout(() => {
          loop();
        }, 200);
      }
    }
    loop();
  }

  init();
  document.addEventListener("pjax:end", init);
})();