Files
compiler-explorer/static/real-dark.ts
Matt Godbolt 8734c3e492 Update biome (#7956)
- latest biome, and fix its configuration
- fixes "static" content to be globally configured too (instead of
per-line)
- fixes issues:
  - imports fixed up
  - `Date.now()` vs `+new Date()`
  - some unused things `_` prefixed
 
After discussion with the team, turned off the unused parameter warning.
2025-07-28 10:34:46 -05:00

66 lines
2.0 KiB
TypeScript

import $ from 'jquery';
import {Hub} from './hub.js';
import * as local from './local.js';
import {Settings} from './settings.js';
const localKey = 'aprilfools2024';
function toggleButton() {
const theme = Settings.getStoredSettings().theme;
const date = new Date();
// month is 0-index and date is 1-indexed, because obviously that makes sense
const is_april_1 = date.getMonth() === 3 && date.getDate() === 1;
$('#true-dark .content').toggle(
is_april_1 && theme !== 'real-dark' && local.localStorage.get(localKey, '') !== 'hidden',
);
}
export function takeUsersOutOfRealDark() {
// take user out of real-dark in case they got stuck previously
if (Settings.getStoredSettings().theme === 'real-dark') {
const settings = Settings.getStoredSettings();
settings.theme = 'dark';
Settings.setStoredSettings(settings);
}
}
export function setupRealDark(hub: Hub) {
const overlay = $('#real-dark');
let overlay_on = false;
const toggleOverlay = () => {
const theme = Settings.getStoredSettings().theme;
overlay_on = theme === 'real-dark';
overlay.toggle(overlay_on);
};
const eventHub = hub.createEventHub();
eventHub.on('settingsChange', () => {
toggleButton();
toggleOverlay();
});
toggleButton();
toggleOverlay();
$('#true-dark .content').on('click', e => {
if (e.target.classList.contains('content')) {
// A little bit of a hack:
$('#settings .theme').val('real-dark').trigger('change');
}
});
$('#true-dark .content .dark-close').on('click', _e => {
local.localStorage.set(localKey, 'hidden');
toggleButton();
toggleOverlay();
});
window.addEventListener(
'mousemove',
e => {
if (overlay_on) {
overlay.css({top: e.pageY - window.innerHeight, left: e.pageX - window.innerWidth});
}
},
false,
);
}