addCustomModal
code:style.css
.tzmk_customModalBack {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 200;
background-color: rgba(0.5,0.5,0.5,0.5);
}
.tzmk_hidden {
display: none;
}
.tzmk_customModal {
z-index: 301;
position:fixed;
top: 10%;
right:20px;
min-width: 400px;
padding: 20px;
height: 80%;
overflow: scroll;
padding-bottom: 40px;
background-color: white;
}
select.tzmk_menu {
width: 60%;
min-height: 20px;
padding: 5px;
}
.tzmk_menu {
font-size: 20px;
}
.tzmk_prompt {
width: 80%;
min-height: 60px;
margin: 5px;
}
.tzmk_submitButton {
text-align:center;
padding: 4px;
position:absolute;
right: 10px;
}
.tzmk_closeButton {
text-align:center;
padding: 4px;
position:absolute;
right: 10px;
}
code:export.js
$('body').append('<div id="tzmk_console">console text</div>');
export let modalController = {};
function closeModal() {
$('.tzmk_customModal').addClass('tzmk_hidden');
$('.tzmk_customModalBack').addClass('tzmk_hidden');
};
function openModal() {
$('.tzmk_customModal').removeClass('tzmk_hidden');
$('.tzmk_customModalBack').removeClass('tzmk_hidden');
};
async function setPromptByChoice() {
let systemPrompt = await fetch(https://scrapbox.io/api/code/tsuzumik-sandbox/${val}/system).then(res=>{return res.text()});
$('#tzmk_systemPrompt').val(systemPrompt);
let userQuote = await fetch(https://scrapbox.io/api/code/tsuzumik-sandbox/${val}/quote).then(res=>{return res.text()});
if (userQuote && !$('#tzmk_userPrompt').val()){
$('#tzmk_userPrompt').val(userQuote);
}
}
function getGptAnswer(res) {
let list = []
}
return list;
}
let lock = false;
function submitGpt() {
if (lock) {
alert('process running');
return;
}
lock = true;
setTimeout(function(){lock = false;}, 1000);
let systemInput = $('#tzmk_systemPrompt').val();
let userInput = $('#tzmk_userPrompt').val();
let userQuote = $('#tzmk_userQuote').val();
let logId = scrapbox.tzmk_hopBot.addLog(userInput);
scrapbox.tzmk_askChatGpt(systemInput, userInput, userQuote, "",
function(res) {
let answers = getGptAnswer(res);
for (let answer of answers) {
$('#tzmk_console').append('<p>'+ answer + '</p>');
scrapbox.tzmk_hopBot.addAnswer(logId, answer);
}
scrapbox.tzmk_hopBot.completePase();
}
);
closeModal();
scrapbox.tzmk_hopBot.startHopping();
}
modalController.openModal = function(quote="", prompt="") {
openModal();
if (prompt) {
}
if (quote) {
$('#tzmk_userQuote').val(quote);
}
}
let domString = [
'<div class="tzmk_customModalBack tzmk_hidden"></div>',
'<div class="tzmk_customModal tzmk_hidden">',
' <div><button class="tzmk_closeButton" href="#">close</button></div>',
' Prompt: <select class="tzmk_menu" name="promptType" onchange="onSelect($(this).val());">',
' <option value="general_assistant_prompt">General</option>',
' <option value="general_assistant_prompt">add page to add template</option>',
' </select>',
' <div>System</div>',
' <textarea id="tzmk_systemPrompt" class="tzmk_prompt" readonly></textarea>',
' <div>Selected text</div>',
' <textarea id="tzmk_userQuote" class="tzmk_prompt"></textarea>',
' <div>User instruction</div>',
' <textarea id="tzmk_userPrompt" class="tzmk_prompt"></textarea>',
' <div><button class="tzmk_submitButton" href="#">submit</button></div>',
' </div>'
].join('\n');
$('body').append(domString);
$('.tzmk_closeButton').on('click', closeModal);
$('.tzmk_submitButton').on('click', submitGpt);
setPromptByChoice();