forked from StylishThemes/GitHub-Dark-Script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub-script-make-tooltips.user.js
66 lines (60 loc) · 2.04 KB
/
github-script-make-tooltips.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// ==UserScript==
// @name GitHub Make Tooltips
// @version 1.0.4
// @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
// @updateURL https://raw.githubusercontent.com/StylishThemes/GitHub-Dark-Script/master/github-script-make-tooltips.user.js
// @downloadURL https://raw.githubusercontent.com/StylishThemes/GitHub-Dark-Script/master/github-script-make-tooltips.user.js
// ==/UserScript==
/* jshint esnext:true, unused:true */
(() => {
"use strict";
GM_addStyle(".news .alert, .news .alert .body { overflow: visible !important; }");
function init() {
let indx = 0,
els = document.querySelector("body").querySelectorAll("[title]"),
regex = /(link|time-ago|relative-time)/gi,
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(function(){
loop();
}, 200);
}
}
loop();
}
init();
document.addEventListener("pjax:end", init);
})();