forked from f2404/torn-userscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfaction_prettify_select_clear_all.user.js
67 lines (56 loc) · 2.02 KB
/
faction_prettify_select_clear_all.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
// ==UserScript==
// @name Torn: Factions: Prettify Select/Clear All buttons
// @namespace lugburz.faction.select_clear_button
// @version 0.1
// @description Prettify Select/Clear All buttons on the faction Permissions page.
// @author Lugburz
// @match https://www.torn.com/factions.php?step=your*
// @require https://greasyfork.org/scripts/390917-dkk-torn-utilities/code/DKK%20Torn%20Utilities.js?version=744690
// @grant none
// ==/UserScript==
function replaceCBs(cbs) {
$(cbs).each(function() {
$(this).hide();
let span = '<span class="clear-action t-blue h" style="cursor: pointer;">Select</span>'
$(this).parent().append(span);
let cb = $(this).find('input.checkbox-css');
$(cb).prop('checked', true);
$(this).parent().find('span.clear-action').on('click', function() {
let cb_id = $(cb).attr('id');
$('#'+cb_id).click();
if ($(this).text() == 'Select') {
$(this).text('Clear');
} else {
$(this).text('Select');
}
});
});
}
function prettify() {
if (!$(location).attr('href').includes('tab=controls')) {
return;
}
let cbs = $('#select-all').find('div.choice-container');
if (cbs.length > 0) {
$('#select-all > div.permission-member').append('<span>All:</span>');
// Add top row
let row = $('li.select-all-wrap').clone();
$(row).attr('id', 'select-all-top');
$(row).find('input.checkbox-css').each(function() {
let id = $(this).attr('id') + '-top';
$(this).attr('id', id);
});
$('#permission-members-list').prepend($(row));
replaceCBs(cbs);
let cbs_top = $('#select-all-top').find('div.choice-container');
replaceCBs(cbs_top);
}
}
(function() {
'use strict';
// Your code here...
ajax((page, json, uri) => {
if (page != "factions") return;
$('#select-all').ready(prettify);
});
})();