Files
klz-cables.com/test-decode.js
2026-01-06 13:55:04 +01:00

45 lines
1.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const decodeContent = (html) => {
if (!html) return html;
// Decode numeric HTML entities first
let decoded = html
.replace(/"/g, '"') // ” - Right double quote
.replace(/"/g, '"') // “ - Left double quote
.replace(/'/g, "'") // - Right single quote
.replace(/'/g, "'") // - Left single quote
.replace(//g, '-') // - En dash
.replace(/—/g, '—') // — - Em dash
.replace(/…/g, '…') // … - Ellipsis
.replace(/"/g, '"') // ″ - Double quote
.replace(/'/g, "'") // - Single quote
// Decode Unicode characters
.replace(/”/g, '"') // Right double quote
.replace(/“/g, '"') // Left double quote
.replace(//g, "'") // Left single quote
.replace(//g, "'") // Right single quote
.replace(//g, '-') // En dash
.replace(/—/g, '—') // — - Em dash
.replace(/…/g, '…') // … - Ellipsis
.replace(/″/g, '"') // Double quote
.replace(//g, "'") // Single quote
// Decode named HTML entities
.replace(/"/g, '"')
.replace(/'/g, "'");
// Also handle any remaining numeric entities
decoded = decoded.replace(/&#(\d+);/g, (match, code) => {
return String.fromCharCode(parseInt(code, 10));
});
return decoded;
};
const raw = 'video_mp4=”https://klz-cables.com/wp-content/uploads/2025/02/header.mp4”';
console.log('Raw:', raw);
console.log('Decoded:', decodeContent(raw));
const raw2 = 'video_mp4=”https://klz-cables.com/wp-content/uploads/2025/02/header.mp4”';
console.log('\nRaw2:', raw2);
console.log('Decoded2:', decodeContent(raw2));