Sort Vercel Domains

Sort the search results from Vercel Domains (vercel.com/domains)

// @ts-check
// ==UserScript==
// @name         Sort Vercel Domains
// @version      0.5
// @description  Sort the search results from Vercel Domains (vercel.com/domains)
// @match        https://vercel.com/*
// @grant        none
// @license      MIT
// @namespace    MEMIJE.IO
// @author       MEMIJE.IO
// ==/UserScript==

(function () {
  'use strict';
  // @ts-check
  {
    const observer = new MutationObserver((mutations, observer) => {
      const allDomainElems = document.querySelectorAll(
        '[data-testid="domains/search-item"] .INTERNAL_AVAILABLE',
      );

      const domains = Array.from(allDomainElems).map((elem) => {
        const nameEl = elem.querySelector('.query-part');
        const endingEl = elem.querySelector('.tld-part');
        const name = nameEl ? nameEl.textContent : '';
        const ending = endingEl ? endingEl.textContent : '';

        return `${name}${ending}`;
      });
      const sorted = [...domains]
        .sort((a, b) => a.localeCompare(b))
        .sort((a, b) => (a || '').length - (b || '').length);
      if (sorted.length > 0) {
        console.clear();
        console.log(JSON.stringify(sorted));
      }
    });

    // define what element should be observed by the observer
    // and what types of mutations trigger the callback
    observer.observe(document, {
      subtree: true,
      attributes: true,
      //...
    });
  }
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址