-
Notifications
You must be signed in to change notification settings - Fork 10
/
faction_show_oc_due_date.user.js
92 lines (73 loc) · 3.17 KB
/
faction_show_oc_due_date.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// ==UserScript==
// @name Torn: Faction: Show OC due date
// @namespace lugburz.faction.show_oc_due_date
// @version 0.3.9
// @description Show when OC's are due, in addition to time left that Torn shows.
// @author Lugburz
// @match https://www.torn.com/factions.php?step=your*
// @require https://raw.githubusercontent.com/f2404/torn-userscripts/master/lib/lugburz_lib.js
// @updateURL https://github.com/f2404/torn-userscripts/raw/master/faction_show_oc_due_date.user.js
// @grant none
// ==/UserScript==
// Whether to use Torn time (TCT) or local time
const USE_TCT = false;
// Whether to replace the text in the "Status" column or append to it
const REPLACE = false;
// Whether to highlight your team in the OC list
const HIGHLIGHT = true;
function format_date(d) {
if (USE_TCT) {
const m = d.getUTCMonth() + 1;
return pad(d.getUTCHours(), 2) + ":" + pad(d.getUTCMinutes(), 2) + " " + pad(d.getUTCDate(), 2) + "/" + pad(m, 2) + " TCT";
}
const options = {day: '2-digit', month: '2-digit', hour: '2-digit', minute: '2-digit'};
return d.toLocaleDateString(undefined, options);
}
function format_time(hours, mins) {
const d = Math.trunc(hours / 24);
const h = hours % 24;
return (d > 0 ? d + 'd ' : '') + (d > 0 || h > 0 ? h + 'h ' : '') + mins + 'min';
}
function update() {
const avail = $("div.begin-wrap").find("ul.crimes-list").find("li.item-wrap").first().find("ul.plans-list").children("li").size();
if (avail > 0 && $("#membersAvail").size() < 1) {
const msg = avail == 1 ? '1 member is' : `${avail} members are`;
const div = `<div id="membersAvail" class="cont-gray10 cont-toggle" style="border-radius: 5px;">${msg} available.</div>`;
$(div).insertBefore($("div.faction-crimes-wrap").first());
}
let my_name = "";
if (HIGHLIGHT) {
my_name = $("#sidebarroot").find("a[class^='menu-value']").html();
}
$("ul.crimes-list > li").each(function() {
const status = $(this).find(".status");
if (typeof status !== 'undefined' && status !== null && $(status).text()) {
const found = $(status).text().match(/^\n(\s+)?((\d+)h )?(\d+)min left\s+$/);
if (found !== undefined && found !== null) {
const hours = found[3] || 0;
const mins = found[4] || 0;
let d = new Date(Date.now());
d.setTime(d.getTime() + hours*60*60*1000 + mins*60*1000);
if (REPLACE) {
$(status).html("due at " + format_date(d));
} else {
$(status).html(format_date(d) + "<br>" + format_time(hours, mins) + ' left');
}
}
}
if (HIGHLIGHT && my_name) {
const team = $(this).find(".team");
if (typeof team !== 'undefined' && typeof team.html() !== 'undefined' && team.html().includes(my_name)) {
$(this).addClass("bg-green");
}
}
});
}
(function() {
'use strict';
ajax((page) => {
if (page != "factions") return;
$("ul.crimes-list").ready(update);
});
$("ul.crimes-list").ready(update);
})();