-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.js
More file actions
121 lines (107 loc) · 3.53 KB
/
init.js
File metadata and controls
121 lines (107 loc) · 3.53 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/* eslint-env jquery */
/* global plugin, theWebUI, theContextMenu, askYesNo, noty */
plugin.loadMainCSS();
// Modify the default settings, but
// still respect user customization
theWebUI.addSettings({
// Timeouts generally occur when rtorrent
// is busy. Yet if we tell the user that a
// timeout has occurred, they're more likely
// to hit the refresh button, overloading
// rTorrent further.
'webui.ignore_timeouts': 1,
// A lot of users got a minimum of 280 set during ruTorrent 5.0
// override to the new default of 200
'webui.side_panel_min_width': 200,
});
// Disable pushbullet column by default, but
// still respect a users choice to enable it
theWebUI.tables.trt.columns.origPush = theWebUI.tables.trt.columns.push;
theWebUI.tables.trt.columns.push = function (values) {
if (values.id === 'pushbullet') {
values.enabled = false;
}
return this.origPush(values);
};
theWebUI.restartDaemon = function(){
$.ajax({
type: 'POST',
timeout: theWebUI.settings['webui.reqtimeout'],
async: true,
cache: false,
url: '/api/restart',
data: {'app': 'rtorrent'},
dataType : 'json'
}).done(function(){
location.reload();
});
};
theWebUI.checkDaemon = function(){
$.ajax({
type: 'GET',
timeout: theWebUI.settings['webui.reqtimeout'],
async : true,
cache: false,
url : '/api/rtorrent_status',
dataType : 'json'
}).done(function(json){
if (json.client_running === false) {
askYesNo('Restart rtorrent', 'Your rtorrent daemon appears to be offline. Would you like us to start it for you?', 'theWebUI.restartDaemon()');
}
});
};
theWebUI.checkDownloadLimit = function(){
$.ajax({
type: 'GET',
timeout: theWebUI.settings['webui.reqtimeout'],
async : true,
cache: false,
url : '/api/download_limit',
dataType : 'json'
}).done(function(json){
if (json !== 0) {
noty('whatbox: Your download speed has been throttled because you are over your storage allocation.', 'alert');
}
});
};
plugin.init = function() {
if(this.enabled) {
this.addButtonToToolbar('logoff','Logout','window.location = \'/logout\';','logoff');
theWebUI.showBunnyMenu = function() {
theContextMenu.clear();
theContextMenu.add(['HTTP Listing', 'window.open(\'/private\',\'_blank\');']);
theContextMenu.add(['Labs', 'window.open(\'/labs\',\'_blank\');']);
theContextMenu.add(['Manage', 'window.open(\'https://whatbox.ca/manage\',\'_blank\');']);
theContextMenu.add(['Renew', 'window.open(\'https://whatbox.ca/manage/payments\',\'_blank\');']);
var offs = $('#bunnybutton').offset();
theContextMenu.show(offs.left-5,offs.top+5+$('#plugins').height());
};
this.addButtonToToolbar('bunnybutton','Whatbox','theWebUI.showBunnyMenu()','bunnybutton');
this.addSeparatorToToolbar('bunnybutton');
theWebUI.checkDaemon();
theWebUI.checkDownloadLimit();
// Every 20 minutes do an API no-op so the server knows the session is still active
// Server only records activity every 15 minutes, so we want to be above that
// Normally this would be handled by the disk_usage checks, but we disable
// those to save battery life when a tab is in the background
fetch('/api/noop', {
credentials: 'include',
});
setInterval(function () {
fetch('/api/noop', {
credentials: 'include',
});
}, 1200000);
}
};
plugin.onRemove = function() {
this.removeButtonFromToolbar('logoff');
this.removeButtonFromToolbar('bunnybutton');
};
plugin.init();
$(document).ajaxComplete(function(e, jqXHR){
// https://github.com/jquery/jquery/issues/4339
if (jqXHR.getResponseHeader('X-Whatbox') === 'login'){
window.location = '/login';
}
});