Dash
Items
Custom JavaScript
Save
Cancel
$(document).ready(function () { const base = (document.querySelector("base") || {}).href; const container = $("#sortable"); const liveStats = () => { let hidden, visibilityChange; if (typeof document.hidden !== "undefined") { // Opera 12.10 and Firefox 18 and later support hidden = "hidden"; visibilityChange = "visibilitychange"; } else if (typeof document.msHidden !== "undefined") { hidden = "msHidden"; visibilityChange = "msvisibilitychange"; } else if (typeof document.webkitHidden !== "undefined") { hidden = "webkitHidden"; visibilityChange = "webkitvisibilitychange"; } const livestatsRefreshTimeouts = []; const livestatsFuncs = []; const livestatsContainers = $(".livestats-container"); function stopLivestatsRefresh() { for ( let _i = 0, _livestatsRefreshTime = livestatsRefreshTimeouts; _i < _livestatsRefreshTime.length; _i++ ) { const timeoutId = _livestatsRefreshTime[_i]; window.clearTimeout(timeoutId); } } function startLivestatsRefresh() { for ( let _i2 = 0, _livestatsFuncs = livestatsFuncs; _i2 < _livestatsFuncs.length; _i2++ ) { const fun = _livestatsFuncs[_i2]; fun(); } } if (livestatsContainers.length > 0) { if ( typeof document.addEventListener === "undefined" || hidden === undefined ) { console.log("This browser does not support visibilityChange"); } else { document.addEventListener( visibilityChange, function () { if (document[hidden]) { stopLivestatsRefresh(); } else { startLivestatsRefresh(); } }, false ); } livestatsContainers.each(function (index) { const id = $(this).data("id"); const dataonly = $(this).data("dataonly"); const increaseby = dataonly == 1 ? 20000 : 1000; const container = $(this); const max_timer = 30000; let timer = 5000; const fun = function worker() { $.ajax({ url: base + "get_stats/" + id, dataType: "json", success: function success(data) { container.html(data.html); if (data.status == "active") timer = increaseby; else { if (timer < max_timer) timer += 2000; } }, complete: function complete() { // Schedule the next request when the current one's complete livestatsRefreshTimeouts[index] = window.setTimeout( worker, timer ); }, }); }; livestatsFuncs[index] = fun; fun(); }); } }; const customMain = () => { if (window.location.pathname !== "/") return; container.html(""); container.css("opacity", "1"); $.get(base + "tags", function (data) { const tagArr = Array.from($("tbody tr td a", data)); tags = tagArr .filter((_d, idx) => idx % 2 === 0) .map((node) => node.href.split("/").pop()); const tagPromises = tags.map((tag) => $.get(base + "tag/" + tag)); if (tags.length === 0) return; Promise.all(tagPromises) .then((tagsHtml) => { const tagsNodes = tagsHtml.map((html, idx) => { const inner = $("#sortable", html).html(); const wrapper1 = document.createElement("div"); const wrapper2 = document.createElement("div"); wrapper1.classList.add("tags-container-parent"); wrapper2.classList.add("tags-container"); wrapper2.innerHTML = inner; const tagTitle = document.createElement("h4"); tagTitle.classList.add("tags-title"); tagTitle.textContent = tags[idx].replaceAll("-", " "); wrapper1.append(tagTitle); wrapper1.append(wrapper2); return wrapper1; }); container.append(tagsNodes); }) .finally(() => liveStats()); }); }; customMain(); }); $(document).ready(function () { // Don't add the button more than once if ($('#pin-all-button').length) { return; } // Create the Pin All button const pinAllButton = $( '<a id="pin-all-button" class="config" href="#" title="Pin All">' + '<i class="fas fa-thumbtack"></i>' + '</a>' ); // Add it to the existing Heimdall configuration buttons $('#config-buttons').append(pinAllButton); // Handle click $('#pin-all-button').on('click', function (e) { e.preventDefault(); if (!confirm('Pin all Heimdall items?')) { return; } const button = $(this); // Prevent double-clicks button.css('pointer-events', 'none'); button.css('opacity', '0.5'); $.ajax({ url: 'items/pin-all', type: 'POST', headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') }, success: function (response) { alert(response.message); // Reload dashboard so the newly pinned items appear window.location.reload(); }, error: function (xhr) { console.error('Pin All failed:', xhr); alert( 'Unable to pin the items.\n\n' + 'HTTP Status: ' + xhr.status ); button.css('pointer-events', ''); button.css('opacity', ''); } }); }); });
Home dashboard
Users
Application list
Tags list
Settings