Kanka Summernote Code View to the Top

Sets the cursor position to the start of the input field rather than the end when switching to Code View in Kanka

  1. // ==UserScript==
  2. // @name Kanka Summernote Code View to the Top
  3. // @namespace http://tampermonkey.net/
  4. // @version 2
  5. // @description Sets the cursor position to the start of the input field rather than the end when switching to Code View in Kanka
  6. // @author Salvatos
  7. // @match https://app.kanka.io/*
  8. // @match https://marketplace.kanka.io/*
  9. // @icon https://www.google.com/s2/favicons?domain=kanka.io
  10. // @run-at document-end
  11. // ==/UserScript==
  12.  
  13. // Wait for Summernote to initialize
  14. $('#entry').on('summernote.init', function() {
  15. // Add event to code view toggle
  16. document.getElementsByClassName('btn-codeview')[0].addEventListener('click', cursorToTop);
  17. });
  18.  
  19. function cursorToTop() {
  20. // Run only when in code view
  21. if ($('#entry + div').hasClass('codeview')) {
  22. // Find editor
  23. const codeEditor = document.getElementsByClassName('note-codable')[0];
  24. // Selection to 0
  25. codeEditor.setSelectionRange(0,0);
  26. }
  27. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址