-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdonations-auto-autorefresh.user.js
69 lines (60 loc) · 2.43 KB
/
donations-auto-autorefresh.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
67
68
// ==UserScript==
// @name ESA donations :: auto-autorefresh enabler
// @description Automatically enables autorefresh when table of donations becomes empty
// @author https://github.com/rybak
// @homepageURL https://github.com/rybak/esa-tweaks
// @version 3
// @license MIT; https://github.com/rybak/esa-tweaks/blob/main/LICENSE.txt
// @match https://donations.esamarathon.com/admin/process_donations
// @match https://donations.esamarathon.com/admin/process_pending_bids
// @match https://donations.esamarathon.com/admin/read_donations
// @match https://uksg.esamarathon.com/admin/process_donations
// @match https://uksg.esamarathon.com/admin/process_pending_bids
// @match https://uksg.esamarathon.com/admin/read_donations
// @match https://tracker.bsgmarathon.com/admin/process_donations
// @match https://tracker.bsgmarathon.com/admin/process_pending_bids
// @match https://tracker.bsgmarathon.com/admin/read_donations
// @match https://bsgmarathon.com/tracker/admin/process_donations
// @match https://bsgmarathon.com/tracker/admin/process_pending_bids
// @match https://bsgmarathon.com/tracker/admin/read_donations
// @icon https://www.google.com/s2/favicons?domain=esamarathon.com
// @namespace http://tampermonkey.net/
// @grant none
// ==/UserScript==
(function() {
'use strict';
const MAIN_TABLE_ID = 'id_result_set';
function log(msg) {
console.log("[ESA auto autorefresh] " + msg);
}
function warn(msg) {
console.warn("[ESA auto autorefresh] " + msg);
}
function findAutoRefreshCheckbox() {
return $("#id_autoRefresh");
}
function enableAutoRefreshCheckbox() {
const checkbox = findAutoRefreshCheckbox();
if (checkbox.length) {
log("Auto-refresh checkbox is " + checkbox.prop('checked'));
if (!checkbox.prop('checked')) {
checkbox.click();
log("Auto-refresh changed to " + checkbox.prop('checked'));
}
} else {
warn("Could not find autorefresh checkbox");
}
}
function autoAutoRefresh() {
const rowCount = $('#id_result_set > tbody > tr').length;
log(`There are ${rowCount} rows in the table #${MAIN_TABLE_ID}`);
if (rowCount == 0) {
enableAutoRefreshCheckbox();
}
}
$(document).ready(() => {
const table = document.getElementById(MAIN_TABLE_ID);
const observer = new MutationObserver(autoAutoRefresh);
observer.observe(table, {subtree: true, childList: true});
});
})();