JanitorAI Token Filter

Filters character cards on JanitorAI by token count

当前为 2025-04-09 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name JanitorAI Token Filter
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.9
  5. // @description Filters character cards on JanitorAI by token count
  6. // @author You
  7. // @match https://janitorai.com/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. let MIN_TOKENS = 500;
  15.  
  16. function parseTokens(tokenText) {
  17. try {
  18. let cleanText = tokenText.replace(/<!--[\s\S]*?-->/g, '').replace('tokens', '').trim();
  19. if (cleanText.includes('k')) {
  20. return parseFloat(cleanText.replace('k', '')) * 1000;
  21. }
  22. return parseInt(cleanText, 10) || 0;
  23. } catch (error) {
  24. return 0;
  25. }
  26. }
  27.  
  28. function filterCards() {
  29. const cards = document.querySelectorAll('.chakra-stack.css-1s5evre');
  30. cards.forEach(card => {
  31. const tokenElement = card.querySelector('.chakra-text.css-jccmq6');
  32. if (!tokenElement) return;
  33.  
  34. const tokenCount = parseTokens(tokenElement.textContent);
  35. const parentContainer = card.closest('.css-1sxhvxh');
  36. if (parentContainer) {
  37. parentContainer.style.display = tokenCount < MIN_TOKENS ? 'none' : '';
  38. }
  39. });
  40. }
  41.  
  42. function createTokenSelector() {
  43. const select = document.createElement('select');
  44. select.id = 'token-filter-select';
  45. select.style.position = 'fixed';
  46. select.style.top = '10px';
  47. select.style.left = '10px';
  48. select.style.zIndex = '99999';
  49. select.style.padding = '4px 8px';
  50. select.style.backgroundColor = '#4a4a4a';
  51. select.style.border = '1px solid #666';
  52. select.style.borderRadius = '4px';
  53. select.style.fontSize = '12px';
  54. select.style.color = '#fff';
  55. select.style.cursor = 'pointer';
  56.  
  57. const options = [100, 500, 1000, 1500, 2000, 2500, 3000, 4000]; // Добавлен 100, удалены 4500 и 5000
  58. options.forEach(value => {
  59. const option = document.createElement('option');
  60. option.value = value;
  61. option.text = `${value} tokens`;
  62. if (value === MIN_TOKENS) option.selected = true;
  63. select.appendChild(option);
  64. });
  65.  
  66. select.addEventListener('change', (e) => {
  67. MIN_TOKENS = parseInt(e.target.value);
  68. filterCards();
  69. });
  70.  
  71. const appendSelector = () => {
  72. if (document.body) {
  73. document.body.appendChild(select);
  74. } else {
  75. setTimeout(appendSelector, 500);
  76. }
  77. };
  78. appendSelector();
  79. }
  80.  
  81. function initialize() {
  82. createTokenSelector();
  83. filterCards();
  84. }
  85.  
  86. const tryInitialize = () => {
  87. if (document.body) {
  88. initialize();
  89. const observer = new MutationObserver(() => {
  90. setTimeout(filterCards, 500);
  91. });
  92. observer.observe(document.body, { childList: true, subtree: true });
  93. } else {
  94. setTimeout(tryInitialize, 1000);
  95. }
  96. };
  97.  
  98. tryInitialize();
  99. })();