Le premier test est passé avec les heures fixes.
@Carabidouille @Pokemon @Foutreglacial
On peut définir les heures en éditant dans les premières lignes:
const FIXED_TIME = {
start: '21:30',
end: '07:00',
};
Je vais tester le reste (c'est vibe-codé)
// ==UserScript==
// @name Onche - Logo NOCHE nuit
// @namespace
https://onche.org/
// @version 1.0.0
// @description Remplace le logo ONCHE par NOCHE la nuit
// @match
https://onche.org/*
// @match
https://www.onche.org/*
// @run-at document-start
// @grant GM_addStyle
// ==/UserScript==
(() => {
'use strict';
/*
* Choisir UNE option :
*
* "fixed" => heures fixes
* "manual-gps" => coordonnées GPS définies ici
* "browser-gps" => demande la position au navigateur
*
* Le site ne demandera PAS la position si MODE !== "browser-gps".
*/
const MODE = 'fixed';
const LOGOS = {
full: '
https://cloud.onche.org/f[...]8-de1016900364!N41NKClnyQ',
reduced: '
https://cloud.onche.org/e[...]7-d0186a8adc24!K3NiAFzcy0',
};
const FIXED_TIME = {
start: '21:30',
end: '07:00',
};
const MANUAL_GPS = {
latitude: null, // Exemple : 48.8566
longitude: null, // Exemple : 2.3522
offsetMinutesAfterSunset: 30,
};
const BROWSER_GPS = {
offsetMinutesAfterSunset: 30,
cacheHours: 24,
timeoutMs: 8000,
};
const NIGHT_CLASS = 'noche-logo-night';
addStyle(`
html.${NIGHT_CLASS} header .logo .image {
background-image: url("${LOGOS.full}") !important;
background-position: center !important;
background-repeat: no-repeat !important;
background-size: contain !important;
}
@media (max-width: 880px) {
html.${NIGHT_CLASS} header .logo .image {
background-image: url("${LOGOS.reduced}") !important;
background-position: center !important;
background-repeat: no-repeat !important;
background-size: auto 28px !important;
}
}
`);
function addStyle(css) {
if (typeof GM_addStyle === 'function') {
GM_addStyle(css);
return;
}
const style = document.createElement('style');
style.textContent = css;
const append = () => {
(document.head || document.documentElement).appendChild(style);
};
if (document.head) append();
else document.addEventListener('DOMContentLoaded', append, { once: true });
}
function setNightLogo(enabled) {
document.documentElement.classList.toggle(NIGHT_CLASS, enabled);
}
function parseTimeToMinutes(value) {
const [hours, minutes] = value.split(':').map(Number);
return hours * 60 + minutes;
}
function isNightFixed(now = new Date()) {
const current = now.getHours() * 60 + now.getMinutes();
const start = parseTimeToMinutes(FIXED_TIME.start);
const end = parseTimeToMinutes(FIXED_TIME.end);
if (start < end) {
return current >= start && current < end;
}
return current >= start || current < end;
}
function dayOfYear(date) {
const start = new Date(date.getFullYear(), 0, 0);
const diff = date - start;
return Math.floor(diff / 86400000);
}
function normalizeDegrees(value) {
return ((value % 360) + 360) % 360;
}
function degToRad(value) {
return value * Math.PI / 180;
}
function radToDeg(value) {
return value * 180 / Math.PI;
}
function calculateSunTime(date, latitude, longitude, isSunrise) {
const zenith = 90.833;
const n = dayOfYear(date);
const lngHour = longitude / 15;
const approxTime = n + ((isSunrise ? 6 : 18) - lngHour) / 24;
const meanAnomaly = (0.9856 * approxTime) - 3.289;
let trueLongitude =
meanAnomaly +
(1.916 * Math.sin(degToRad(meanAnomaly))) +
(0.020 * Math.sin(degToRad(2 * meanAnomaly))) +
282.634;
trueLongitude = normalizeDegrees(trueLongitude);
let rightAscension = radToDeg(Math.atan(0.91764 * Math.tan(degToRad(trueLongitude))));
rightAscension = normalizeDegrees(rightAscension);
const lQuadrant = Math.floor(trueLongitude / 90) * 90;
const raQuadrant = Math.floor(rightAscension / 90) * 90;
rightAscension = (rightAscension + lQuadrant - raQuadrant) / 15;
const sinDec = 0.39782 * Math.sin(degToRad(trueLongitude));
const cosDec = Math.cos(Math.asin(sinDec));
const cosHour =
(Math.cos(degToRad(zenith)) - (sinDec * Math.sin(degToRad(latitude)))) /
(cosDec * Math.cos(degToRad(latitude)));
if (cosHour > 1 || cosHour < -1) {
return null;
}
let hourAngle;
if (isSunrise) {
hourAngle = 360 - radToDeg(Math.acos(cosHour));
} else {
hourAngle = radToDeg(Math.acos(cosHour));
}
hourAngle /= 15;
const localMeanTime =
hourAngle +
rightAscension -
(0.06571 * approxTime) -
6.622;
const utcHour = ((localMeanTime - lngHour) % 24 + 24) % 24;
const result = new Date(Date.UTC(
date.getFullYear(),
date.getMonth(),
date.getDate(),
0,
0,
0,
0
));
const hours = Math.floor(utcHour);
const minutes = Math.floor((utcHour - hours) * 60);
const seconds = Math.floor((((utcHour - hours) * 60) - minutes) * 60);
result.setUTCHours(hours, minutes, seconds, 0);
return result;
}
function isNightBySun(latitude, longitude, offsetMinutesAfterSunset, now = new Date()) {
const sunrise = calculateSunTime(now, latitude, longitude, true);
const sunset = calculateSunTime(now, latitude, longitude, false);
if (!sunrise || !sunset) {
console.warn('[NOCHE] Impossible de calculer lever/coucher du soleil pour ces coordonnées.');
return false;
}
const nightStart = new Date(sunset.getTime() + offsetMinutesAfterSunset * 60000);
return now >= nightStart || now < sunrise;
}
function readCachedPosition() {
try {
const raw = localStorage.getItem('noche-logo-position');
if (!raw) return null;
const cached = JSON.parse(raw);
const maxAgeMs = BROWSER_GPS.cacheHours * 60 * 60 * 1000;
if (Date.now() - cached.savedAt > maxAgeMs) {
return null;
}
if (
typeof cached.latitude !== 'number' ||
typeof cached.longitude !== 'number'
) {
return null;
}
return cached;
} catch {
return null;
}
}
function saveCachedPosition(latitude, longitude) {
try {
localStorage.setItem('noche-logo-position', JSON.stringify({
latitude,
longitude,
savedAt: Date.now(),
}));
} catch {
// Pas grave.
}
}
function getBrowserPosition() {
return new Promise((resolve, reject) => {
const cached = readCachedPosition();
if (cached) {
resolve(cached);
return;
}
if (!navigator.geolocation) {
reject(new Error('Géolocalisation non disponible.'));
return;
}
navigator.geolocation.getCurrentPosition(
position => {
const coords = {
latitude: position.coords.latitude,
longitude: position.coords.longitude,
};
saveCachedPosition(coords.latitude, coords.longitude);
resolve(coords);
},
reject,
{
enableHighAccuracy: false,
timeout: BROWSER_GPS.timeoutMs,
maximumAge: BROWSER_GPS.cacheHours * 60 * 60 * 1000,
}
);
});
}
async function computeNight() {
if (MODE === 'fixed') {
return isNightFixed();
}
if (MODE === 'manual-gps') {
if (
typeof MANUAL_GPS.latitude !== 'number' ||
typeof MANUAL_GPS.longitude !== 'number'
) {
console.warn('[NOCHE] MODE manual-gps choisi, mais latitude/longitude non définies.');
return false;
}
return isNightBySun(
MANUAL_GPS.latitude,
MANUAL_GPS.longitude,
MANUAL_GPS.offsetMinutesAfterSunset
);
}
if (MODE === 'browser-gps') {
const position = await getBrowserPosition();
return isNightBySun(
position.latitude,
position.longitude,
BROWSER_GPS.offsetMinutesAfterSunset
);
}
console.warn(`[NOCHE] MODE inconnu : ${MODE}`);
return false;
}
async function refreshLogo() {
try {
const night = await computeNight();
setNightLogo(night);
} catch (error) {
console.warn('[NOCHE] Erreur:', error);
setNightLogo(false);
}
}
refreshLogo();
setInterval(refreshLogo, 60 * 1000);
})();
@Carabidouille @Pokemon @Foutreglacial
On peut définir les heures en éditant dans les premières lignes:
const FIXED_TIME = {
start: '21:30',
end: '07:00',
};
Je vais tester le reste (c'est vibe-codé)
userscript
// ==UserScript==
// @name Onche - Logo NOCHE nuit
// @namespace
// @version 1.0.0
// @description Remplace le logo ONCHE par NOCHE la nuit
// @match
// @match
// @run-at document-start
// @grant GM_addStyle
// ==/UserScript==
(() => {
'use strict';
/*
* Choisir UNE option :
*
* "fixed" => heures fixes
* "manual-gps" => coordonnées GPS définies ici
* "browser-gps" => demande la position au navigateur
*
* Le site ne demandera PAS la position si MODE !== "browser-gps".
*/
const MODE = 'fixed';
const LOGOS = {
full: '
reduced: '
};
const FIXED_TIME = {
start: '21:30',
end: '07:00',
};
const MANUAL_GPS = {
latitude: null, // Exemple : 48.8566
longitude: null, // Exemple : 2.3522
offsetMinutesAfterSunset: 30,
};
const BROWSER_GPS = {
offsetMinutesAfterSunset: 30,
cacheHours: 24,
timeoutMs: 8000,
};
const NIGHT_CLASS = 'noche-logo-night';
addStyle(`
html.${NIGHT_CLASS} header .logo .image {
background-image: url("${LOGOS.full}") !important;
background-position: center !important;
background-repeat: no-repeat !important;
background-size: contain !important;
}
@media (max-width: 880px) {
html.${NIGHT_CLASS} header .logo .image {
background-image: url("${LOGOS.reduced}") !important;
background-position: center !important;
background-repeat: no-repeat !important;
background-size: auto 28px !important;
}
}
`);
function addStyle(css) {
if (typeof GM_addStyle === 'function') {
GM_addStyle(css);
return;
}
const style = document.createElement('style');
style.textContent = css;
const append = () => {
(document.head || document.documentElement).appendChild(style);
};
if (document.head) append();
else document.addEventListener('DOMContentLoaded', append, { once: true });
}
function setNightLogo(enabled) {
document.documentElement.classList.toggle(NIGHT_CLASS, enabled);
}
function parseTimeToMinutes(value) {
const [hours, minutes] = value.split(':').map(Number);
return hours * 60 + minutes;
}
function isNightFixed(now = new Date()) {
const current = now.getHours() * 60 + now.getMinutes();
const start = parseTimeToMinutes(FIXED_TIME.start);
const end = parseTimeToMinutes(FIXED_TIME.end);
if (start < end) {
return current >= start && current < end;
}
return current >= start || current < end;
}
function dayOfYear(date) {
const start = new Date(date.getFullYear(), 0, 0);
const diff = date - start;
return Math.floor(diff / 86400000);
}
function normalizeDegrees(value) {
return ((value % 360) + 360) % 360;
}
function degToRad(value) {
return value * Math.PI / 180;
}
function radToDeg(value) {
return value * 180 / Math.PI;
}
function calculateSunTime(date, latitude, longitude, isSunrise) {
const zenith = 90.833;
const n = dayOfYear(date);
const lngHour = longitude / 15;
const approxTime = n + ((isSunrise ? 6 : 18) - lngHour) / 24;
const meanAnomaly = (0.9856 * approxTime) - 3.289;
let trueLongitude =
meanAnomaly +
(1.916 * Math.sin(degToRad(meanAnomaly))) +
(0.020 * Math.sin(degToRad(2 * meanAnomaly))) +
282.634;
trueLongitude = normalizeDegrees(trueLongitude);
let rightAscension = radToDeg(Math.atan(0.91764 * Math.tan(degToRad(trueLongitude))));
rightAscension = normalizeDegrees(rightAscension);
const lQuadrant = Math.floor(trueLongitude / 90) * 90;
const raQuadrant = Math.floor(rightAscension / 90) * 90;
rightAscension = (rightAscension + lQuadrant - raQuadrant) / 15;
const sinDec = 0.39782 * Math.sin(degToRad(trueLongitude));
const cosDec = Math.cos(Math.asin(sinDec));
const cosHour =
(Math.cos(degToRad(zenith)) - (sinDec * Math.sin(degToRad(latitude)))) /
(cosDec * Math.cos(degToRad(latitude)));
if (cosHour > 1 || cosHour < -1) {
return null;
}
let hourAngle;
if (isSunrise) {
hourAngle = 360 - radToDeg(Math.acos(cosHour));
} else {
hourAngle = radToDeg(Math.acos(cosHour));
}
hourAngle /= 15;
const localMeanTime =
hourAngle +
rightAscension -
(0.06571 * approxTime) -
6.622;
const utcHour = ((localMeanTime - lngHour) % 24 + 24) % 24;
const result = new Date(Date.UTC(
date.getFullYear(),
date.getMonth(),
date.getDate(),
0,
0,
0,
0
));
const hours = Math.floor(utcHour);
const minutes = Math.floor((utcHour - hours) * 60);
const seconds = Math.floor((((utcHour - hours) * 60) - minutes) * 60);
result.setUTCHours(hours, minutes, seconds, 0);
return result;
}
function isNightBySun(latitude, longitude, offsetMinutesAfterSunset, now = new Date()) {
const sunrise = calculateSunTime(now, latitude, longitude, true);
const sunset = calculateSunTime(now, latitude, longitude, false);
if (!sunrise || !sunset) {
console.warn('[NOCHE] Impossible de calculer lever/coucher du soleil pour ces coordonnées.');
return false;
}
const nightStart = new Date(sunset.getTime() + offsetMinutesAfterSunset * 60000);
return now >= nightStart || now < sunrise;
}
function readCachedPosition() {
try {
const raw = localStorage.getItem('noche-logo-position');
if (!raw) return null;
const cached = JSON.parse(raw);
const maxAgeMs = BROWSER_GPS.cacheHours * 60 * 60 * 1000;
if (Date.now() - cached.savedAt > maxAgeMs) {
return null;
}
if (
typeof cached.latitude !== 'number' ||
typeof cached.longitude !== 'number'
) {
return null;
}
return cached;
} catch {
return null;
}
}
function saveCachedPosition(latitude, longitude) {
try {
localStorage.setItem('noche-logo-position', JSON.stringify({
latitude,
longitude,
savedAt: Date.now(),
}));
} catch {
// Pas grave.
}
}
function getBrowserPosition() {
return new Promise((resolve, reject) => {
const cached = readCachedPosition();
if (cached) {
resolve(cached);
return;
}
if (!navigator.geolocation) {
reject(new Error('Géolocalisation non disponible.'));
return;
}
navigator.geolocation.getCurrentPosition(
position => {
const coords = {
latitude: position.coords.latitude,
longitude: position.coords.longitude,
};
saveCachedPosition(coords.latitude, coords.longitude);
resolve(coords);
},
reject,
{
enableHighAccuracy: false,
timeout: BROWSER_GPS.timeoutMs,
maximumAge: BROWSER_GPS.cacheHours * 60 * 60 * 1000,
}
);
});
}
async function computeNight() {
if (MODE === 'fixed') {
return isNightFixed();
}
if (MODE === 'manual-gps') {
if (
typeof MANUAL_GPS.latitude !== 'number' ||
typeof MANUAL_GPS.longitude !== 'number'
) {
console.warn('[NOCHE] MODE manual-gps choisi, mais latitude/longitude non définies.');
return false;
}
return isNightBySun(
MANUAL_GPS.latitude,
MANUAL_GPS.longitude,
MANUAL_GPS.offsetMinutesAfterSunset
);
}
if (MODE === 'browser-gps') {
const position = await getBrowserPosition();
return isNightBySun(
position.latitude,
position.longitude,
BROWSER_GPS.offsetMinutesAfterSunset
);
}
console.warn(`[NOCHE] MODE inconnu : ${MODE}`);
return false;
}
async function refreshLogo() {
try {
const night = await computeNight();
setNightLogo(night);
} catch (error) {
console.warn('[NOCHE] Erreur:', error);
setNightLogo(false);
}
}
refreshLogo();
setInterval(refreshLogo, 60 * 1000);
})();
ça a l'air compliqué comme truc
Ceux qui n'aiment pas sucer des chibres féminins sont tous PD
il y a un jour
Sponsorisé
Connectez-vous pour masquer les pubsça a l'air compliqué comme truc
T'installes violentmonkey et tu le colles dedans ou tampermonkey (le premier c'est pour brave, ça bug pas).
Ca va faire tourner le code sur le navigateur, sur la page.
Après, tu peux le passer dans una IA pour demander ce que ça fait, si tu veux éviter les fuites
Cum My Fanatics
Ca va faire tourner le code sur le navigateur, sur la page.
Après, tu peux le passer dans una IA pour demander ce que ça fait, si tu veux éviter les fuites
il y a un jour
Il est pas mal
Le userscript fonctionne, si vous avez des questions, j'y répondrais.
En gros on renseigne un mode au début:
/*
* Choisir UNE option :
*
* "fixed" => heures fixes
* "manual-gps" => coordonnées GPS définies ici
* "browser-gps" => demande la position au navigateur
*
* Le site ne demandera PAS la position si MODE !== "browser-gps".
*/
const MODE = 'browser-gps';
Pour fixed, il faudra renseigner les horaires manuellement:
const FIXED_TIME = {
start: '16:10',
end: '16:12',
};
Pour le mode "manuel-gps" on renseigne ses coordonnées:
const MANUAL_GPS = {
latitude: null, // Exemple : 48.8566
longitude: null, // Exemple : 2.3522
offsetMinutesAfterSunset: 30, // ça si on veut décaler un peu le logo nuit
};
Cum My Fanatics
En gros on renseigne un mode au début:
/*
* Choisir UNE option :
*
* "fixed" => heures fixes
* "manual-gps" => coordonnées GPS définies ici
* "browser-gps" => demande la position au navigateur
*
* Le site ne demandera PAS la position si MODE !== "browser-gps".
*/
const MODE = 'browser-gps';
Pour fixed, il faudra renseigner les horaires manuellement:
const FIXED_TIME = {
start: '16:10',
end: '16:12',
};
Pour le mode "manuel-gps" on renseigne ses coordonnées:
const MANUAL_GPS = {
latitude: null, // Exemple : 48.8566
longitude: null, // Exemple : 2.3522
offsetMinutesAfterSunset: 30, // ça si on veut décaler un peu le logo nuit
};
il y a 6 heures
ça a l'air compliqué comme truc
Le userscript fonctionne, si vous avez des questions, j'y répondrais.
En gros on renseigne un mode au début:
/*
* Choisir UNE option :
*
* "fixed" => heures fixes
* "manual-gps" => coordonnées GPS définies ici
* "browser-gps" => demande la position au navigateur
*
* Le site ne demandera PAS la position si MODE !== "browser-gps".
*/
const MODE = 'browser-gps';
Pour fixed, il faudra renseigner les horaires manuellement:
const FIXED_TIME = {
start: '16:10',
end: '16:12',
};
Pour le mode "manuel-gps" on renseigne ses coordonnées:
const MANUAL_GPS = {
latitude: null, // Exemple : 48.8566
longitude: null, // Exemple : 2.3522
offsetMinutesAfterSunset: 30, // ça si on veut décaler un peu le logo nuit
};
En gros on renseigne un mode au début:
/*
* Choisir UNE option :
*
* "fixed" => heures fixes
* "manual-gps" => coordonnées GPS définies ici
* "browser-gps" => demande la position au navigateur
*
* Le site ne demandera PAS la position si MODE !== "browser-gps".
*/
const MODE = 'browser-gps';
Pour fixed, il faudra renseigner les horaires manuellement:
const FIXED_TIME = {
start: '16:10',
end: '16:12',
};
Pour le mode "manuel-gps" on renseigne ses coordonnées:
const MANUAL_GPS = {
latitude: null, // Exemple : 48.8566
longitude: null, // Exemple : 2.3522
offsetMinutesAfterSunset: 30, // ça si on veut décaler un peu le logo nuit
};
Au cas où
Pour l'installer, ça passe par l'extension violentmonkey par exemple: On clique dessus, on clique sur "+" et on le colle dedans.
Bien entendu, après avoir passé le script dans une IA pour savoir ce que ça fait
Je ne suis pas un Zazou, mais vous devriez avoir cette habitude en général
il y a 6 heures
En ligne
244
Sur ce sujet0









