<style>
ul.lettered li {
list-style: lower-alpha!important;
}
</style>
<script>
function loadMergedHtml(options) {
const target = document.querySelector(options.target);
const remoteHtmlUrl = options.url;
const fields = options.lottery_specifics || {};
const fallbacks = options.fallbacks || {};
if (!target || !remoteHtmlUrl) return;
function getMergeValue(fieldName) {
if (Object.prototype.hasOwnProperty.call(fields, fieldName)) {
return String(fields[fieldName]);
}
if (Object.prototype.hasOwnProperty.call(fallbacks, fieldName)) {
return String(fallbacks[fieldName]);
}
return "";
}
function normaliseConditionalValue(value) {
return String(value)
.trim()
.replace(/^["']|["']$/g, "")
.trim()
.toUpperCase();
}
fetch(remoteHtmlUrl)
.then(function (response) {
if (!response.ok) {
throw new Error("Could not load remote HTML");
}
return response.text();
})
.then(function (html) {
// Process IF blocks first
html = html.replace(
/\*\|IF:([A-Za-z0-9_]+)\s*=\s*([^|]+?)\|\*([\s\S]*?)\*\|END:IF\|\*/g,
function (match, fieldName, expectedValue, content) {
const actualValue = getMergeValue(fieldName);
const actualNormalised = normaliseConditionalValue(actualValue);
const expectedNormalised = normaliseConditionalValue(expectedValue);
return actualNormalised === expectedNormalised ? content : "";
}
);
// Then process normal merge fields
html = html.replace(/\*\|([A-Za-z0-9_]+)\|\*/g, function (match, fieldName) {
if (Object.prototype.hasOwnProperty.call(fields, fieldName)) {
return String(fields[fieldName]);
}
if (Object.prototype.hasOwnProperty.call(fallbacks, fieldName)) {
return String(fallbacks[fieldName]);
}
return '<span style="color:red;font-weight:bold;font-size:2em;">' + match + '</span>';
});
target.innerHTML = html;
})
.catch(function (error) {
console.error("Remote HTML merge error:", error);
});
}
loadMergedHtml({
target: "#rulesContent",
url: "https://files.charitylotteries.co.uk/sites/unity/rules_live.html",
lottery_specifics: {
CHARITY_NAME: "Debra"
},
fallbacks: {
RULES_URL: window.location.hostname,
CHARITY_NAME: "Unity",
MAX_CHANCES_DECIMAL: "20.00",
HAS_CARDS: "Y",
HAS_OB: "Y",
HAS_GV: "Y"
}
});
</script>