-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlgtm-gifs-github.user.js
55 lines (48 loc) · 1.81 KB
/
lgtm-gifs-github.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
// ==UserScript==
// @name lgtm-gifs-github
// @namespace https://www.github.com/thatlittleboy
// @version 2.0
// @author thatlittleboy
// @include https://github.com/*
// @require https://cdnjs.cloudflare.com/ajax/libs/js-yaml/4.1.0/js-yaml.min.js
// @grant GM.xmlHttpRequest
// ==/UserScript==
(function () {
console.log("Greasemonkey lgtm-gifs-github running...");
let all_lgtm;
GM.xmlHttpRequest({
method: "GET",
url: "https://raw.githubusercontent.com/thatlittleboy/lgtm-db/main/lgtm_db/data/db.yaml",
onload: function (resp) {
if (resp.status === 200) {
try {
const ymldoc = jsyaml.load(resp.response);
all_lgtm = ymldoc["gifs"].concat(ymldoc["images"]);
} catch (e) {
console.log("error", e);
all_lgtm = [];
}
// console.log(all_lgtm);
}
},
});
document.documentElement.addEventListener("click", function (e) {
let msg;
console.log(
"click event registered. name:",
e.target.name,
", value:",
e.target.value
);
if (all_lgtm.length && e.target.name === "pull_request_review[event]" && e.target.value === "approve") {
console.log("inside approved if-block");
// user just clicked on the "Approve" button
// find the comment box by id
msg = document.querySelector("#pull_request_review_body");
// select a random gif
const selected = all_lgtm[Math.floor(Math.random() * all_lgtm.length)];
// replace the msg value
msg.value = `${msg.value}\n\n![${selected.name}](${selected.url})`;
}
});
})();