Skip to content

Commit

Permalink
GLOBAL: use ES6 modules
Browse files Browse the repository at this point in the history
While CoRT doesn't really need modules, that would allow in the future
to use webpack or other stuff more easily.

This finally breaks the compatibility with the old baseline Firefox 52,
as modules are supported starting from Firefox 60.

There should be no user facing changes, some pages may benefit from it
as it has reduced the amount of javascript loaded.
  • Loading branch information
mascaldotfr committed Jan 13, 2024
1 parent 27a0543 commit 6ffe3f3
Show file tree
Hide file tree
Showing 27 changed files with 217 additions and 225 deletions.
7 changes: 3 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ The oldest browser a valid bug was reported against was Chrome 80
(`element.replaceChildren()` missing), so we've mostly up to date users, thanks
to browser updating themselves. But the baseline is born from it.

Actually the site works even with Firefox 52 (XP/Vista), minus the charts. As
such, Firefox 60 (May 2018) was chosen because it was the closest ESR version
to 52 supporting the charts, and any bug report for a browser older than that
will be rejected.
Firefox 60 (May 2018) was chosen because it was the minimal version of Firefox
supporting all the site features, and any bug report for a browser older than
that will be rejected.

You can use an old [Debian Live image which has already that version
preloaded](https://cdimage.debian.org/cdimage/archive/9.7.0-live/amd64/iso-hybrid/debian-live-9.7.0-amd64-xfce.iso)
Expand Down
10 changes: 2 additions & 8 deletions bosses.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,9 @@
<link rel="icon" type="image/png" href="favicon.png">
<link rel="apple-touch-icon" href="favicon.png" sizes="192x192">
<script type="text/javascript" src="js/unsupported.js"></script>
<script type="text/javascript" src="js/api_url.js"></script>
<script type="text/javascript" src="js/browserquirks.js"></script>
<script type="text/javascript" src="js/lamaiquery.js"></script>
<script type="text/javascript" src="data/i18n_db.js"></script>
<script type="text/javascript" src="js/i18n.js"></script>
<script type="text/javascript" src="js/menu.js"></script>
<script type="text/javascript" src="js/notify.js"></script>
<script type="text/javascript" src="js/wztools.js"></script>
<script type="text/javascript" src="js/bosses.js"></script>
<script type="module" src="js/menu.js"></script>
<script type="module" src="js/bosses.js"></script>
</head>
<body>
<div id="main-container">
Expand Down
9 changes: 2 additions & 7 deletions bz.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,9 @@
<link rel="icon" type="image/png" href="favicon.png">
<link rel="apple-touch-icon" href="favicon.png" sizes="192x192">
<script type="text/javascript" src="js/unsupported.js"></script>
<script type="text/javascript" src="js/api_url.js"></script>
<script type="text/javascript" src="js/browserquirks.js"></script>
<script type="text/javascript" src="js/lamaiquery.js"></script>
<script type="text/javascript" src="data/i18n_db.js"></script>
<script type="text/javascript" src="js/i18n.js"></script>
<script type="text/javascript" src="js/menu.js"></script>
<script type="text/javascript" src="js/notify.js"></script>
<script type="text/javascript" src="js/bz.js"></script>
<script type="module" src="js/menu.js"></script>
<script type="module" src="js/bz.js"></script>
</head>
<body>
<div id="main-container">
Expand Down
2 changes: 1 addition & 1 deletion data/i18n_db.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const __i18n__ = {
export const __i18n__ = {
"supported_lang": ["en", "fr", "es", "de"],
"You are offline. Impossible to fetch the data.": {
"fr": "Vous êtes hors ligne. Impossible de récupérer les données.",
Expand Down
13 changes: 4 additions & 9 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,11 @@
<link rel="icon" type="image/png" href="favicon.png">
<link rel="apple-touch-icon" href="favicon.png" sizes="192x192">
<script type="text/javascript" src="js/unsupported.js"></script>
<script type="text/javascript" src="js/api_url.js"></script>
<script type="text/javascript" src="js/browserquirks.js"></script>
<script type="text/javascript" src="js/lamaiquery.js"></script>
<script type="text/javascript" src="data/i18n_db.js"></script>
<script type="text/javascript" src="js/i18n.js"></script>
<script type="text/javascript" src="js/menu.js"></script>
<script type="text/javascript" src="js/lz-string.min.js"></script>
<script type="text/javascript" src="js/popper.js"></script>
<script type="text/javascript" src="js/tippy.js"></script>
<script type="text/javascript" src="js/trainer.js" defer></script>
<script type="module" src="js/popper.js"></script>
<script type="module" src="js/tippy.js"></script>
<script type="module" src="js/menu.js"></script>
<script type="module" src="js/trainer.js"></script>
</head>
<body>
<div id="main-container">
Expand Down
24 changes: 11 additions & 13 deletions js/api_url.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@
// the pull!

// The root where all API files can be found
const __api__base = "https://hail.thebus.top/CoRT";
export const __api__base = "https://hail.thebus.top/CoRT";
// Used by the trainer to filter setup submissions
const __api__frontsite = "https://mascaldotfr.github.io";
export const __api__frontsite = "https://mascaldotfr.github.io";
// Subdirectory where the HTML/JS/CSS/etc. files are placed, relative to your
// www root with the leading '/'
const __api__frontsite_dir = "/CoRT";
export const __api__frontsite_dir = "/CoRT";

const __api__urls = {
export const __api__urls = {
"submit_trainer": `${__api__base}/collect/submit.php`,
"events": `${__api__base}/warstatus/stats/allevents.json`,
"stats": `${__api__base}/warstatus/stats/statistics.json`,
"wstatus": `${__api__base}/warstatus/warstatus.json`
};
const __api__pages = {
export const __api__pages = {
"wevents.html": __api__urls["events"],
"wz.html": __api__urls["wstatus"],
"wstats.html": __api__urls["stats"]
};

function __api_create_prefetch(url) {
export function __api_create_prefetch(url) {
let l = document.createElement("link");
l.href = url;
l.rel = "preload";
Expand All @@ -33,10 +33,8 @@ function __api_create_prefetch(url) {
document.head.appendChild(l);
}


(function() {
const currpage = location.pathname.split("/").pop();
if (currpage in __api__pages) {
__api_create_prefetch(__api__pages[currpage]);
}
}());
const currpage = location.pathname.split("/").pop();
if (currpage in __api__pages) {
console.log("creating prefetch for", currpage, "at", __api__pages[currpage]);
__api_create_prefetch(__api__pages[currpage]);
}
6 changes: 6 additions & 0 deletions js/bosses.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
* along with CoRT. If not, see <http://www.gnu.org/licenses/>.
*/

import {$} from "./lamaiquery.js";
import {_} from "./i18n.js";
import {insert_notification_link, mynotify} from "./notify.js";
import {timestamp_now, timestamp_ago} from "./wztools/time.js";

// The last respawn timestamp in UTC time
// You can update it by looking at your browser console and getting the last
// respawn timestamps. At least yearly, since the get_next_respawns() loop
Expand All @@ -38,6 +43,7 @@ function unixstamp2human(unixstamp) {
function get_next_respawns(boss) {
let tried_respawn = first_respawns[boss];
let now = timestamp_now();
let respawn_time = 0;
while (true) {
if (boss == "server")
respawn_time = 168 * 3600; // 1 week
Expand Down
35 changes: 19 additions & 16 deletions js/bz.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,29 @@
* along with CoRT. If not, see <http://www.gnu.org/licenses/>.
*/

import {$} from "./lamaiquery.js";
import {_} from "./i18n.js";
import {insert_notification_link, mynotify} from "./notify.js";

// XXX ALL TIMES ARE UTC INTERNALLY
// SUNDAY = 0 SATURDAY = 6
let bz_begin = [ [13, 18],
[3, 13, 20],
[13, 18],
[13, 20],
[3, 13, 18],
[13, 20],
[3, 13, 20] ];

bz_begin = [ [13, 18],
[3, 13, 20],
[13, 18],
[13, 20],
[3, 13, 18],
[13, 20],
[3, 13, 20] ];

bz_end = [ [16, 21],
[6, 16, 23],
[16, 21],
[16, 23],
[6, 16, 21],
[17, 23],
[6, 16, 23] ];
let bz_end = [ [16, 21],
[6, 16, 23],
[16, 21],
[16, 23],
[6, 16, 21],
[17, 23],
[6, 16, 23] ];

notified_10m = false;
let notified_10m = false;

function future_date(in_day, at_hour) {
let d = new Date();
Expand Down
2 changes: 1 addition & 1 deletion js/chartist-1.3.0.min.js

Large diffs are not rendered by default.

12 changes: 5 additions & 7 deletions js/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,22 @@
*
*/

import {__i18n__} from "../data/i18n_db.js"

(function() {
// automatic language detection if none is defined
if (localStorage.getItem("lang") !== null)
return;
// automatic language detection if none is defined
if (localStorage.getItem("lang") == null) {
let nav_lang = navigator.language.slice(0,2).toLowerCase();
let lang = __i18n__.supported_lang.includes(nav_lang) ? nav_lang : "en";
localStorage.setItem("lang", lang);
}
)();

const _ = function(string, ...p) {
export const _ = function(string, ...p) {
try {
// Note that it doesn't protect from localstorage manipulation
let lang = localStorage.getItem("lang");
if (lang != "en")
string = __i18n__[string][lang];
for (position in p)
for (let position in p)
string = string.replace("%s", p[position]);
return string;
}
Expand Down
2 changes: 1 addition & 1 deletion js/lamaiquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
* */

const $ = (function (selector) {
export const $ = (function (selector) {
return {
appendTo: function(target) {
let selector_node = document.querySelector(selector);
Expand Down
2 changes: 1 addition & 1 deletion js/lz-string.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6ffe3f3

Please sign in to comment.