This repository has been archived by the owner on Jan 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
87 lines (78 loc) · 2.02 KB
/
bot.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/**
* HipChat Delete BOT
*
* @since 2015
* @copyright Simon Sippert <[email protected]>
* @type {object}
*/
var deleteBot = {
// stores jquery instance
jq: null,
/**
* inits the bot
*/
init: function () {
deleteBot.jq = jQuery;
deleteBot.action();
},
/**
* search for messages and send them to remove action
*/
action: function () {
var forms = deleteBot.getForms();
if (!forms.length) {
deleteBot.goNext();
} else {
forms.each(function (i, form) {
deleteBot.remove(deleteBot.jq(form));
});
}
},
/**
* Get all messages to delete
*/
getForms: function () {
return deleteBot.jq('.delete form');
},
/**
* Remove them
* @param {object} form
*/
remove: function (form) {
deleteBot.jq.ajax({
method: 'POST',
url: form.attr('action'),
data: form.serialize(),
success: function () {
// remove dom element
form.remove();
// check additional forms
if (!deleteBot.getForms().length) {
// go to next page
deleteBot.goNext();
}
}
});
},
/**
* Goes to next page
*/
goNext: function () {
var a, li = deleteBot.jq('.aui-nav-pagination .aui-nav-selected').next();
if (li.length && li.is(':visible')) {
a = li.find('a');
} else {
a = deleteBot.jq('.historynav .aui-button:first-child');
}
deleteBot.jq.ajax({
url: a.attr('href'),
success: function (html) {
deleteBot.jq('html').html(html.replace(/<html(.*)>(.*)<\/html>/, "$2"));
setTimeout(deleteBot.action, 80);
}
});
}
};
// go :)
jQuery(deleteBot.init);
console.debug('Please close your console now to prevent slowing down your computer.');