Sort Vercel Domains

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

当前为 2023-02-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. (function () {
  12. 'use strict';
  13. // @ts-check
  14. {
  15. const observer = new MutationObserver((mutations, observer) => {
  16. const allDomainElems = document.querySelectorAll(
  17. '[data-testid="domains/search-item"] .INTERNAL_AVAILABLE',
  18. );
  19. const domains = Array.from(allDomainElems).map((elem) => {
  20. const nameEl = elem.querySelector('.query-part');
  21. const endingEl = elem.querySelector('.tld-part');
  22. const name = nameEl ? nameEl.textContent : '';
  23. const ending = endingEl ? endingEl.textContent : '';
  24. return `${name}${ending}`;
  25. });
  26. const sorted = [...domains]
  27. .sort((a, b) => a.localeCompare(b))
  28. .sort((a, b) => (a || '').length - (b || '').length);
  29. if (sorted.length > 0) {
  30. console.clear();
  31. console.log(JSON.stringify(sorted));
  32. }
  33. });
  34. // define what element should be observed by the observer
  35. // and what types of mutations trigger the callback
  36. observer.observe(document, {
  37. subtree: true,
  38. attributes: true,
  39. //...
  40. });
  41. }
  42. })();