Sort Vercel Domains

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

  1. // @ts-check
  2. // ==UserScript==
  3. // @name Sort Vercel Domains
  4. // @version 0.5
  5. // @description Sort the search results from Vercel Domains (vercel.com/domains)
  6. // @match https://vercel.com/*
  7. // @grant none
  8. // @license MIT
  9. // @namespace MEMIJE.IO
  10. // @author MEMIJE.IO
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. 'use strict';
  15. // @ts-check
  16. {
  17. const observer = new MutationObserver((mutations, observer) => {
  18. const allDomainElems = document.querySelectorAll(
  19. '[data-testid="domains/search-item"] .INTERNAL_AVAILABLE',
  20. );
  21.  
  22. const domains = Array.from(allDomainElems).map((elem) => {
  23. const nameEl = elem.querySelector('.query-part');
  24. const endingEl = elem.querySelector('.tld-part');
  25. const name = nameEl ? nameEl.textContent : '';
  26. const ending = endingEl ? endingEl.textContent : '';
  27.  
  28. return `${name}${ending}`;
  29. });
  30. const sorted = [...domains]
  31. .sort((a, b) => a.localeCompare(b))
  32. .sort((a, b) => (a || '').length - (b || '').length);
  33. if (sorted.length > 0) {
  34. console.clear();
  35. console.log(JSON.stringify(sorted));
  36. }
  37. });
  38.  
  39. // define what element should be observed by the observer
  40. // and what types of mutations trigger the callback
  41. observer.observe(document, {
  42. subtree: true,
  43. attributes: true,
  44. //...
  45. });
  46. }
  47. })();