top of page
bottom of page
(function(){
if (window.__cnJeuxScoreHudV1) return;
window.__cnJeuxScoreHudV1 = true;
var state = { score: 'Score: 0', best: 'Best: ' + (localStorage.getItem('carrementnous_dodge_ball_best_score') || localStorage.getItem('bestScore') || '0') };
function isJeuxPage(){
return //jeux(?:$|[?#/])/.test(window.location.pathname + window.location.search + window.location.hash);
}
function gameIframe(){
return document.querySelector('iframe[title="GAME DODGE BALL"]');
}
function ensureHud(){
var hud = document.getElementById('cn-game-score-hud');
if (!hud) {
hud = document.createElement('div');
hud.id = 'cn-game-score-hud';
hud.innerHTML = ' ';
document.body.appendChild(hud);
var s = hud.style;
s.position = 'fixed';
s.zIndex = '999999';
s.display = 'none';
s.alignItems = 'center';
s.justifyContent = 'space-between';
s.gap = '8px';
s.boxSizing = 'border-box';
s.pointerEvents = 'none';
s.color = '#fff';
s.background = 'rgba(0,0,0,.78)';
s.border = '1px solid rgba(255,255,255,.55)';
s.borderRadius = '4px';
s.padding = '3px 6px';
s.fontFamily = 'monospace';
s.fontWeight = '800';
s.lineHeight = '1.1';
s.textShadow = '0 1px 2px #000';
}
var left = hud.querySelector('.cn-score-left');
var right = hud.querySelector('.cn-score-right');
if (left) left.textContent = state.score.replace('Score:', 'Score :');
if (right) right.textContent = state.best.replace('Best:', 'Best :');
return hud;
}
function positionHud(){
var hud = ensureHud();
if (!isJeuxPage()) {
hud.style.display = 'none';
return;
}
var iframe = gameIframe();
if (!iframe) {
hud.style.display = 'none';
return;
}
var canvasRect = null;
var frameWidth = 0;
try {
var doc = iframe.contentDocument;
var canvas = doc && doc.getElementById('game');
if (canvas) {
var cr = canvas.getBoundingClientRect();
canvasRect = { x: cr.x, y: cr.y, width: cr.width, height: cr.height };
frameWidth = iframe.contentWindow.innerWidth || 0;
}
} catch (e) {}
if (!canvasRect || !frameWidth) {
hud.style.display = 'none';
return;
}
var ir = iframe.getBoundingClientRect();
var scale = ir.width / frameWidth;
var leftPos = ir.left + canvasRect.x * scale;
var topPos = ir.top + canvasRect.y * scale + 3;
var width = canvasRect.width * scale;
hud.style.display = 'flex';
hud.style.left = Math.round(leftPos) + 'px';
hud.style.top = Math.round(topPos) + 'px';
hud.style.width = Math.round(width) + 'px';
hud.style.height = Math.max(18, Math.round(24 * Math.min(1, Math.max(.78, scale + .28)))) + 'px';
hud.style.fontSize = Math.max(10, Math.min(13, Math.round(width / 16))) + 'px';
}
function injectScoreBridge(){
if (!isJeuxPage()) return false;
var iframe = gameIframe();
if (!iframe) return false;
try {
var win = iframe.contentWindow;
if (!win || win.__cnScorePostPatchV1) return true;
if (!win.CanvasRenderingContext2D) return false;
win.__cnScorePostPatchV1 = true;
var proto = win.CanvasRenderingContext2D.prototype;
var originalFillText = proto.fillText;
proto.fillText = function(text, x, y, maxWidth){
try {
var txt = String(text || '');
if (/^Score:/i.test(txt)) win.parent.postMessage({ type: 'cnDodgeScoreHud', score: txt }, '*');
if (/^Best:/i.test(txt)) win.parent.postMessage({ type: 'cnDodgeScoreHud', best: txt }, '*');
} catch (e) {}
return originalFillText.apply(this, arguments);
};
return true;
} catch (e) {
return false;
}
}
window.addEventListener('message', function(e){
if (!e.data || e.data.type !== 'cnDodgeScoreHud') return;
if (e.data.score) state.score = e.data.score;
if (e.data.best) state.best = e.data.best;
positionHud();
});
function tick(){
injectScoreBridge();
positionHud();
}
window.addEventListener('resize', positionHud, { passive: true });
window.addEventListener('scroll', positionHud, { passive: true });
setInterval(tick, 500);
setTimeout(tick, 250);
setTimeout(tick, 1000);
setTimeout(tick, 2500);
})();