Sort Vercel Domains

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

当前为 2023-04-07 提交的版本,查看 最新版本

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