GitHub Make Tooltips

A userscript converts title tooltips into Github Tooltips

目前为 2017-04-21 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name GitHub Make Tooltips
  3. // @version 1.0.3
  4. // @description A userscript converts title tooltips into Github Tooltips
  5. // @license https://creativecommons.org/licenses/by-sa/4.0/
  6. // @author StylishThemes
  7. // @namespace https://github.com/StylishThemes
  8. // @include https://github.com/*
  9. // @run-at document-idle
  10. // @grant GM_addStyle
  11. // @icon https://avatars3.githubusercontent.com/u/6145677?v=3&s=200
  12. // ==/UserScript==
  13. /* jshint esnext:true, unused:true */
  14. (() => {
  15. "use strict";
  16.  
  17. GM_addStyle(".news .alert, .news .alert .body { overflow: visible !important; }");
  18.  
  19. function init() {
  20.  
  21. let indx = 0,
  22. els = document.querySelector("body").querySelectorAll("[title]"),
  23. regex = /(link|time-ago|relative-time)/gi,
  24. len = els.length;
  25.  
  26. // loop with delay to allow user interaction
  27. function loop() {
  28. var el, txt, direction,
  29. // max number of DOM modifications per loop
  30. max = 0;
  31. while ( max < 20 && indx < len ) {
  32. if (indx >= len) {
  33. return;
  34. }
  35. el = els[indx];
  36. if (!regex.test(el.nodeName) && !el.classList.contains("tooltipped")) {
  37. txt = el.title || "";
  38. // Change direction of star & fork tooltips - fixes #30
  39. direction = el.classList.contains("btn-with-count") ?
  40. "tooltipped-s" :
  41. "tooltipped-n";
  42. el.classList.add(...["tooltipped", direction]);
  43. if (txt.length > 45) {
  44. el.classList.add("tooltipped-multiline");
  45. }
  46. el.setAttribute("aria-label", txt);
  47. el.removeAttribute("title");
  48. max++;
  49. }
  50. indx++;
  51. }
  52. if (indx < len) {
  53. setTimeout(function(){
  54. loop();
  55. }, 200);
  56. }
  57. }
  58. loop();
  59. }
  60.  
  61. init();
  62. document.addEventListener("pjax:end", init);
  63.  
  64. })();