From f7e23ffccdae00d0185b9b127c5e61ba7bd178af Mon Sep 17 00:00:00 2001 From: bi1101 Date: Mon, 22 Jul 2024 11:03:38 +0700 Subject: [PATCH] Elementor compatibility Fix --- Assets/js/docx_export.js | 4 +- Assets/js/docx_export_speaking.js | 4 +- Assets/js/writify_event_stream.js | 76 ------------------------------- writify-gform-openai.php | 8 ++-- 4 files changed, 8 insertions(+), 84 deletions(-) delete mode 100644 Assets/js/writify_event_stream.js diff --git a/Assets/js/docx_export.js b/Assets/js/docx_export.js index ad7c028..e06e5cd 100644 --- a/Assets/js/docx_export.js +++ b/Assets/js/docx_export.js @@ -1,6 +1,6 @@ /** * Script Name: Docx Export - * Version: 1.0.8 + * Version: 1.0.9 * Last Updated: 16-5-2024 * Author: bi1101 * Description: Export the result page as docx files with comments. @@ -143,7 +143,7 @@ function createSectionsWithComments(rawComments) { function createNormalSections(className) { const element = document.querySelector( - `.${className} .elementor-widget-container .elementor-shortcode` + `.${className}` ); if (!element) { console.warn(`No element found with class name: ${className}`); diff --git a/Assets/js/docx_export_speaking.js b/Assets/js/docx_export_speaking.js index c432ce4..1f14941 100644 --- a/Assets/js/docx_export_speaking.js +++ b/Assets/js/docx_export_speaking.js @@ -1,6 +1,6 @@ /** * Script Name: Docx Export for Speaking - * Version: 1.0.1 + * Version: 1.0.2 * Last Updated: 16-05-2024 * Author: bi1101 * Description: Export the result page as docx files with comments. @@ -114,7 +114,7 @@ function createSectionsWithComments(rawComments) { function createNormalSections(className) { const element = document.querySelector( - `.${className} .elementor-widget-container .elementor-shortcode` + `.${className}` ); if (!element) { console.warn(`No element found with class name: ${className}`); diff --git a/Assets/js/writify_event_stream.js b/Assets/js/writify_event_stream.js deleted file mode 100644 index 014766f..0000000 --- a/Assets/js/writify_event_stream.js +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Script Name: Writify Event Stream - * Version: 1.0.0 - * Last Updated: 13-11-2023 - * Author: bi1101 - * Description: Initiate event stream & process streaming data. - */ - - -var div_index = 0, div_index_str = ''; -var buffer = ""; // Buffer for holding messages -var md = new Remarkable(); - -// Fetch the user role using fetch API -fetch("", { - method: 'POST', - headers: { - 'Content-Type': 'application/x-www-form-urlencoded' - }, - body: 'action=writify_get_user_role' -}) - .then(response => response.json()) - .then(data => { - const userIdentifier = data.role; - - // Now initiate the EventSource with the userIdentifier in the query params - const formId = ; - const entryId = ; - const sourceUrl = `/wp-json/writify/v1/event_stream_openai?form_id=${formId}&entry_id=${entryId}&user_identifier=${userIdentifier}`; - - const source = new EventSource(sourceUrl); - source.onmessage = function (event) { - if (event.data == "[ALLDONE]") { - source.close(); - } else if (event.data.startsWith("[DIVINDEX-")) { - div_index_str = event.data.replace("[DIVINDEX-", "").replace("]", ""); - div_index = parseInt(div_index_str); - console.log(div_index); - jQuery('.response-div-' + (div_index)).css('display', 'flex'); - jQuery('.response-div-divider' + (div_index)).show(); - } else if (event.data == "[DONE]") { - // When a message is done, convert the buffer to HTML and display it - var html = md.render(buffer); - jQuery('.response-div-' + div_index).find('.preloader-icon').hide(); - var current_div = jQuery('.response-div-' + div_index).find('.elementor-shortcode'); - current_div.html(html); // Replace the current HTML content with the processed markdown - - jQuery.when(current_div.html(html)).then(function () { - // Add the "upgrade_vocab" class to the
  • elements that match the format - addUpgradeVocabClass(current_div); - }); - - // Clear the buffer - buffer = ""; - } else { - // Add the message to the buffer - text = JSON.parse(event.data).choices[0].delta.content; - if (text !== undefined) { - buffer += text; - // Convert the buffer to HTML and display it - var html = md.render(buffer); - jQuery('.response-div-' + div_index).find('.preloader-icon').hide(); - var current_div = jQuery('.response-div-' + div_index).find('.elementor-shortcode'); - current_div.html(html); // Replace the current HTML content with the processed markdown - } - } - }; - source.onerror = function (event) { - div_index = 0; - source.close(); - jQuery('.error_message').css('display', 'flex'); - }; - }) - .catch(error => { - console.error("Error fetching user role:", error); - }); diff --git a/writify-gform-openai.php b/writify-gform-openai.php index cd69bfc..56592ba 100644 --- a/writify-gform-openai.php +++ b/writify-gform-openai.php @@ -2,7 +2,7 @@ /** * Plugin Name: Writify * Description: Score IELTS Essays x GPT - * Version: 1.2.6 + * Version: 1.2.7 * Author: IELTS Science * Copyright: © 2023-2026 RLT */ @@ -147,7 +147,7 @@ function writify_enqueue_scripts_footer() // When a message is done, convert the buffer to HTML and display it var html = md.render(buffer); jQuery('.response-div-' + div_index).find('.preloader-icon').hide(); - var current_div = jQuery('.response-div-' + div_index).find('.elementor-shortcode'); + var current_div = jQuery('.response-div-' + div_index).find('.e-con-full'); current_div.html(html); // Replace the current HTML content with the processed markdown jQuery.when(current_div.html(html)).then(function () { @@ -223,7 +223,7 @@ function writify_enqueue_scripts() // Enqueue the script only if the slug starts with 'result' if (substr($slug, 0, 6) === 'result') { - wp_enqueue_script('writify-docx-export', plugin_dir_url(__FILE__) . 'Assets/js/docx_export.js', array('jquery'), '1.0.8', true); + wp_enqueue_script('writify-docx-export', plugin_dir_url(__FILE__) . 'Assets/js/docx_export.js', array('jquery'), '1.0.9', true); // Enqueue Docx script wp_enqueue_script('docx', 'https://unpkg.com/docx@8.0.0/build/index.js', array(), null, true); // Enqueue FileSaver script @@ -262,7 +262,7 @@ function writify_enqueue_scripts() // Enqueue the script only if the slug starts with 'speaking-result' if (substr($slug, 0, 15) === 'speaking-result') { // Enqueue necessary scripts - wp_enqueue_script('writify-docx-export', plugin_dir_url(__FILE__) . 'Assets/js/docx_export_speaking.js', array('jquery'), '1.0.1', true); + wp_enqueue_script('writify-docx-export', plugin_dir_url(__FILE__) . 'Assets/js/docx_export_speaking.js', array('jquery'), '1.0.2', true); // Enqueue Docx script wp_enqueue_script('docx', 'https://unpkg.com/docx@8.0.0/build/index.js', array(), null, true); // Enqueue FileSaver script