Greasy Fork 支持简体中文。

GitHub Make Tooltips

A userscript converts title tooltips into Github Tooltips

目前為 2017-03-13 提交的版本,檢視 最新版本

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