(function () {
let speechRate = 1; // default speed
let selectedVoice = "UK English Male";
function blockQeTextInstant() {
const styleId = 'qetext-kill-style';
if (!document.getElementById(styleId)) {
const style = document.createElement('style');
style.id = styleId;
style.innerHTML = `
#qetext{
display:none !important;
visibility:hidden !important;
opacity:0 !important;
pointer-events:none !important;
position:absolute !important;
left:-9999px !important;
top:-9999px !important;
}
.voice-controls {
display:flex;
flex-direction:column;
gap:8px;
margin-top:10px;
width:100%;
}
.voice-controls select,
.voice-controls input {
width:100%;
padding:4px;
border-radius:4px;
border:none;
}
.speed-slider {
width:100%;
}
.audio-btn-row button {
transition: opacity 0.2s ease;
}
.audio-btn-row.st-stopped #pause,
.audio-btn-row.st-stopped #stop,
.audio-btn-row.st-stopped #resume,
.audio-btn-row.st-playing #play,
.audio-btn-row.st-playing #resume,
.audio-btn-row.st-paused #play,
.audio-btn-row.st-paused #pause,
.audio-btn-row.st-paused #stop {
opacity: 0.3 !important;
filter: grayscale(1);
cursor: not-allowed !important;
pointer-events: none !important;
}
`;
document.head.appendChild(style);
}
}
function applyFix() {
if (!document.body.classList.contains('template-product')) return;
const container = document.querySelector('.buttons');
const target = document.querySelector('.product-main .product-details .single-product-meta');
if (!container || !target) return;
blockQeTextInstant();
if (target.nextElementSibling !== container) {
target.parentNode.insertBefore(container, target.nextSibling);
}
container.style.cssText = `
display:flex !important;
flex-direction:column !important;
gap:10px !important;
margin-top:12px !important;
padding:12px !important;
background:#2e7d32 !important;
border-radius:8px !important;
width:260px !important;
`;
// Instruction
if (!container.querySelector('.audio-instruction')) {
const text = document.createElement('div');
text.className = "audio-instruction";
text.textContent = "Listen to product description";
text.style.color = "#fff";
container.prepend(text);
}
// --- CONTROL PANEL ---
if (!container.querySelector('.voice-controls')) {
const controls = document.createElement('div');
controls.className = "voice-controls";
controls.innerHTML = `
`;
container.appendChild(controls);
// Events
controls.querySelector('.speed-slider').addEventListener('input', (e) => {
speechRate = parseFloat(e.target.value);
});
controls.querySelector('.voice-select').addEventListener('change', (e) => {
selectedVoice = e.target.value;
});
controls.querySelector('.lang-select').addEventListener('change', (e) => {
selectedVoice = e.target.value;
});
}
// --- BUTTON LOGIC ---
const play = document.getElementById('play');
const pause = document.getElementById('pause');
const stop = document.getElementById('stop');
const resume = document.getElementById('resume');
const textEl = document.getElementById('qetext');
if (play && pause && stop && resume) {
const setPlaying = () => {
responsiveVoice.cancel();
responsiveVoice.speak(textEl.innerText, selectedVoice, {
rate: speechRate
});
};
if (!play.dataset.updated) {
play.addEventListener('click', setPlaying);
resume.addEventListener('click', () => {
responsiveVoice.resume();
});
pause.addEventListener('click', () => {
responsiveVoice.pause();
});
stop.addEventListener('click', () => {
responsiveVoice.cancel();
});
play.dataset.updated = "1";
}
}
}
let count = 0;
const interval = setInterval(() => {
applyFix();
if (++count > 40) clearInterval(interval);
}, 250);
const observer = new MutationObserver(() => applyFix());
observer.observe(document.body, {
childList: true,
subtree: true
});
})();
.template-index #start_button,
.template-collection #start_button,
.template-product #start_button,
body.template-index .buttons {
display: none !important;
}
.template-collection .buttons,
.template-product .buttons {
display: none !important;
}