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

目前為 2021-08-12 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Kanka Summernote Code View to the Top
// @namespace    http://tampermonkey.net/
// @version      1
// @description  Sets the cursor position to the start of the input field rather than the end when switching to Code View in Kanka
// @author       Salvatos
// @match        https://kanka.io/*
// @match        https://marketplace.kanka.io/*
// @icon         https://www.google.com/s2/favicons?domain=kanka.io
// @run-at       document-end
// ==/UserScript==

// Wait for Summernote to initialize
$('#entry').on('summernote.init', function() {
    // Add event to code view toggle
    document.getElementsByClassName('btn-codeview')[0].addEventListener('click', cursorToTop);
});

function cursorToTop() {
    // Run only when in code view
    if ($('#entry + div').hasClass('codeview')) {
        // Find editor
        const codeEditor = document.getElementsByClassName('note-codable')[0];
        // Selection to 0
        codeEditor.setSelectionRange(0,0);
    }
}

QingJ © 2025

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