Kanka Summernote Code View Save Fix

Correctly saves changes made while in code view in the Summernote editor.

目前為 2021-07-23 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Kanka Summernote Code View Save Fix
// @namespace    http://tampermonkey.net/
// @version      2
// @description  Correctly saves changes made while in code view in the Summernote editor.
// @author       Salvatos
// @match        https://kanka.io/*
// @icon         https://www.google.com/s2/favicons?domain=kanka.io
// @grant        none
// @run-at       document-end
// ==/UserScript==

async function fixCodeEditor() {
    // Wait for Summernote to finish initializing
    while(!document.querySelector(".note-codable")) {
        console.log("Waiting for Summernote.");
        await new Promise(r => setTimeout(r, 100));
    }
    console.log("Ready.");

    // Add input event to code editor
    var codeEditor = document.getElementsByClassName('note-codable')[0];
    codeEditor.addEventListener('input', ()=>{
        // Copy code editor’s value to Summernote’s hidden textarea
        document.getElementById('entry').value = codeEditor.value;
    });
}
if (document.getElementById('entity-form')) {
    fixCodeEditor();
}