var snapshot_layout = "portrait"; /* (portrait | landscape | full_screen | custom ) */ var snapshot_arrangement = "symbol_row"; /* (symbol_row | symbol_column ) */ let detectReloadSwipe = true; const include_reload_time_in_title = true; const include_time_elapsed_in_title = true; const clear_snapshot_before_reload = true; const snapshot_message_text_placeholder = 'SNAPSHOT-MESSAGE-TEXT-PLACEHOLDER'; const snapshot_message_html = '
' + snapshot_message_text_placeholder + '
'; const snapshot_wait_content = '
'; const include_crosshair_on_single_svg = true; const include_crosshair_on_multiple_svg = true; const crosshair_width = 0.5; const crosshair_height = 0.5; const crosshair_color_r = 255; const crosshair_color_g = 255; const crosshair_color_b = 255; const crosshair_color_a = 0.5; const crosshair_touch_delay = 500; const crosshair = "
"; const reloadDiv = ""; function load_snapshot_reload_delay_element(select_id, selected_reload_delay) { const reloadDelayElement = getElement(select_id); reloadDelayElement.innerHTML = ""; create_snapshot_reload_delay_option(reloadDelayElement, 'OFF', -1, (-1 === selected_reload_delay)); create_snapshot_reload_delay_option(reloadDelayElement, '30 Seconds', 30000, (30000 === selected_reload_delay)); create_snapshot_reload_delay_option(reloadDelayElement, '45 Seconds', 45000, (45000 === selected_reload_delay)); create_snapshot_reload_delay_option(reloadDelayElement, '60 Seconds', 60000, (60000 === selected_reload_delay)); create_snapshot_reload_delay_option(reloadDelayElement, '02 Minutes', 120000, (120000 === selected_reload_delay)); create_snapshot_reload_delay_option(reloadDelayElement, '03 Minutes', 180000, (180000 === selected_reload_delay)); create_snapshot_reload_delay_option(reloadDelayElement, '05 Minutes', 300000, (300000 === selected_reload_delay)); create_snapshot_reload_delay_option(reloadDelayElement, '10 Minutes', 600000, (600000 === selected_reload_delay)); create_snapshot_reload_delay_option(reloadDelayElement, '15 Minutes', 900000, (900000 === selected_reload_delay)); create_snapshot_reload_delay_option(reloadDelayElement, '30 Minutes', 1800000, (1800000 === selected_reload_delay)); create_snapshot_reload_delay_option(reloadDelayElement, '45 Minutes', 2700000, (2700000 === selected_reload_delay)); create_snapshot_reload_delay_option(reloadDelayElement, '60 Minutes', 3600000, (3600000 === selected_reload_delay)); } function create_snapshot_reload_delay_option(reloadDelayElement, name, value, selected) { var optionElement = document.createElement('option'); optionElement.innerHTML = name; optionElement.value = value; if (selected) { optionElement.selected = true; } reloadDelayElement.appendChild(optionElement); } function load_snapshot_arrangement_element(select_id, selected_arrangement) { const arrangementElement = getElement(select_id); arrangementElement.innerHTML = ""; add_arrangement_option(arrangementElement, "Symbol Row", "symbol_row", (selected_arrangement === "symbol_row")); add_arrangement_option(arrangementElement, "Symbol Column", "symbol_column", (selected_arrangement === "symbol_column")); } function add_arrangement_option(arrangement_element, name, value, selected) { var optionElement = document.createElement('option'); optionElement.innerHTML = name; optionElement.value = value; optionElement.selected = selected; arrangement_element.appendChild(optionElement); } function set_snapshot_arrangement(arrangement) { snapshot_arrangement = arrangement; } function load_snapshot_layout_element(select_id, selected_layout, filter_mobile_options) { const layoutElement = getElement(select_id); layoutElement.innerHTML = ""; if (!filter_mobile_options || !is_mobile_device) { add_layout_option(layoutElement, "Portrait", "portrait", (selected_layout === "portrait")); add_layout_option(layoutElement, "Landscape", "landscape", (selected_layout === "landscape")); } add_layout_option(layoutElement, "Full Screen", "full_screen", (is_mobile_device ? true : (selected_layout === "full_screen"))); if (!filter_mobile_options || !is_mobile_device) { add_layout_option(layoutElement, "Custom", "custom", (selected_layout === "custom")); } } function add_layout_option(layout_element, name, value, selected) { var optionElement = document.createElement('option'); optionElement.innerHTML = name; optionElement.value = value; optionElement.selected = selected; layout_element.appendChild(optionElement); } function set_snapshot_layout(layout) { snapshot_layout = layout; set_snapshot_custom_size_div('custom_size_div', layout); } function set_snapshot_custom_size_div(layout_custom_size_div_id, layout) { var layout_custom_size_div = getElement(layout_custom_size_div_id); if (layout === "custom") { layout_custom_size_div.style.display = "block"; } else { layout_custom_size_div.style.display = "none"; } } function createSnapshotAltContent(alt_content) { return snapshot_message_html.replace(snapshot_message_text_placeholder, alt_content); } function openSnapshotWindow() { return openSnapshotWindowOfLayout(snapshot_layout); } function openSnapshotWindowOfLayout(snapshot_layout) { var popup_width; var popup_height; if (typeof snapshot_layout !== 'undefined') { if (snapshot_layout === "portrait") { // same as app size popup_width = 400; popup_height = 600; } else if (snapshot_layout === "landscape") { if (window.screen.width && window.screen.height) { popup_width = window.screen.width - (window.screen.width / 2); popup_height = window.screen.height - (window.screen.height / 2); } else { popup_width = 1200; popup_height = 800; } } else if (snapshot_layout === "full_screen") { popup_width = window.screen.width; popup_height = window.screen.height; } else if (snapshot_layout === "custom") { var custom_width = getElement('custom_width'); var custom_height = getElement('custom_height'); popup_width = custom_width.value; popup_height = custom_height.value; } else { popup_width = window.screen.width; popup_height = window.screen.height; } } else { popup_width = 1200; popup_height = 800; } return openSnapshotWindowWithSize(popup_width, popup_height); } function openSnapshotWindowWithSize(popup_width, popup_height) { var x; var y; if (window.screen.width && window.screen.height) { x = (window.screen.width / 2) - (popup_width / 2); y = (window.screen.height / 2) - (popup_height / 2); } else { x = (window.innerWidth / 2) - (popup_width / 2); y = (window.innerHeight / 2) - (popup_height / 2); } const popupParams = "scrollbars=no,resizable=yes,status=no,location=no,toolbar=no,menubar=no,width=" + popup_width + ",height=" + popup_height + ",left=" + x + ",top=" + y; const popupName = "SNP" + Date.now(); const snapshotWindow = window.open('', popupName, popupParams); setSnapshotWindowStyle(snapshotWindow); return snapshotWindow; } function setSnapshotWindowStyle(snapshotWindow) { snapshotWindow.document.body.style.background = '#0a1b2c'; snapshotWindow.document.body.style.color = '#7c7c7c'; snapshotWindow.document.body.style.fontSize = '18px'; snapshotWindow.document.body.style.fontFamily = 'Arial, Helvetica, sans-serif'; snapshotWindow.document.body.style.margin = 0; snapshotWindow.document.body.style.padding = 0; } function closeSnapshotWindowFunction(snapshotWindow) { if (snapshotWindow && !snapshotWindow.closed) { return function closeSnapshotWindow() { if (snapshotWindow) { snapshotWindow.close(); } }; } } async function setSnapshots(snapshotWindow, snapshots, arrangement, message_box_id) { try { if (snapshotWindow.closed) { return; } const snapshotItems = new Array(); const snapshotTimeframes = new Array(); for (var i = 0; i < snapshots.length; i++) { if (!snapshotItems.includes(snapshots[i].item)) { snapshotItems.push(snapshots[i].item); } if (!snapshotTimeframes.includes(snapshots[i].timeframe)) { snapshotTimeframes.push(snapshots[i].timeframe); } } const arrangedSnapshots = new Array(); var snapshotHeight; var snapshotWidth; if (arrangement === 'symbol_row') { for (var i = 0; i < snapshotItems.length; i++) { const snapshotItem = snapshotItems[i]; for (var j = 0; j < snapshots.length; j++) { if (snapshotItem === snapshots[j].item) { arrangedSnapshots.push(snapshots[j]); } } } snapshotHeight = (100 / snapshotItems.length); snapshotWidth = (100 / snapshotTimeframes.length); } else if (arrangement === 'symbol_column') { for (var i = 0; i < snapshotTimeframes.length; i++) { const snapshotTimeframe = snapshotTimeframes[i]; for (var j = 0; j < snapshots.length; j++) { if (snapshotTimeframe === snapshots[j].timeframe) { arrangedSnapshots.push(snapshots[j]); } } } snapshotHeight = (100 / snapshotTimeframes.length); snapshotWidth = (100 / snapshotItems.length); } else { snapshotWindow.document.body.innerHTML = createSnapshotAltContent("Arrangement is not supported: " + arrangement); return; } var title = snapshotItems.length === 1 ? snapshots[0].item : ""; title += snapshotTimeframes.length === 1 ? ((snapshotItems.length === 1 ? " - " : "") + snapshots[0].timeframe) : ""; if (title === "") { title = "Combo"; } snapshotWindow.document.title = title; for (i = 0; i < arrangedSnapshots.length; i++) { const snapshotObject = arrangedSnapshots[i]; var encoded = snapshotObject.encoded; var data = snapshotObject.data; var format; if (snapshotObject.format.endsWith("png")) { format = "png"; } else if (snapshotObject.format.endsWith("jpeg")) { format = "jpeg"; } else if (snapshotObject.format.endsWith("svg")) { format = "svg"; } else if (snapshotObject.format.endsWith("html")) { format = "html"; } else { snapshotWindow.document.body.innerHTML = createSnapshotAltContent("Format is not supported in web application. " + snapshotObject.format); return; } // if (snapshotObject.compressed) { if (!encoded) { snapshotWindow.document.body.innerHTML = createSnapshotAltContent("Compressed document is not encoded. " + format); return; } if (format === "png" || format === "jpeg") { snapshotWindow.document.body.innerHTML = createSnapshotAltContent(format + "'s compression is not supported"); return; } if (!isCompressionSupported()) { snapshotWindow.document.body.innerHTML = createSnapshotAltContent("Compression is not supported on your device or browser. You can only use PNG format."); return; } await unzipGzipString(data, encoded).then((unzipped) => { data = unzipped; encoded = false; }).catch((error) => { console.error("Error unzipping:", error); throw error; }); } if (!snapshotObject.encoded) { if (format === "png" || format === "jpeg") { snapshotWindow.document.body.innerHTML = createSnapshotAltContent(format + " is not encoded"); return; } } var snapshot_element_id = 'snapshot_' + i; if (format === "png" || format === "jpeg") { const img = ""; snapshotWindow.document.body.innerHTML = i === 0 ? img : (snapshotWindow.document.body.innerHTML + img); const snapshot_image = snapshotWindow.document.getElementById(snapshot_element_id); snapshot_image.focus(); } else if (format === "svg" || format === "html") { if (encoded) { data = window.atob(data); } var frame = "