Filter keywords on Azure

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

Verze ze dne 01. 02. 2024. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==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()
    }
  }
});