Advertisement
Guest User

Untitled

a guest
Jan 18th, 2025
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.10 KB | None | 0 0
  1. $(document).ready(function () {
  2. const base = (document.querySelector("base") || {}).href || '/';
  3. const container = $("#sortable");
  4.  
  5. const liveStats = () => {
  6. let hidden, visibilityChange;
  7.  
  8. if (typeof document.hidden !== "undefined") {
  9. hidden = "hidden";
  10. visibilityChange = "visibilitychange";
  11. } else if (typeof document.msHidden !== "undefined") {
  12. hidden = "msHidden";
  13. visibilityChange = "msvisibilitychange";
  14. } else if (typeof document.webkitHidden !== "undefined") {
  15. hidden = "webkitHidden";
  16. visibilityChange = "webkitvisibilitychange";
  17. }
  18.  
  19. const livestatsRefreshTimeouts = [];
  20. const livestatsFuncs = [];
  21. const livestatsContainers = $(".livestats-container");
  22.  
  23. function stopLivestatsRefresh() {
  24. livestatsRefreshTimeouts.forEach(timeoutId => {
  25. window.clearTimeout(timeoutId);
  26. });
  27. }
  28.  
  29. function startLivestatsRefresh() {
  30. livestatsFuncs.forEach(fun => fun());
  31. }
  32.  
  33. if (livestatsContainers.length > 0) {
  34. if (typeof document.addEventListener !== "undefined" && hidden !== undefined) {
  35. document.addEventListener(visibilityChange, function () {
  36. if (document[hidden]) {
  37. stopLivestatsRefresh();
  38. } else {
  39. startLivestatsRefresh();
  40. }
  41. }, false);
  42. } else {
  43. console.log("Browser does not support visibilityChange");
  44. }
  45.  
  46. livestatsContainers.each(function (index) {
  47. const id = $(this).data("id");
  48. const dataonly = $(this).data("dataonly");
  49. const increaseby = dataonly == 1 ? 20000 : 1000;
  50. const container = $(this);
  51. const max_timer = 30000;
  52. let timer = 5000;
  53.  
  54. const fun = function worker() {
  55. $.ajax({
  56. url: base + "get_stats/" + id,
  57. dataType: "json",
  58. success: function (data) {
  59. if (data && data.html) {
  60. container.html(data.html);
  61. timer = data.status == "active" ? increaseby : Math.min(timer + 2000, max_timer);
  62. }
  63. },
  64. error: function(xhr, status, error) {
  65. console.error('Error fetching stats:', error);
  66. },
  67. complete: function () {
  68. livestatsRefreshTimeouts[index] = window.setTimeout(worker, timer);
  69. }
  70. });
  71. };
  72.  
  73. livestatsFuncs[index] = fun;
  74. fun();
  75. });
  76. }
  77. };
  78.  
  79. const customMain = () => {
  80. if (window.location.pathname !== "/") {
  81. console.log("Not on home page, skipping customization");
  82. return;
  83. }
  84.  
  85. if (!container.length) {
  86. console.error("Sortable container not found");
  87. return;
  88. }
  89.  
  90. // Store the existing content
  91. const existingContent = container.children().not('.add-item');
  92.  
  93. // Create wrapper for the content
  94. const wrapper = document.createElement("div");
  95. wrapper.classList.add("tags-container");
  96.  
  97. // Move the content into the wrapper
  98. $(wrapper).append(existingContent);
  99.  
  100. // Clear the container and add the wrapped content
  101. container.empty()
  102. .append(wrapper)
  103. .append($('.add-item')); // Re-add the "Pin item to dashboard" section
  104.  
  105. // Make sure container is visible
  106. container.css("opacity", "1");
  107.  
  108. // Initialize live stats
  109. liveStats();
  110. };
  111.  
  112. customMain();
  113. });
  114.  
  115. document.addEventListener('DOMContentLoaded', function() {
  116. // Create background container
  117. const bgContainer = document.createElement('div');
  118. bgContainer.className = 'background-container';
  119.  
  120. // Get the background image directly from inline style
  121. const appElement = document.getElementById('app');
  122. const bgImage = appElement.style.backgroundImage;
  123.  
  124. // Set the background directly on the container
  125. bgContainer.style.backgroundImage = bgImage;
  126.  
  127. // Clear the app background
  128. appElement.style.background = 'none';
  129.  
  130. // Insert the background container at the start of body
  131. document.body.insertBefore(bgContainer, document.body.firstChild);
  132. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement