Sort Vercel Domains

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

目前为 2022-11-12 提交的版本。查看 最新版本

// ==UserScript==
// @name         Sort Vercel Domains
// @namespace    https://gf.qytechs.cn/en/users/673321-christianmemije
// @version      0.3
// @description  Sort the search results from Vercel Domains (vercel.com/domains)
// @author       Memije.io
// @match https://vercel.com/domains*
// @grant        none
// @license      MIT
// ==/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或关注我们的公众号极客氢云获取最新地址