Filter keywords on Azure

1/16/2024, 8:12:42 PM

Version vom 01.02.2024. Aktuellste Version

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        Filter keywords on Azure
// @namespace   Violentmonkey Scripts
// @match       https://portal.azure.com/*
// @grant       none
// @version     1.0
// @author      chaoscreater
// @description 1/16/2024, 8:12:42 PM
// ==/UserScript==

const getVisibleElements = (selector) =>
  [...document.querySelectorAll(selector)].filter((it) => it.checkVisibility());

// load for 5 seconds

const loadValues = ({ interval = 250, timeout = 5000 } = {}) => {
  return new Promise((resolve) => {
    let timer = null,
      stop = () => resolve(clearInterval(timer));

    timer = setInterval(() => {
      var $loadMores = getVisibleElements(".azc-grid-pageable-loadMoreContainer");

      for (let $loadMore of $loadMores) {
        if (!$loadMore.classList.contains("fxs-display-none")) {
          $loadMore?.click();
          return;
        }
      }

      stop();
    }, interval);

    setTimeout(stop, timeout);
  });
};

const getValueRows = () =>
  getVisibleElements(".azc-grid-full").flatMap((it) => [...it.querySelectorAll("tbody > tr")]);

const filterValues = (term) => {
  return getValueRows().filter((tr) => {
    const matched = new RegExp(term, "gi").test(tr.innerText);
    tr.style.display = matched ? "" : "none";
    return matched;
  });
};

const resetFilter = () => {
  getValueRows().forEach((tr) => {
    tr.style.display = "";
  });
};

const loadAndFilterValues = async (term) => {
  await loadValues();
  filterValues(term);
};

// Add keybinding for CTRL+SHIFT+J
document.addEventListener("keydown", async (event) => {
  if (event.shiftKey && event.key === "J") {
    const term = prompt("Enter keyword to filter on and load more:");
    if (term !== null) {
      await loadValues();
      loadAndFilterValues(term);
    }
  }
});

// Add keybinding for CTRL+SHIFT+F
document.addEventListener("keydown", (event) => {
  if (event.ctrlKey && event.shiftKey && event.key === "F") {
    const term = prompt("Enter keyword to filter on:");
    if (term !== null) {
      filterValues(term);
    }
  }
});


const actions = {
  "L": function LoadMore() {

    loadValues();
  },
  "Z": function ResetLoadMore() {
    resetFilter();
  }
}


document.body.addEventListener("keyup", ev => {
  if (ev.ctrlKey) {
    if (ev.key === '/') {
      alert(`Ctrl + Shift + F : Filter by keyword\nCtrl + Shift + J : Filter by keyword and click on Load More\n` +
        Object.entries(actions).map(it => `Ctrl + Shift + ${it[0]} : ${it[1].name.replace(/([A-Z])/g, ' $1').trim()}`).join('\n') + '\n\nGreat for checking Sign-in logs or blobs in a Storage account container');
    } else if (ev.shiftKey) {
      const action = actions[ev.key]
      action && action()
    }
  }
});