GitHub Make Tooltips

A userscript converts title tooltips into Github Tooltips

目前为 2016-08-10 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name GitHub Make Tooltips
  3. // @version 1.0.0
  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.querySelectorAll("[title]"),
  22. len = els.length;
  23.  
  24. // loop with delay to allow user interaction
  25. function loop() {
  26. var el, txt,
  27. // max number of DOM modifications per loop
  28. max = 0;
  29. while ( max < 20 && indx < len ) {
  30. if (indx >= len) {
  31. return;
  32. }
  33. el = els[indx];
  34. if (el.nodeName !== "LINK" && !el.classList.contains("tooltipped")) {
  35. txt = el.title;
  36. el.classList.add(...["tooltipped", "tooltipped-n"]);
  37. if (txt.length > 45) {
  38. el.classList.add("tooltipped-multiline");
  39. }
  40. el.setAttribute("aria-label", txt);
  41. el.removeAttribute('title');
  42. max++;
  43. }
  44. indx++;
  45. }
  46. if (indx < len) {
  47. setTimeout(function(){
  48. loop();
  49. }, 200);
  50. }
  51. }
  52. loop();
  53. }
  54.  
  55. init();
  56. document.addEventListener("pjax:end", init);
  57.  
  58. })();