-
Notifications
You must be signed in to change notification settings - Fork 26
/
acacia_BONUS.user.js
111 lines (106 loc) · 4.04 KB
/
acacia_BONUS.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// ==UserScript==
// @name acacia. BONUS
// @version 2024.10.17
// @description:fr Affiche si on est en prod ; Affiche une horloge UTC ; Shift+click pour tout ouvrir/fermer
// @description Show PRD banner; Show an UTC Clock; Shift+click to expand/collapse all
// @namespace https://github.com/jesus2099/konami-command
// @supportURL https://github.com/jesus2099/konami-command/labels/acacia_BONUS
// @downloadURL https://github.com/jesus2099/konami-command/raw/master/acacia_BONUS.user.js
// @author jesus2099
// @licence CC-BY-NC-SA-4.0; https://creativecommons.org/licenses/by-nc-sa/4.0/
// @licence GPL-3.0-or-later; http://www.gnu.org/licenses/gpl-3.0.txt
// @since 2024-07-25
// @grant none
// @include /https?:\/\/[aci]{6}(-[cdertv]{3})?\.[fiancer]{9}\.fr/
// @run-at document-idle
// ==/UserScript==
"use strict";
var acacia_BONUS = {
script_name: GM_info.script.name + " version " + GM_info.script.version,
is_production: !/-/.test(location.host),
css: document.createElement("style"),
};
acacia_BONUS.css.setAttribute("type", "text/css");
document.head.appendChild(acacia_BONUS.css);
acacia_BONUS.css = acacia_BONUS.css.sheet;
// UTC Clock
waitForElement("app-footer footer", function(footer) {
acacia_BONUS.UTC_clock = document.createElement("div");
acacia_BONUS.UTC_clock.classList.add("j2-utc-clock", "text-white");
acacia_BONUS.UTC_clock.classList.add(acacia_BONUS.is_production ? "bg-red" : "bg-green");
acacia_BONUS.css.insertRule("app-footer > footer > div.j2-utc-clock { padding: 2px 8px; font-family: monospace; margin-right: auto; border-radius: .8em; font-weight: bold; text-shadow: 1px 1px 3px black; box-shadow: 2px 2px 4px grey; }", 0);
acacia_BONUS.UTC_clock.setAttribute("title", acacia_BONUS.script_name);
acacia_BONUS.UTC_clock.appendChild(document.createTextNode(getUTCTimeString(getLocale())));
footer.insertBefore(acacia_BONUS.UTC_clock, footer.firstChild);
setInterval(function() {
acacia_BONUS.UTC_clock.replaceChild(document.createTextNode(getUTCTimeString(getLocale())), acacia_BONUS.UTC_clock.firstChild);
}, 5000);
});
function getUTCTimeString(locale) {
return (new Date()).toLocaleString(
locale,
{
timeZone: "UTC",
timeZoneName: "short",
/* year: "numeric",
month: "long",
day: "2-digit",
weekday: "long", */
hour: "2-digit",
minute: "2-digit"
}
);
}
function getLocale() {
var locale = localStorage.getItem("lang");
switch (locale) {
default:
case "fr":
locale = "fr-FR";
break;
case "en":
locale = "en-GB";
break;
}
return locale;
}
// Shift+click to expand/collapse all
document.addEventListener("click", function(event) {
if (event.shiftKey) {
var mat_card = event.target.closest("div mat-card");
if (mat_card) {
var mat_icon = mat_card.querySelector("mat-icon");
if (mat_icon.textContent.match(/^expand_(less|more)$/)) {
var other_mat_icons = mat_card.closest("div").querySelectorAll("mat-card mat-icon");
for (var i = 0; i < other_mat_icons.length; i++) {
if (
other_mat_icons[i] != mat_icon
&& other_mat_icons[i].textContent.match(/^expand_(less|more)$/)
&& other_mat_icons[i].textContent != mat_icon.textContent
)
other_mat_icons[i].click();
}
}
}
}
});
// PRD banner
if (acacia_BONUS.is_production) {
waitForElement("app-header > mat-toolbar > mat-toolbar-row", function(toolbar) {
var prd_banner = document.createElement("div");
prd_banner.classList.add("fixed", "-right-9", "top-1.5", "w-28", "rotate-45", "bg-red", "p-1", "text-center", "text-xs", "font-normal", "text-white", "opacity-75", "ng-star-inserted");
prd_banner.setAttribute("title", acacia_BONUS.script_name);
prd_banner.appendChild(document.createTextNode("PRD"));
toolbar.appendChild(prd_banner);
});
}
// Library
function waitForElement(selector, callback) {
var waitForElementIntervalID = setInterval(function() {
var element = document.querySelector(selector);
if (element) {
clearInterval(waitForElementIntervalID);
callback(element);
}
}, 123);
}