Filter keywords on Azure

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

当前为 2024-02-01 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

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