-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathaddbutton.js
45 lines (40 loc) · 1.54 KB
/
addbutton.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
/*
Author: Abhijeet Rastogi (shadyabhi)
Email: abhijeet.1989@gmail.com
*/
LoadAllComments = {
runAgain : function () {
//Run every two seconds (API guidelines)
window.setTimeout(LoadAllComments.clickFirstButton, 2000);
},
clickFirstButton : function () {
//All buttons have class as "button"
var first_button = document.getElementsByClassName("button")[0];
if (first_button == null) {
return;
}
if (first_button.innerHTML === "loading...") {
first_button.className = ""; //To fix later
} else {
var theEvent = document.createEvent("MouseEvent");
theEvent.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
first_button.dispatchEvent(theEvent);
}
if (first_button.id) {
LoadAllComments.runAgain();
}
},
createButton : function () {
//Link created and added as child to "pane"
var pane = document.getElementsByClassName("panestack-title")[0];
var newlink = document.createElement("a");
newlink.appendChild(document.createTextNode("Load all comments"));
newlink.id = "loadmorecomments";
newlink.href = "javascript:void(0)";
newlink.className = "title-button ";
newlink.title = 'Opens all "load more comments" links every 2 seconds';
newlink.addEventListener('click', LoadAllComments.runAgain, false);
pane.appendChild(newlink);
}
};
LoadAllComments.createButton();