butterchoco

Heimdall CustomJs, Homer Look Like

Aug 5th, 2022 (edited)
4,199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.       // Opera 12.10 and Firefox 18 and later support
  10.       hidden = "hidden";
  11.       visibilityChange = "visibilitychange";
  12.     } else if (typeof document.msHidden !== "undefined") {
  13.       hidden = "msHidden";
  14.       visibilityChange = "msvisibilitychange";
  15.     } else if (typeof document.webkitHidden !== "undefined") {
  16.       hidden = "webkitHidden";
  17.       visibilityChange = "webkitvisibilitychange";
  18.     }
  19.  
  20.     const livestatsRefreshTimeouts = [];
  21.     const livestatsFuncs = [];
  22.     const livestatsContainers = $(".livestats-container");
  23.  
  24.     function stopLivestatsRefresh() {
  25.       for (
  26.         let _i = 0, _livestatsRefreshTime = livestatsRefreshTimeouts;
  27.         _i < _livestatsRefreshTime.length;
  28.         _i++
  29.       ) {
  30.         const timeoutId = _livestatsRefreshTime[_i];
  31.         window.clearTimeout(timeoutId);
  32.       }
  33.     }
  34.  
  35.     function startLivestatsRefresh() {
  36.       for (
  37.         let _i2 = 0, _livestatsFuncs = livestatsFuncs;
  38.         _i2 < _livestatsFuncs.length;
  39.         _i2++
  40.       ) {
  41.         const fun = _livestatsFuncs[_i2];
  42.         fun();
  43.       }
  44.     }
  45.  
  46.     if (livestatsContainers.length > 0) {
  47.       if (
  48.         typeof document.addEventListener === "undefined" ||
  49.         hidden === undefined
  50.       ) {
  51.         console.log("This browser does not support visibilityChange");
  52.       } else {
  53.         document.addEventListener(
  54.           visibilityChange,
  55.           function () {
  56.             if (document[hidden]) {
  57.               stopLivestatsRefresh();
  58.             } else {
  59.               startLivestatsRefresh();
  60.             }
  61.           },
  62.           false
  63.         );
  64.       }
  65.  
  66.       livestatsContainers.each(function (index) {
  67.         const id = $(this).data("id");
  68.         const dataonly = $(this).data("dataonly");
  69.         const increaseby = dataonly == 1 ? 20000 : 1000;
  70.         const container = $(this);
  71.         const max_timer = 30000;
  72.         let timer = 5000;
  73.  
  74.         const fun = function worker() {
  75.           $.ajax({
  76.             url: base + "get_stats/" + id,
  77.             dataType: "json",
  78.             success: function success(data) {
  79.               container.html(data.html);
  80.               if (data.status == "active") timer = increaseby;
  81.               else {
  82.                 if (timer < max_timer) timer += 2000;
  83.               }
  84.             },
  85.             complete: function complete() {
  86.               // Schedule the next request when the current one's complete
  87.               livestatsRefreshTimeouts[index] = window.setTimeout(
  88.                 worker,
  89.                 timer
  90.               );
  91.             },
  92.           });
  93.         };
  94.  
  95.         livestatsFuncs[index] = fun;
  96.         fun();
  97.       });
  98.     }
  99.   };
  100.  
  101.   const customMain = () => {
  102.     if (window.location.pathname !== "/") return;
  103.  
  104.     container.html("");
  105.     container.css("opacity", "1");
  106.     $.get(base + "tags", function (data) {
  107.       const tagArr = Array.from($("tbody tr td a", data));
  108.       tags = tagArr
  109.         .filter((_d, idx) => idx % 2 === 0)
  110.         .map((node) => node.href.split("/").pop());
  111.       const tagPromises = tags.map((tag) => $.get(base + "tag/" + tag));
  112.  
  113.       if (tags.length === 0) return;
  114.       Promise.all(tagPromises)
  115.         .then((tagsHtml) => {
  116.           const tagsNodes = tagsHtml.map((html, idx) => {
  117.             const inner = $("#sortable", html).html();
  118.             const wrapper1 = document.createElement("div");
  119.             const wrapper2 = document.createElement("div");
  120.             wrapper2.classList.add("tags-container");
  121.             wrapper2.innerHTML = inner;
  122.             const tagTitle = document.createElement("h4");
  123.             tagTitle.classList.add("tags-title");
  124.             tagTitle.textContent = tags[idx].replaceAll("-", " ");
  125.             wrapper1.append(tagTitle);
  126.             wrapper1.append(wrapper2);
  127.             return wrapper1;
  128.           });
  129.           container.append(tagsNodes);
  130.         })
  131.         .finally(() => liveStats());
  132.     });
  133.   };
  134.  
  135.   customMain();
  136. });
Add Comment
Please, Sign In to add comment