console.js 666 B

12345678910111213141516171819202122232425262728293031
  1. window.consoleEmulatorScroll = (el) => {
  2. if (el) el.scrollTop = el.scrollHeight;
  3. };
  4. window.consoleHasSelection = () => {
  5. const sel = window.getSelection();
  6. return sel && sel.toString().length > 0;
  7. };
  8. window.scrollToAnchor = (anchor) => {
  9. if (!anchor) return;
  10. let attempts = 0;
  11. const maxAttempts = 30;
  12. const tryScroll = () => {
  13. const el = document.getElementById(anchor);
  14. if (el) {
  15. el.scrollIntoView({ behavior: "smooth", block: "start" });
  16. return;
  17. }
  18. attempts++;
  19. if (attempts < maxAttempts) {
  20. setTimeout(tryScroll, 50);
  21. }
  22. };
  23. tryScroll();
  24. };