2021-05-03 00:48:47 +02:00
//=================================================================//
// VARIABLES
//=================================================================//
2021-05-05 09:04:06 +02:00
// Socket IO Object
2021-05-03 00:48:47 +02:00
var socket ;
2021-05-05 09:04:06 +02:00
// UI references for jQuery
2021-05-07 20:32:10 +02:00
var connect _status ;
2022-03-07 01:51:35 +01:00
var button _loadmodel ;
2021-05-04 15:56:48 +02:00
var button _newgame ;
2021-08-19 12:54:44 +02:00
var button _rndgame ;
2021-05-04 15:56:48 +02:00
var button _save ;
2021-05-22 11:28:40 +02:00
var button _saveas ;
var button _savetofile ;
2021-05-04 15:56:48 +02:00
var button _load ;
2021-05-11 06:27:34 +02:00
var button _import ;
2021-05-29 11:46:03 +02:00
var button _importwi ;
2021-05-16 11:29:39 +02:00
var button _impaidg ;
2021-05-04 15:56:48 +02:00
var button _settings ;
2021-05-11 01:17:10 +02:00
var button _format ;
2021-10-22 20:18:10 +02:00
var button _softprompt ;
2021-12-13 07:03:26 +01:00
var button _userscripts ;
2022-06-14 02:18:09 +02:00
var button _samplers ;
2021-08-19 13:18:01 +02:00
var button _mode ;
var button _mode _label ;
2021-05-03 00:48:47 +02:00
var button _send ;
var button _actmem ;
var button _actback ;
2022-01-21 21:30:37 +01:00
var button _actfwd ;
2021-05-03 00:48:47 +02:00
var button _actretry ;
2021-05-13 07:26:42 +02:00
var button _actwi ;
2021-05-03 00:48:47 +02:00
var game _text ;
var input _text ;
var message _text ;
2021-12-27 04:21:58 +01:00
var chat _name ;
2021-05-07 20:32:10 +02:00
var settings _menu ;
2021-05-11 01:17:10 +02:00
var format _menu ;
2021-05-13 07:26:42 +02:00
var wi _menu ;
2021-05-05 09:04:06 +02:00
var anote _menu ;
var anote _input ;
var anote _labelcur ;
var anote _slider ;
2022-01-24 18:54:44 +01:00
var debug _area ;
2021-05-11 06:27:34 +02:00
var popup ;
var popup _title ;
var popup _content ;
var popup _accept ;
var popup _close ;
2021-05-16 11:29:39 +02:00
var aidgpopup ;
var aidgpromptnum ;
var aidg _accept ;
var aidg _close ;
2021-05-22 11:28:40 +02:00
var saveaspopup ;
var saveasinput ;
2022-01-22 01:02:56 +01:00
var savepins ;
2021-08-19 12:54:44 +02:00
var topic ;
2021-05-22 11:28:40 +02:00
var saveas _accept ;
var saveas _close ;
2022-03-07 01:51:35 +01:00
var loadmodelpopup ;
2021-05-22 11:28:40 +02:00
var loadpopup ;
var loadcontent ;
var load _accept ;
var load _close ;
2021-10-22 20:18:10 +02:00
var sppopup ;
var spcontent ;
var sp _accept ;
var sp _close ;
2021-12-13 07:03:26 +01:00
var uspopup ;
var uscontent ;
var us _accept ;
var us _close ;
2021-05-22 11:28:40 +02:00
var nspopup ;
var ns _accept ;
var ns _close ;
2021-08-19 12:54:44 +02:00
var rspopup ;
var rs _accept ;
var rs _close ;
2021-05-29 11:46:03 +02:00
var seqselmenu ;
var seqselcontents ;
2022-07-28 05:13:08 +02:00
var stream _preview ;
2021-05-03 00:48:47 +02:00
2021-09-19 17:41:37 +02:00
var storyname = null ;
2021-08-19 13:18:01 +02:00
var memorymode = false ;
2021-09-19 17:41:37 +02:00
var memorytext = "" ;
2021-08-19 13:18:01 +02:00
var gamestarted = false ;
2021-12-05 05:59:28 +01:00
var wiscroll = 0 ;
2021-08-23 08:34:27 +02:00
var editmode = false ;
var connected = false ;
var newly _loaded = true ;
2022-07-01 19:45:57 +02:00
var all _modified _chunks = new Set ( ) ;
2021-09-27 19:11:15 +02:00
var modified _chunks = new Set ( ) ;
var empty _chunks = new Set ( ) ;
var gametext _bound = false ;
2021-09-28 04:21:14 +02:00
var saved _prompt = "..." ;
2021-12-05 05:59:28 +01:00
var wifolders _d = { } ;
var wifolders _l = [ ] ;
2021-09-28 04:56:12 +02:00
var override _focusout = false ;
2021-09-01 00:22:30 +02:00
var sman _allow _delete = false ;
var sman _allow _rename = false ;
2021-10-22 20:18:10 +02:00
var allowsp = false ;
2021-11-05 00:33:17 +01:00
var remote = false ;
2022-01-10 22:36:15 +01:00
var gamestate = "" ;
2022-01-18 23:20:45 +01:00
var gamesaved = true ;
var modelname = null ;
2022-03-12 20:21:11 +01:00
var model = "" ;
2022-07-28 05:13:08 +02:00
var ignore _stream = false ;
2021-08-19 13:18:01 +02:00
2021-09-30 20:13:54 +02:00
// This is true iff [we're in macOS and the browser is Safari] or [we're in iOS]
2021-10-01 04:58:54 +02:00
var using _webkit _patch = true ;
2021-09-30 20:13:54 +02:00
2021-05-05 09:04:06 +02:00
// Key states
var shift _down = false ;
2021-05-03 00:48:47 +02:00
var do _clear _ent = false ;
2022-06-06 03:06:09 +02:00
// Whether or not an entry in the Userscripts menu is being dragged
var us _dragging = false ;
2022-06-14 02:18:09 +02:00
// Whether or not an entry in the Samplers menu is being dragged
var samplers _dragging = false ;
2021-05-11 01:17:10 +02:00
// Display vars
var allowtoggle = false ;
var formatcount = 0 ;
2021-08-23 08:34:27 +02:00
var allowedit = true ; // Whether clicking on chunks will edit them
2021-05-11 01:17:10 +02:00
2021-08-19 13:18:01 +02:00
// Adventure
var action _mode = 0 ; // 0: story, 1: action
var adventure = false ;
2021-12-26 01:51:32 +01:00
// Chatmode
var chatmode = false ;
2022-04-27 03:14:44 +02:00
var sliders _throttle = getThrottle ( 200 ) ;
2022-06-30 18:23:06 +02:00
var submit _throttle = null ;
2022-03-25 20:08:56 +01:00
2021-05-03 00:48:47 +02:00
//=================================================================//
// METHODS
//=================================================================//
2022-03-25 20:08:56 +01:00
/ * *
* Returns a function that will automatically wait for X ms before executing the callback
* The timer is reset each time the returned function is called
* Useful for methods where something is overridden too fast
* @ param ms milliseconds to wait before executing the callback
* @ return { ( function ( * ) : void ) | * } function that takes the ms to wait and a callback to execute after the timer
* /
function getThrottle ( ms ) {
2022-03-25 20:37:45 +01:00
var timer = { } ;
2022-03-25 20:08:56 +01:00
2022-03-25 20:37:45 +01:00
return function ( id , callback ) {
if ( timer [ id ] ) {
clearTimeout ( timer [ id ] ) ;
2022-03-25 20:08:56 +01:00
}
2022-03-25 20:37:45 +01:00
timer [ id ] = setTimeout ( function ( ) {
2022-03-25 20:08:56 +01:00
callback ( ) ;
2022-03-25 20:46:08 +01:00
delete timer [ id ] ;
2022-03-25 20:08:56 +01:00
} , ms ) ;
}
}
2022-06-10 20:47:52 +02:00
function reset _menus ( ) {
settings _menu . html ( "" ) ;
format _menu . html ( "" ) ;
wi _menu . html ( "" ) ;
}
2021-05-07 20:32:10 +02:00
function addSetting ( ob ) {
// Add setting block to Settings Menu
2021-05-29 11:46:03 +02:00
if ( ob . uitype == "slider" ) {
settings _menu . append ( "<div class=\"settingitem\" > \
< div class = \ "settinglabel\" > \
< div class = \ "justifyleft\" > \
"+ob.label+" < span class = \ "helpicon\">?<span class=\"helptext\">" + ob . tooltip + " < / s p a n > < / s p a n > \
< / d i v > \
2022-04-26 21:27:28 +02:00
< input inputmode = \ "" + ( ob . unit === "float" ? "decimal" : "numeric" ) + "\" class=\"justifyright flex-push-right\" id=\"" + ob . id + "cur\" value=\"" + ob . default + "\" > \
2021-05-07 20:32:10 +02:00
< / d i v > \
2021-05-29 11:46:03 +02:00
< div > \
< input type = \ "range\" class=\"form-range airange\" min=\"" + ob . min + "\" max=\"" + ob . max + "\" step=\"" + ob . step + "\" id=\"" + ob . id + "\" > \
2021-05-07 20:32:10 +02:00
< / d i v > \
2021-05-29 11:46:03 +02:00
< div class = \ "settingminmax\" > \
< div class = \ "justifyleft\" > \
"+ob.min+" \
< / d i v > \
< div class = \ "justifyright\" > \
"+ob.max+" \
< / d i v > \
2021-05-07 20:32:10 +02:00
< / d i v > \
2021-05-29 11:46:03 +02:00
< / d i v > " ) ;
// Set references to HTML objects
var refin = $ ( "#" + ob . id ) ;
var reflb = $ ( "#" + ob . id + "cur" ) ;
window [ "setting_" + ob . id ] = refin ; // Is this still needed?
window [ "label_" + ob . id ] = reflb ; // Is this still needed?
// Add event function to input
2022-05-29 01:14:26 +02:00
var updateLabelColor = function ( ) {
var value = ( ob . unit === "float" ? parseFloat : parseInt ) ( reflb . val ( ) ) ;
if ( value > ob . max || value < ob . min ) {
reflb . addClass ( "setting-value-warning" ) ;
} else {
reflb . removeClass ( "setting-value-warning" ) ;
}
}
2022-04-26 21:27:28 +02:00
var send = function ( ) {
2022-03-25 20:37:45 +01:00
sliders _throttle ( ob . id , function ( ) {
2022-05-29 00:33:57 +02:00
socket . send ( { 'cmd' : $ ( refin ) . attr ( 'id' ) , 'data' : $ ( reflb ) . val ( ) } ) ;
2022-03-25 20:08:56 +01:00
} ) ;
2022-04-26 21:27:28 +02:00
}
2022-05-29 00:33:57 +02:00
refin . on ( "input" , function ( event ) {
reflb . val ( refin . val ( ) ) ;
2022-05-29 01:14:26 +02:00
updateLabelColor ( ) ;
2022-05-29 00:33:57 +02:00
send ( ) ;
2022-05-29 01:14:26 +02:00
} ) . on ( "change" , updateLabelColor ) ;
2022-04-26 21:27:28 +02:00
reflb . on ( "change" , function ( event ) {
var value = ( ob . unit === "float" ? parseFloat : parseInt ) ( event . target . value ) ;
2022-05-29 01:14:26 +02:00
if ( Number . isNaN ( value ) || ( ob . min >= 0 && value < 0 ) ) {
2022-04-26 21:27:28 +02:00
event . target . value = refin . val ( ) ;
return ;
}
2022-05-29 00:33:57 +02:00
if ( ob . unit === "float" ) {
value = parseFloat ( value . toFixed ( 3 ) ) ; // Round to 3 decimal places to help avoid the number being too long to fit in the box
}
2022-04-26 21:27:28 +02:00
refin . val ( value ) ;
2022-05-29 00:33:57 +02:00
reflb . val ( value ) ;
2022-05-29 01:14:26 +02:00
updateLabelColor ( ) ;
2022-04-26 21:27:28 +02:00
send ( ) ;
2021-05-29 11:46:03 +02:00
} ) ;
} else if ( ob . uitype == "toggle" ) {
settings _menu . append ( "<div class=\"settingitem\" > \
< input type = \ "checkbox\" data-toggle=\"toggle\" data-onstyle=\"success\" id=\"" + ob . id + "\" > \
< span class = \ "formatlabel\">" + ob . label + " < / s p a n > \
< span class = \ "helpicon\">?<span class=\"helptext\">" + ob . tooltip + " < / s p a n > < / s p a n > \
< / d i v > " ) ;
// Tell Bootstrap-Toggle to render the new checkbox
$ ( "input[type=checkbox]" ) . bootstrapToggle ( ) ;
$ ( "#" + ob . id ) . on ( "change" , function ( ) {
if ( allowtoggle ) {
socket . send ( { 'cmd' : $ ( this ) . attr ( 'id' ) , 'data' : $ ( this ) . prop ( 'checked' ) } ) ;
}
2021-08-19 13:18:01 +02:00
if ( ob . id == "setadventure" ) {
setadventure ( $ ( this ) . prop ( 'checked' ) ) ;
}
2021-05-29 11:46:03 +02:00
} ) ;
}
2021-05-07 20:32:10 +02:00
}
2022-01-18 23:20:45 +01:00
function refreshTitle ( ) {
var title = gamesaved ? "" : "\u2731 " ;
if ( storyname !== null ) {
title += storyname + " \u2014 " ;
}
title += "KoboldAI Client" ;
if ( modelname !== null ) {
title += " (" + modelname + ")" ;
}
document . title = title ;
}
function setGameSaved ( state ) {
gamesaved = ! ! state ;
refreshTitle ( ) ;
}
2021-05-11 01:17:10 +02:00
function addFormat ( ob ) {
// Check if we need to make a new column for this button
if ( formatcount == 0 ) {
format _menu . append ( "<div class=\"formatcolumn\"></div>" ) ;
}
// Get reference to the last child column
var ref = $ ( "#formatmenu > div" ) . last ( ) ;
// Add format block to Format Menu
ref . append ( "<div class=\"formatrow\" > \
< input type = \ "checkbox\" data-toggle=\"toggle\" data-onstyle=\"success\" id=\"" + ob . id + "\" > \
< span class = \ "formatlabel\">" + ob . label + " < / s p a n > \
< span class = \ "helpicon\">?<span class=\"helptext\">" + ob . tooltip + " < / s p a n > < / s p a n > \
< / d i v > " ) ;
// Tell Bootstrap-Toggle to render the new checkbox
$ ( "input[type=checkbox]" ) . bootstrapToggle ( ) ;
// Add event to input
$ ( "#" + ob . id ) . on ( "change" , function ( ) {
if ( allowtoggle ) {
socket . send ( { 'cmd' : $ ( this ) . attr ( 'id' ) , 'data' : $ ( this ) . prop ( 'checked' ) } ) ;
}
} ) ;
// Increment display variable
formatcount ++ ;
if ( formatcount == 2 ) {
formatcount = 0 ;
}
}
2021-05-11 06:27:34 +02:00
function addImportLine ( ob ) {
popup _content . append ( "<div class=\"popuplistitem\" id=\"import" + ob . num + "\" > \
< div > "+ob.title+" < / d i v > \
< div > "+ob.acts+" < / d i v > \
< div > "+ob.descr+" < / d i v > \
< / d i v > " ) ;
$ ( "#import" + ob . num ) . on ( "click" , function ( ) {
socket . send ( { 'cmd' : 'importselect' , 'data' : $ ( this ) . attr ( 'id' ) } ) ;
highlightImportLine ( $ ( this ) ) ;
} ) ;
}
2021-12-05 05:59:28 +01:00
function adjustWiCommentHeight ( element ) {
element . style . height = "0px" ;
element . style . height = element . scrollHeight + "px" ;
element . parentNode . parentNode . style . height = element . scrollHeight + 90 + "px" ;
}
function adjustWiFolderNameHeight ( element ) {
element . style . height = "0px" ;
element . style . height = element . scrollHeight + "px" ;
element . parentNode . parentNode . parentNode . style . height = element . scrollHeight + 19 + "px" ;
}
2021-05-13 07:26:42 +02:00
function addWiLine ( ob ) {
2021-12-05 05:59:28 +01:00
var current _wifolder _element = ob . folder === null ? $ ( ".wisortable-body:not([folder-uid])" ) . last ( ) : $ ( ".wisortable-body[folder-uid=" + ob . folder + "]" ) ;
2021-05-13 07:26:42 +02:00
if ( ob . init ) {
2021-08-19 13:48:33 +02:00
if ( ob . selective ) {
2022-01-01 03:22:51 +01:00
current _wifolder _element . append ( "<div class=\"wilistitem wilistitem-selective " + ( ob . constant ? "wilistitem-constant" : "" ) + "\" num=\"" + ob . num + "\" uid=\"" + ob . uid + "\" id=\"wilistitem" + ob . num + "\" > \
2021-12-05 05:59:28 +01:00
< div class = \ "wicomment\" > \
< textarea class = \ "form-control\" placeholder=\"Comment\" id=\"wicomment" + ob . num + "\">" + ob . comment + " < / t e x t a r e a > \
< / d i v > \
< div class = \ "wihandle\" id=\"wihandle" + ob . num + "\" > \
< div class = \ "wicentered\" > \
< span class = \ "oi oi-grid-two-up\" aria-hidden=\"true\" > < / s p a n > \
< br / > \
< span class = \ "oi oi-grid-two-up\" aria-hidden=\"true\" > < / s p a n > \
< br / > \
< span class = \ "oi oi-grid-two-up\" aria-hidden=\"true\" > < / s p a n > \
< br / > \
< span class = \ "oi oi-grid-two-up\" aria-hidden=\"true\" > < / s p a n > \
< br / > \
< span class = \ "oi oi-grid-two-up\" aria-hidden=\"true\" > < / s p a n > \
< br / > \
< span class = \ "oi oi-grid-two-up\" aria-hidden=\"true\" > < / s p a n > \
< br / > \
< span class = \ "oi oi-grid-two-up\" aria-hidden=\"true\" > < / s p a n > \
< / d i v > \
< / d i v > \
2021-08-19 13:48:33 +02:00
< div class = \ "wiremove\" > \
< button type = \ "button\" class=\"btn btn-primary heightfull\" id=\"btn_wi" + ob . num + "\" > X < / b u t t o n > \
< button type = \ "button\" class=\"btn btn-success heighthalf hidden\" id=\"btn_widel" + ob . num + "\" > ✓ < / b u t t o n > \
< button type = \ "button\" class=\"btn btn-danger heighthalf hidden\" id=\"btn_wican" + ob . num + "\" > ⮌ < / b u t t o n > \
< / d i v > \
2021-08-24 19:45:20 +02:00
< div class = \ "icon-container wikey\" > \
2021-12-05 05:59:28 +01:00
< input class = \ "form-control wiheightfull hidden\" type=\"text\" placeholder=\"Key(s)\" id=\"wikey" + ob . num + "\" > \
< input class = \ "form-control wiheighthalf\" type=\"text\" placeholder=\"Primary Key(s)\" id=\"wikeyprimary" + ob . num + "\" > \
< input class = \ "form-control wiheighthalf\" type=\"text\" placeholder=\"Secondary Key(s)\" id=\"wikeysecondary" + ob . num + "\" > \
< span class = \ "selective-key-icon " + ( ob . selective ? "selective-key-icon-enabled" : "" ) + " oi oi-layers\" id=\"selective-key-" + ob . num + "\" title=\"Toggle Selective Key mode (if enabled, this world info entry will be included in memory only if at least one PRIMARY KEY and at least one SECONDARY KEY are both present in the story)\" aria-hidden=\"true\" > < / s p a n > \
2021-08-24 19:45:20 +02:00
< span class = \ "constant-key-icon " + ( ob . constant ? "constant-key-icon-enabled" : "" ) + " oi oi-pin\" id=\"constant-key-" + ob . num + "\" title=\"Toggle Constant Key mode (if enabled, this world info entry will always be included in memory)\" aria-hidden=\"true\" > < / s p a n > \
2021-08-19 13:48:33 +02:00
< / d i v > \
< div class = \ "wientry\" > \
2021-08-24 19:45:20 +02:00
< textarea class = \ "layer-bottom form-control\" id=\"wientry" + ob . num + "\" placeholder=\"What To Remember\">" + ob . content + " < / t e x t a r e a > \
2021-08-19 13:48:33 +02:00
< / d i v > \
< / d i v > " ) ;
} else {
2022-01-01 03:22:51 +01:00
current _wifolder _element . append ( "<div class=\"wilistitem " + ( ob . constant ? "wilistitem-constant" : "" ) + "\" num=\"" + ob . num + "\" uid=\"" + ob . uid + "\" id=\"wilistitem" + ob . num + "\" > \
2021-12-05 05:59:28 +01:00
< div class = \ "wicomment\" > \
< textarea class = \ "form-control\" placeholder=\"Comment\" id=\"wicomment" + ob . num + "\">" + ob . comment + " < / t e x t a r e a > \
< / d i v > \
< div class = \ "wihandle\" id=\"wihandle" + ob . num + "\" > \
< div class = \ "wicentered\" > \
< span class = \ "oi oi-grid-two-up\" aria-hidden=\"true\" > < / s p a n > \
< br / > \
< span class = \ "oi oi-grid-two-up\" aria-hidden=\"true\" > < / s p a n > \
< br / > \
< span class = \ "oi oi-grid-two-up\" aria-hidden=\"true\" > < / s p a n > \
< br / > \
< span class = \ "oi oi-grid-two-up\" aria-hidden=\"true\" > < / s p a n > \
< br / > \
< span class = \ "oi oi-grid-two-up\" aria-hidden=\"true\" > < / s p a n > \
< br / > \
< span class = \ "oi oi-grid-two-up\" aria-hidden=\"true\" > < / s p a n > \
< br / > \
< span class = \ "oi oi-grid-two-up\" aria-hidden=\"true\" > < / s p a n > \
< / d i v > \
< / d i v > \
2021-08-19 13:48:33 +02:00
< div class = \ "wiremove\" > \
< button type = \ "button\" class=\"btn btn-primary heightfull\" id=\"btn_wi" + ob . num + "\" > X < / b u t t o n > \
< button type = \ "button\" class=\"btn btn-success heighthalf hidden\" id=\"btn_widel" + ob . num + "\" > ✓ < / b u t t o n > \
< button type = \ "button\" class=\"btn btn-danger heighthalf hidden\" id=\"btn_wican" + ob . num + "\" > ⮌ < / b u t t o n > \
< / d i v > \
2021-08-24 19:45:20 +02:00
< div class = \ "icon-container wikey\" > \
2021-12-05 05:59:28 +01:00
< input class = \ "form-control wiheightfull\" type=\"text\" placeholder=\"Key(s)\" id=\"wikey" + ob . num + "\" > \
< input class = \ "form-control wiheighthalf hidden\" type=\"text\" placeholder=\"Primary Key(s)\" id=\"wikeyprimary" + ob . num + "\" > \
< input class = \ "form-control wiheighthalf hidden\" type=\"text\" placeholder=\"Secondary Key(s)\" id=\"wikeysecondary" + ob . num + "\" > \
< span class = \ "selective-key-icon " + ( ob . selective ? "selective-key-icon-enabled" : "" ) + " oi oi-layers\" id=\"selective-key-" + ob . num + "\" title=\"Toggle Selective Key mode (if enabled, this world info entry will be included in memory only if at least one PRIMARY KEY and at least one SECONDARY KEY are both present in the story)\" aria-hidden=\"true\" > < / s p a n > \
2021-08-24 19:45:20 +02:00
< span class = \ "constant-key-icon " + ( ob . constant ? "constant-key-icon-enabled" : "" ) + " oi oi-pin\" id=\"constant-key-" + ob . num + "\" title=\"Toggle Constant Key mode (if enabled, this world info entry will always be included in memory)\" aria-hidden=\"true\" > < / s p a n > \
2021-08-19 13:48:33 +02:00
< / d i v > \
< div class = \ "wientry\" > \
< textarea class = \ "form-control\" id=\"wientry" + ob . num + "\" placeholder=\"What To Remember\">" + ob . content + " < / t e x t a r e a > \
< / d i v > \
< / d i v > " ) ;
}
2021-12-05 05:59:28 +01:00
adjustWiCommentHeight ( $ ( "#wicomment" + ob . num ) [ 0 ] ) ;
2021-05-13 07:26:42 +02:00
// Send key value to text input
$ ( "#wikey" + ob . num ) . val ( ob . key ) ;
2021-08-19 13:48:33 +02:00
$ ( "#wikeyprimary" + ob . num ) . val ( ob . key ) ;
$ ( "#wikeysecondary" + ob . num ) . val ( ob . keysecondary ) ;
2021-05-13 07:26:42 +02:00
// Assign delete event to button
$ ( "#btn_wi" + ob . num ) . on ( "click" , function ( ) {
showWiDeleteConfirm ( ob . num ) ;
} ) ;
} else {
// Show WI line item with form fields hidden (uninitialized)
2022-01-01 03:22:51 +01:00
current _wifolder _element . append ( "<div class=\"wilistitem wilistitem-uninitialized wisortable-excluded\" num=\"" + ob . num + "\" uid=\"" + ob . uid + "\" id=\"wilistitem" + ob . num + "\" > \
2021-12-05 05:59:28 +01:00
< div class = \ "wicomment\" > \
< textarea class = \ "form-control hidden\" placeholder=\"Comment\" id=\"wicomment" + ob . num + "\">" + ob . comment + " < / t e x t a r e a > \
< / d i v > \
< div class = \ "wihandle-inactive hidden\" id=\"wihandle" + ob . num + "\" > \
< div class = \ "wicentered\" > \
< span class = \ "oi oi-grid-two-up\" aria-hidden=\"true\" > < / s p a n > \
< br / > \
< span class = \ "oi oi-grid-two-up\" aria-hidden=\"true\" > < / s p a n > \
< br / > \
< span class = \ "oi oi-grid-two-up\" aria-hidden=\"true\" > < / s p a n > \
< br / > \
< span class = \ "oi oi-grid-two-up\" aria-hidden=\"true\" > < / s p a n > \
< br / > \
< span class = \ "oi oi-grid-two-up\" aria-hidden=\"true\" > < / s p a n > \
< br / > \
< span class = \ "oi oi-grid-two-up\" aria-hidden=\"true\" > < / s p a n > \
< br / > \
< span class = \ "oi oi-grid-two-up\" aria-hidden=\"true\" > < / s p a n > \
< / d i v > \
< / d i v > \
2021-05-13 07:26:42 +02:00
< div class = \ "wiremove\" > \
< button type = \ "button\" class=\"btn btn-primary heightfull\" id=\"btn_wi" + ob . num + "\" > + < / b u t t o n > \
< button type = \ "button\" class=\"btn btn-success heighthalf hidden\" id=\"btn_widel" + ob . num + "\" > ✓ < / b u t t o n > \
< button type = \ "button\" class=\"btn btn-danger heighthalf hidden\" id=\"btn_wican" + ob . num + "\" > X < / b u t t o n > \
< / d i v > \
2021-08-24 19:45:20 +02:00
< div class = \ "icon-container wikey\" > \
2021-12-05 05:59:28 +01:00
< input class = \ "form-control wiheightfull hidden\" type=\"text\" placeholder=\"Key(s)\" id=\"wikey" + ob . num + "\" > \
< input class = \ "form-control wiheighthalf hidden\" type=\"text\" placeholder=\"Primary Key(s)\" id=\"wikeyprimary" + ob . num + "\" > \
< input class = \ "form-control wiheighthalf hidden\" type=\"text\" placeholder=\"Secondary Key(s)\" id=\"wikeysecondary" + ob . num + "\" > \
< span class = \ "selective-key-icon oi oi-layers hidden\" id=\"selective-key-" + ob . num + "\" title=\"Toggle Selective Key mode (if enabled, this world info entry will be included in memory only if at least one PRIMARY KEY and at least one SECONDARY KEY are both present in the story)\" aria-hidden=\"true\" > < / s p a n > \
2021-08-24 19:45:20 +02:00
< span class = \ "constant-key-icon oi oi-pin hidden\" id=\"constant-key-" + ob . num + "\" title=\"Toggle Constant Key mode (if enabled, this world info entry will always be included in memory)\" aria-hidden=\"true\" > < / s p a n > \
2021-05-13 07:26:42 +02:00
< / d i v > \
< div class = \ "wientry\" > \
2021-08-24 19:45:20 +02:00
< textarea class = \ "layer-bottom form-control hidden\" id=\"wientry" + ob . num + "\" placeholder=\"What To Remember\">" + ob . content + " < / t e x t a r e a > \
2021-05-13 07:26:42 +02:00
< / d i v > \
< / d i v > " ) ;
// Assign function to expand WI item to button
$ ( "#btn_wi" + ob . num ) . on ( "click" , function ( ) {
2021-12-05 17:39:59 +01:00
var folder = $ ( "#wilistitem" + ob . num ) . parent ( ) . attr ( "folder-uid" ) ;
if ( folder === undefined ) {
folder = null ;
} else {
folder = parseInt ( folder ) ;
}
2021-12-05 05:59:28 +01:00
socket . send ( { 'cmd' : 'wiexpand' , 'data' : ob . num } ) ;
2021-12-05 17:39:59 +01:00
socket . send ( { 'cmd' : 'wiinit' , 'folder' : folder , 'data' : ob . num } ) ;
2021-05-13 07:26:42 +02:00
} ) ;
}
// Assign actions to other elements
2021-08-24 19:45:20 +02:00
wientry _onfocus = function ( ) {
2021-12-05 05:59:28 +01:00
$ ( "#selective-key-" + ob . num ) . addClass ( "selective-key-icon-clickthrough" ) ;
2021-08-24 19:45:20 +02:00
$ ( "#constant-key-" + ob . num ) . addClass ( "constant-key-icon-clickthrough" ) ;
}
wientry _onfocusout = function ( ) {
2021-12-05 05:59:28 +01:00
$ ( "#selective-key-" + ob . num ) . removeClass ( "selective-key-icon-clickthrough" ) ;
2021-08-24 19:45:20 +02:00
$ ( "#constant-key-" + ob . num ) . removeClass ( "constant-key-icon-clickthrough" ) ;
2021-12-05 05:59:28 +01:00
// Tell server about updated WI fields
var selective = $ ( "#wilistitem" + ob . num ) [ 0 ] . classList . contains ( "wilistitem-selective" ) ;
socket . send ( { 'cmd' : 'wiupdate' , 'num' : ob . num , 'data' : {
key : selective ? $ ( "#wikeyprimary" + ob . num ) . val ( ) : $ ( "#wikey" + ob . num ) . val ( ) ,
keysecondary : $ ( "#wikeysecondary" + ob . num ) . val ( ) ,
content : $ ( "#wientry" + ob . num ) . val ( ) ,
comment : $ ( "#wicomment" + ob . num ) . val ( ) ,
} } ) ;
2021-08-24 19:45:20 +02:00
}
$ ( "#wikey" + ob . num ) . on ( "focus" , wientry _onfocus ) ;
$ ( "#wikeyprimary" + ob . num ) . on ( "focus" , wientry _onfocus ) ;
$ ( "#wikeysecondary" + ob . num ) . on ( "focus" , wientry _onfocus ) ;
2021-12-05 05:59:28 +01:00
$ ( "#wientry" + ob . num ) . on ( "focus" , wientry _onfocus ) ;
$ ( "#wicomment" + ob . num ) . on ( "focus" , wientry _onfocus ) ;
2021-08-24 19:45:20 +02:00
$ ( "#wikey" + ob . num ) . on ( "focusout" , wientry _onfocusout ) ;
$ ( "#wikeyprimary" + ob . num ) . on ( "focusout" , wientry _onfocusout ) ;
$ ( "#wikeysecondary" + ob . num ) . on ( "focusout" , wientry _onfocusout ) ;
2021-12-05 05:59:28 +01:00
$ ( "#wientry" + ob . num ) . on ( "focusout" , wientry _onfocusout ) ;
$ ( "#wicomment" + ob . num ) . on ( "focusout" , wientry _onfocusout ) ;
2021-05-13 07:26:42 +02:00
$ ( "#btn_wican" + ob . num ) . on ( "click" , function ( ) {
hideWiDeleteConfirm ( ob . num ) ;
} ) ;
$ ( "#btn_widel" + ob . num ) . on ( "click" , function ( ) {
2022-01-01 03:22:51 +01:00
socket . send ( { 'cmd' : 'widelete' , 'data' : ob . uid } ) ;
2021-05-13 07:26:42 +02:00
} ) ;
2021-12-05 05:59:28 +01:00
$ ( "#selective-key-" + ob . num ) . on ( "click" , function ( ) {
var element = $ ( "#selective-key-" + ob . num ) ;
if ( element . hasClass ( "selective-key-icon-enabled" ) ) {
socket . send ( { 'cmd' : 'wiseloff' , 'data' : ob . num } ) ;
} else {
socket . send ( { 'cmd' : 'wiselon' , 'data' : ob . num } ) ;
}
2021-08-19 13:48:33 +02:00
} ) ;
2021-08-24 19:45:20 +02:00
$ ( "#constant-key-" + ob . num ) . on ( "click" , function ( ) {
2021-09-01 20:01:04 +02:00
var element = $ ( "#constant-key-" + ob . num ) ;
2021-08-24 19:45:20 +02:00
if ( element . hasClass ( "constant-key-icon-enabled" ) ) {
socket . send ( { 'cmd' : 'wiconstantoff' , 'data' : ob . num } ) ;
} else {
socket . send ( { 'cmd' : 'wiconstanton' , 'data' : ob . num } ) ;
}
} ) ;
2021-12-05 09:04:45 +01:00
$ ( "#wihandle" + ob . num ) . off ( ) . on ( "mousedown" , function ( ) {
wientry _onfocusout ( )
$ ( ".wisortable-container" ) . addClass ( "wisortable-excluded" ) ;
// Prevent WI entries with extremely long comments from filling the screen and preventing scrolling
$ ( this ) . parent ( ) . css ( "max-height" , "200px" ) . find ( ".wicomment" ) . find ( ".form-control" ) . css ( "max-height" , "110px" ) ;
} ) . on ( "mouseup" , function ( ) {
$ ( ".wisortable-excluded-dynamic" ) . removeClass ( "wisortable-excluded-dynamic" ) ;
$ ( this ) . parent ( ) . css ( "max-height" , "" ) . find ( ".wicomment" ) . find ( ".form-control" ) . css ( "max-height" , "" ) ;
} ) ;
2021-12-05 05:59:28 +01:00
}
function addWiFolder ( uid , ob ) {
if ( uid !== null ) {
var uninitialized = $ ( "#wilistfoldercontainer" + null ) ;
2021-12-22 19:12:35 +01:00
var html = "<div class=\"wisortable-container " + ( ob . collapsed ? "" : "folder-expanded" ) + "\" id=\"wilistfoldercontainer" + uid + "\" folder-uid=\"" + uid + "\" > \
2021-12-05 05:59:28 +01:00
< div class = \ "wilistfolder\" id=\"wilistfolder" + uid + "\" > \
< div class = \ "wiremove\" > \
< button type = \ "button\" class=\"btn btn-primary heightfull\" id=\"btn_wifolder" + uid + "\" > X < / b u t t o n > \
< button type = \ "button\" class=\"btn btn-success heighthalf hidden\" id=\"btn_wifolderdel" + uid + "\" > ✓ < / b u t t o n > \
< button type = \ "button\" class=\"btn btn-danger heighthalf hidden\" id=\"btn_wifoldercan" + uid + "\" > ⮌ < / b u t t o n > \
< / d i v > \
< div class = \ "wifoldericon\" > \
< div class = \ "wicentered\" > \
2021-12-22 19:12:35 +01:00
< span class = \ "oi oi-folder folder-expand " + ( ob . collapsed ? "" : "folder-expanded" ) + "\" id=\"btn_wifolderexpand" + uid + "\" aria-hidden=\"true\" > < / s p a n > \
2021-12-05 05:59:28 +01:00
< / d i v > \
< / d i v > \
< div class = \ "wifoldername\" > \
< div class = \ "wicentered-vertical\" > \
< textarea class = \ "form-control\" placeholder=\"Untitled Folder\" id=\"wifoldername" + uid + "\">" + ob . name + " < / t e x t a r e a > \
< / d i v > \
< / d i v > \
< div class = \ "wihandle wifolderhandle\" id=\"wifolderhandle" + uid + "\" > \
< div class = \ "wicentered\" > \
< span class = \ "oi oi-grid-two-up\" aria-hidden=\"true\" > < / s p a n > \
< br / > \
< span class = \ "oi oi-grid-two-up\" aria-hidden=\"true\" > < / s p a n > \
< br / > \
< span class = \ "oi oi-grid-two-up\" aria-hidden=\"true\" > < / s p a n > \
< / d i v > \
< / d i v > \
< / d i v > \
2021-12-05 09:29:13 +01:00
< div class = \ "wifoldergutter-container\" id=\"wifoldergutter" + uid + "\" > \
< div class = \ "wifoldergutter\" > < / d i v > \
< / d i v > \
2021-12-05 05:59:28 +01:00
< div class = \ "wisortable-body\" folder-uid=\"" + uid + "\" > \
< div class = \ "wisortable-dummy\" > < / d i v > \
< / d i v > \
< / d i v > " ;
if ( uninitialized . length ) {
$ ( html ) . insertBefore ( uninitialized ) ;
} else {
wi _menu . append ( html ) ;
}
var onfocusout = function ( ) {
socket . send ( { 'cmd' : 'wifolderupdate' , 'uid' : uid , 'data' : {
name : $ ( "#wifoldername" + uid ) . val ( ) ,
2021-12-22 19:12:35 +01:00
collapsed : ! $ ( "#btn_wifolderexpand" + uid ) . hasClass ( "folder-expanded" ) ,
2021-12-05 05:59:28 +01:00
} } ) ;
} ;
2021-12-05 09:29:13 +01:00
$ ( "#wifoldergutter" + uid ) . on ( "click" , function ( ) {
$ ( this ) . siblings ( ".wilistfolder" ) [ 0 ] . scrollIntoView ( ) ;
} ) ;
2021-12-05 05:59:28 +01:00
$ ( "#btn_wifolder" + uid ) . on ( "click" , function ( ) {
showWiFolderDeleteConfirm ( uid ) ;
} ) ;
$ ( "#btn_wifolderdel" + uid ) . on ( "click" , function ( ) {
socket . send ( { 'cmd' : 'wifolderdelete' , 'data' : uid } ) ;
} ) ;
$ ( "#btn_wifoldercan" + uid ) . on ( "click" , function ( ) {
hideWiFolderDeleteConfirm ( uid ) ;
} )
$ ( "#wifoldername" + uid ) . on ( "focusout" , onfocusout ) ;
2021-12-05 09:04:45 +01:00
$ ( "#wifolderhandle" + uid ) . off ( ) . on ( "mousedown" , function ( ) {
onfocusout ( ) ;
$ ( ".wilistitem, .wisortable-dummy" ) . addClass ( "wisortable-excluded-dynamic" ) ;
// Prevent WI folders with extremely long names from filling the screen and preventing scrolling
$ ( this ) . parent ( ) . parent ( ) . find ( ".wisortable-body" ) . addClass ( "hidden" ) ;
$ ( this ) . parent ( ) . css ( "max-height" , "200px" ) . find ( ".wifoldername" ) . find ( ".form-control" ) . css ( "max-height" , "181px" ) ;
} ) . on ( "mouseup" , function ( ) {
$ ( ".wisortable-excluded-dynamic" ) . removeClass ( "wisortable-excluded-dynamic" ) ;
$ ( this ) . parent ( ) . parent ( ) . find ( ".wisortable-body" ) . removeClass ( "hidden" ) ;
$ ( this ) . parent ( ) . css ( "max-height" , "" ) . find ( ".wifoldername" ) . find ( ".form-control" ) . css ( "max-height" , "" ) ;
} ) ;
2021-12-22 19:12:35 +01:00
$ ( "#btn_wifolderexpand" + uid ) . on ( "click" , function ( ) {
if ( $ ( this ) . hasClass ( "folder-expanded" ) ) {
socket . send ( { 'cmd' : 'wifoldercollapsecontent' , 'data' : uid } ) ;
} else {
socket . send ( { 'cmd' : 'wifolderexpandcontent' , 'data' : uid } ) ;
}
} )
2021-12-05 05:59:28 +01:00
adjustWiFolderNameHeight ( $ ( "#wifoldername" + uid ) [ 0 ] ) ;
2021-12-22 19:12:35 +01:00
if ( ob . collapsed ) {
setTimeout ( function ( ) {
var container = $ ( "#wilistfoldercontainer" + uid ) ;
hide ( [ container . find ( ".wifoldergutter-container" ) , container . find ( ".wisortable-body" ) ] ) ;
} , 2 ) ;
}
2021-12-05 05:59:28 +01:00
} else {
2021-12-22 19:12:35 +01:00
wi _menu . append ( "<div class=\"wisortable-container folder-expanded\" id=\"wilistfoldercontainer" + uid + "\" > \
2021-12-05 05:59:28 +01:00
< div class = \ "wilistfolder\" id=\"wilistfolder" + uid + "\" > \
< div class = \ "wiremove\" > \
< button type = \ "button\" class=\"btn btn-primary heightfull\" id=\"btn_wifolder" + uid + "\" > + < / b u t t o n > \
< button type = \ "button\" class=\"btn btn-success heighthalf hidden\" id=\"btn_wifolderdel" + uid + "\" > ✓ < / b u t t o n > \
< button type = \ "button\" class=\"btn btn-danger heighthalf hidden\" id=\"btn_wifoldercan" + uid + "\" > ⮌ < / b u t t o n > \
< / d i v > \
< div class = \ "wifoldericon\" > \
< div class = \ "wicentered\" > \
2021-12-22 19:12:35 +01:00
< span class = \ "oi oi-folder folder-expand folder-expanded\" id=\"btn_wifolderexpand" + uid + "\" aria-hidden=\"true\" > < / s p a n > \
2021-12-05 05:59:28 +01:00
< / d i v > \
< / d i v > \
< div class = \ "wifoldername\" > \
< div class = \ "wicentered-vertical\" > \
< textarea class = \ "form-control hidden\" placeholder=\"Untitled Folder\" id=\"wifoldername" + uid + "\" > < / t e x t a r e a > \
< / d i v > \
< / d i v > \
< div class = \ "wihandle-inactive wifolderhandle hidden\" id=\"wifolderhandle" + uid + "\" > \
< div class = \ "wicentered\" > \
< span class = \ "oi oi-grid-two-up\" aria-hidden=\"true\" > < / s p a n > \
< br / > \
< span class = \ "oi oi-grid-two-up\" aria-hidden=\"true\" > < / s p a n > \
< br / > \
< span class = \ "oi oi-grid-two-up\" aria-hidden=\"true\" > < / s p a n > \
< / d i v > \
< / d i v > \
< / d i v > \
< div class = \ "wisortable-body\" > \
< div class = \ "wisortable-dummy\" > < / d i v > \
< / d i v > \
< / d i v > " ) ;
$ ( "#btn_wifolder" + uid ) . on ( "click" , function ( ) {
expandWiFolderLine ( uid ) ;
} ) ;
}
2021-05-13 07:26:42 +02:00
}
function expandWiLine ( num ) {
2021-12-05 05:59:28 +01:00
show ( [ $ ( "#wikey" + num ) , $ ( "#wientry" + num ) , $ ( "#wihandle" + num ) , $ ( "#selective-key-" + num ) , $ ( "#constant-key-" + num ) , $ ( "#btn_wiselon" + num ) , $ ( "#wicomment" + num ) ] ) ;
$ ( "#wihandle" + num ) . removeClass ( "wihandle-inactive" ) . addClass ( "wihandle" ) ;
2021-05-13 07:26:42 +02:00
$ ( "#btn_wi" + num ) . html ( "X" ) ;
$ ( "#btn_wi" + num ) . off ( ) ;
2021-12-05 05:59:28 +01:00
$ ( "#wilistitem" + num ) . removeClass ( "wilistitem-uninitialized" ) . removeClass ( "wisortable-excluded" ) ;
2021-05-13 07:26:42 +02:00
$ ( "#btn_wi" + num ) . on ( "click" , function ( ) {
showWiDeleteConfirm ( num ) ;
} ) ;
2021-12-05 05:59:28 +01:00
adjustWiCommentHeight ( $ ( "#wicomment" + num ) [ 0 ] ) ;
}
function expandWiFolderLine ( num ) {
socket . send ( { 'cmd' : 'wifolderinit' , 'data' : '' } ) ;
2021-05-13 07:26:42 +02:00
}
function showWiDeleteConfirm ( num ) {
hide ( [ $ ( "#btn_wi" + num ) ] ) ;
show ( [ $ ( "#btn_widel" + num ) , $ ( "#btn_wican" + num ) ] ) ;
}
2021-12-05 05:59:28 +01:00
function showWiFolderDeleteConfirm ( num ) {
hide ( [ $ ( "#btn_wifolder" + num ) ] ) ;
show ( [ $ ( "#btn_wifolderdel" + num ) , $ ( "#btn_wifoldercan" + num ) ] ) ;
}
2021-05-13 07:26:42 +02:00
function hideWiDeleteConfirm ( num ) {
show ( [ $ ( "#btn_wi" + num ) ] ) ;
hide ( [ $ ( "#btn_widel" + num ) , $ ( "#btn_wican" + num ) ] ) ;
}
2021-12-05 05:59:28 +01:00
function hideWiFolderDeleteConfirm ( num ) {
show ( [ $ ( "#btn_wifolder" + num ) ] ) ;
hide ( [ $ ( "#btn_wifolderdel" + num ) , $ ( "#btn_wifoldercan" + num ) ] ) ;
}
2021-12-22 19:12:35 +01:00
function collapseWiFolderContent ( uid ) {
hide ( [ $ ( "#wifoldergutter" + uid ) , $ ( ".wisortable-body[folder-uid=" + uid + "]" ) ] ) ;
$ ( "#btn_wifolderexpand" + uid ) . removeClass ( "folder-expanded" ) ;
$ ( "#wilistfoldercontainer" + uid ) . removeClass ( "folder-expanded" ) ;
}
function expandWiFolderContent ( uid ) {
show ( [ $ ( "#wifoldergutter" + uid ) , $ ( ".wisortable-body[folder-uid=" + uid + "]" ) ] ) ;
$ ( "#btn_wifolderexpand" + uid ) . addClass ( "folder-expanded" ) ;
$ ( "#wilistfoldercontainer" + uid ) . addClass ( "folder-expanded" ) ;
}
2021-08-19 13:48:33 +02:00
function enableWiSelective ( num ) {
2021-12-05 05:59:28 +01:00
hide ( [ $ ( "#wikey" + num ) ] ) ;
2021-08-24 19:45:20 +02:00
$ ( "#wikeyprimary" + num ) . val ( $ ( "#wikey" + num ) . val ( ) ) ;
2021-12-05 05:59:28 +01:00
show ( [ $ ( "#wikeyprimary" + num ) , $ ( "#wikeysecondary" + num ) ] ) ;
var element = $ ( "#selective-key-" + num ) ;
element . addClass ( "selective-key-icon-enabled" ) ;
$ ( "#wikey" + num ) . addClass ( "wilistitem-selective" ) ;
2021-08-19 13:48:33 +02:00
}
function disableWiSelective ( num ) {
2021-12-05 05:59:28 +01:00
hide ( [ $ ( "#wikeyprimary" + num ) , $ ( "#wikeysecondary" + num ) ] ) ;
2021-08-24 19:45:20 +02:00
$ ( "#wikey" + num ) . val ( $ ( "#wikeyprimary" + num ) . val ( ) ) ;
2021-12-05 05:59:28 +01:00
show ( [ $ ( "#wikey" + num ) ] ) ;
var element = $ ( "#selective-key-" + num ) ;
element . removeClass ( "selective-key-icon-enabled" ) ;
$ ( "#wikey" + num ) . removeClass ( "wilistitem-selective" ) ;
}
function enableWiConstant ( num ) {
var element = $ ( "#constant-key-" + num ) ;
element . addClass ( "constant-key-icon-enabled" ) ;
$ ( "#wikey" + num ) . addClass ( "wilistitem-constant" ) ;
}
function disableWiConstant ( num ) {
var element = $ ( "#constant-key-" + num ) ;
element . removeClass ( "constant-key-icon-enabled" ) ;
$ ( "#wikey" + num ) . removeClass ( "wilistitem-constant" ) ;
2021-08-19 13:48:33 +02:00
}
2021-05-11 06:27:34 +02:00
function highlightImportLine ( ref ) {
$ ( "#popupcontent > div" ) . removeClass ( "popuplistselected" ) ;
ref . addClass ( "popuplistselected" ) ;
2021-05-22 11:28:40 +02:00
enableButtons ( [ popup _accept ] ) ;
2021-05-11 06:27:34 +02:00
}
2021-05-05 09:04:06 +02:00
function enableButtons ( refs ) {
for ( i = 0 ; i < refs . length ; i ++ ) {
refs [ i ] . prop ( "disabled" , false ) ;
refs [ i ] . removeClass ( "btn-secondary" ) ;
refs [ i ] . addClass ( "btn-primary" ) ;
}
2021-05-03 00:48:47 +02:00
}
2021-05-05 09:04:06 +02:00
function disableButtons ( refs ) {
for ( i = 0 ; i < refs . length ; i ++ ) {
refs [ i ] . prop ( "disabled" , true ) ;
refs [ i ] . removeClass ( "btn-primary" ) ;
refs [ i ] . addClass ( "btn-secondary" ) ;
}
2021-05-03 00:48:47 +02:00
}
function enableSendBtn ( ) {
2022-01-10 22:36:15 +01:00
button _send . removeClass ( "wait" ) ;
button _send . addClass ( "btn-primary" ) ;
2021-05-03 00:48:47 +02:00
button _send . html ( "Submit" ) ;
}
function disableSendBtn ( ) {
2022-01-10 22:36:15 +01:00
button _send . removeClass ( "btn-primary" ) ;
button _send . addClass ( "wait" ) ;
2021-05-03 00:48:47 +02:00
button _send . html ( "" ) ;
}
function showMessage ( msg ) {
message _text . removeClass ( ) ;
message _text . addClass ( "color_green" ) ;
message _text . html ( msg ) ;
}
2022-01-17 03:09:10 +01:00
function errMessage ( msg , type = "error" ) {
2021-05-03 00:48:47 +02:00
message _text . removeClass ( ) ;
2022-01-17 03:09:10 +01:00
message _text . addClass ( type == "warn" ? "color_orange" : "color_red" ) ;
2021-05-03 00:48:47 +02:00
message _text . html ( msg ) ;
}
function hideMessage ( ) {
message _text . html ( "" ) ;
message _text . removeClass ( ) ;
}
function showWaitAnimation ( ) {
2021-12-20 02:18:28 +01:00
hideWaitAnimation ( ) ;
2021-05-03 00:48:47 +02:00
$ ( "#inputrowright" ) . append ( "<img id=\"waitanim\" src=\"static/thinking.gif\"/>" ) ;
}
function hideWaitAnimation ( ) {
$ ( '#waitanim' ) . remove ( ) ;
}
2021-08-26 21:15:42 +02:00
function scrollToBottom ( ) {
setTimeout ( function ( ) {
2021-09-28 00:10:33 +02:00
game _text . stop ( true ) . animate ( { scrollTop : game _text . prop ( 'scrollHeight' ) } , 500 ) ;
2021-08-26 21:15:42 +02:00
} , 5 ) ;
}
2021-05-05 09:04:06 +02:00
function hide ( refs ) {
for ( i = 0 ; i < refs . length ; i ++ ) {
refs [ i ] . addClass ( "hidden" ) ;
}
2021-05-03 00:48:47 +02:00
}
2021-05-05 09:04:06 +02:00
function show ( refs ) {
for ( i = 0 ; i < refs . length ; i ++ ) {
refs [ i ] . removeClass ( "hidden" ) ;
}
2021-05-03 00:48:47 +02:00
}
2021-05-11 06:27:34 +02:00
function popupShow ( state ) {
if ( state ) {
popup . removeClass ( "hidden" ) ;
popup . addClass ( "flex" ) ;
2021-05-22 11:28:40 +02:00
disableButtons ( [ popup _accept ] ) ;
2021-05-11 06:27:34 +02:00
} else {
popup . removeClass ( "flex" ) ;
popup . addClass ( "hidden" ) ;
}
}
2021-05-03 00:48:47 +02:00
function enterEditMode ( ) {
2021-08-23 08:34:27 +02:00
editmode = true ;
2021-05-03 00:48:47 +02:00
}
function exitEditMode ( ) {
2021-08-23 08:34:27 +02:00
editmode = false ;
2021-05-03 00:48:47 +02:00
}
function enterMemoryMode ( ) {
2021-08-19 13:18:01 +02:00
memorymode = true ;
setmodevisibility ( false ) ;
2021-12-27 04:21:58 +01:00
setchatnamevisibility ( false ) ;
2021-05-03 00:48:47 +02:00
showMessage ( "Edit the memory to be sent with each request to the AI." ) ;
button _actmem . html ( "Cancel" ) ;
2022-01-22 01:02:56 +01:00
hide ( [ button _actback , button _actfwd , button _actretry , button _actwi ] ) ;
2021-05-05 09:04:06 +02:00
// Display Author's Note field
anote _menu . slideDown ( "fast" ) ;
2021-05-03 00:48:47 +02:00
}
function exitMemoryMode ( ) {
2021-08-19 13:18:01 +02:00
memorymode = false ;
setmodevisibility ( adventure ) ;
2021-12-27 04:21:58 +01:00
setchatnamevisibility ( chatmode ) ;
2021-05-03 00:48:47 +02:00
hideMessage ( ) ;
button _actmem . html ( "Memory" ) ;
2022-01-22 01:02:56 +01:00
show ( [ button _actback , button _actfwd , button _actretry , button _actwi ] ) ;
2021-05-03 00:48:47 +02:00
input _text . val ( "" ) ;
2021-05-05 09:04:06 +02:00
// Hide Author's Note field
anote _menu . slideUp ( "fast" ) ;
2021-05-03 00:48:47 +02:00
}
2021-05-13 07:26:42 +02:00
function enterWiMode ( ) {
showMessage ( "World Info will be added to memory only when the key appears in submitted text or the last action." ) ;
button _actwi . html ( "Accept" ) ;
2022-01-22 01:02:56 +01:00
hide ( [ button _actback , button _actfwd , button _actmem , button _actretry , game _text ] ) ;
2021-12-27 04:21:58 +01:00
setchatnamevisibility ( false ) ;
2021-05-13 07:26:42 +02:00
show ( [ wi _menu ] ) ;
disableSendBtn ( ) ;
2021-09-29 01:00:23 +02:00
$ ( "#gamescreen" ) . addClass ( "wigamescreen" ) ;
2021-05-13 07:26:42 +02:00
}
function exitWiMode ( ) {
hideMessage ( ) ;
button _actwi . html ( "W Info" ) ;
hide ( [ wi _menu ] ) ;
2021-12-27 04:21:58 +01:00
setchatnamevisibility ( chatmode ) ;
2022-01-22 01:02:56 +01:00
show ( [ button _actback , button _actfwd , button _actmem , button _actretry , game _text ] ) ;
2021-05-13 07:26:42 +02:00
enableSendBtn ( ) ;
2021-09-29 01:00:23 +02:00
$ ( "#gamescreen" ) . removeClass ( "wigamescreen" ) ;
2021-05-13 07:26:42 +02:00
}
function returnWiList ( ar ) {
var list = [ ] ;
var i ;
for ( i = 0 ; i < ar . length ; i ++ ) {
2021-12-05 17:39:59 +01:00
var folder = $ ( "#wilistitem" + ar [ i ] ) . parent ( ) . attr ( "folder-uid" ) ;
if ( folder === undefined ) {
folder = null ;
} else {
folder = parseInt ( folder ) ;
}
2022-01-01 03:22:51 +01:00
var ob = { "key" : "" , "keysecondary" : "" , "content" : "" , "comment" : "" , "folder" : null , "uid" : parseInt ( $ ( "#wilistitem" + ar [ i ] ) . attr ( "uid" ) ) , "selective" : false , "constant" : false } ;
2021-08-19 13:48:33 +02:00
ob . selective = $ ( "#wikeyprimary" + ar [ i ] ) . css ( "display" ) != "none"
ob . key = ob . selective ? $ ( "#wikeyprimary" + ar [ i ] ) . val ( ) : $ ( "#wikey" + ar [ i ] ) . val ( ) ;
2021-12-05 05:59:28 +01:00
ob . keysecondary = $ ( "#wikeysecondary" + ar [ i ] ) . val ( ) ;
2021-08-19 13:48:33 +02:00
ob . content = $ ( "#wientry" + ar [ i ] ) . val ( ) ;
2021-12-05 05:59:28 +01:00
ob . comment = $ ( "#wicomment" + i ) . val ( ) ;
2021-12-05 17:39:59 +01:00
ob . folder = folder ;
2021-08-24 19:45:20 +02:00
ob . constant = $ ( "#constant-key-" + ar [ i ] ) . hasClass ( "constant-key-icon-enabled" ) ;
2021-05-13 07:26:42 +02:00
list . push ( ob ) ;
}
socket . send ( { 'cmd' : 'sendwilist' , 'data' : list } ) ;
}
2021-10-13 06:42:03 +02:00
function formatChunkInnerText ( chunk ) {
var text = chunk . innerText . replace ( /\u00a0/g , " " ) ;
if ( ( chunk . nextSibling === null || chunk . nextSibling . nodeType !== 1 || chunk . nextSibling . tagName !== "CHUNK" ) && text . slice ( - 1 ) === '\n' ) {
return text . slice ( 0 , - 1 ) ;
}
return text ;
}
2022-01-10 22:36:15 +01:00
function dosubmit ( disallow _abort ) {
2022-07-28 05:13:08 +02:00
ignore _stream = false ;
2022-06-11 02:51:22 +02:00
submit _start = Date . now ( ) ;
2021-09-29 01:48:43 +02:00
var txt = input _text . val ( ) . replace ( /\u00a0/g , " " ) ;
2022-01-10 23:09:47 +01:00
if ( ( disallow _abort || gamestate !== "wait" ) && ! memorymode && ! gamestarted && ( ( ! adventure || ! action _mode ) && txt . trim ( ) . length == 0 ) ) {
2021-09-29 01:48:43 +02:00
return ;
}
2022-06-26 19:40:58 +02:00
chunkOnFocusOut ( "override" ) ;
2022-06-30 18:23:06 +02:00
// Wait for editor changes to be applied before submitting
submit _throttle = getThrottle ( 70 ) ;
submit _throttle . txt = txt ;
submit _throttle . disallow _abort = disallow _abort ;
submit _throttle ( 0 , _dosubmit ) ;
}
function _dosubmit ( ) {
2022-07-28 05:13:08 +02:00
ignore _stream = false ;
2022-06-30 18:23:06 +02:00
var txt = submit _throttle . txt ;
var disallow _abort = submit _throttle . disallow _abort ;
submit _throttle = null ;
2021-12-13 09:21:08 +01:00
input _text . val ( "" ) ;
hideMessage ( ) ;
hidegenseqs ( ) ;
2022-01-10 22:36:15 +01:00
socket . send ( { 'cmd' : 'submit' , 'allowabort' : ! disallow _abort , 'actionmode' : adventure ? action _mode : 0 , 'chatname' : chatmode ? chat _name . val ( ) : undefined , 'data' : txt } ) ;
2021-05-03 00:48:47 +02:00
}
2021-08-19 13:18:01 +02:00
function changemode ( ) {
if ( gamestarted ) {
action _mode += 1 ;
action _mode %= 2 ; // Total number of action modes (Story and Action)
} else {
action _mode = 0 ; // Force "Story" mode if game is not started
}
switch ( action _mode ) {
case 0 : button _mode _label . html ( "Story" ) ; break ;
case 1 : button _mode _label . html ( "Action" ) ; break ;
}
}
2021-05-03 00:48:47 +02:00
function newTextHighlight ( ref ) {
2021-08-23 08:34:27 +02:00
ref . addClass ( "edit-flash" ) ;
2021-05-03 00:48:47 +02:00
setTimeout ( function ( ) {
2021-08-23 08:34:27 +02:00
ref . addClass ( "colorfade" ) ;
ref . removeClass ( "edit-flash" ) ;
2021-05-03 00:48:47 +02:00
setTimeout ( function ( ) {
2021-05-16 11:29:39 +02:00
ref . removeClass ( "colorfade" ) ;
2021-05-03 00:48:47 +02:00
} , 1000 ) ;
2021-08-24 00:52:45 +02:00
} , 50 ) ;
2021-05-03 00:48:47 +02:00
}
2021-05-16 11:29:39 +02:00
function showAidgPopup ( ) {
aidgpopup . removeClass ( "hidden" ) ;
aidgpopup . addClass ( "flex" ) ;
aidgpromptnum . focus ( ) ;
}
function hideAidgPopup ( ) {
aidgpopup . removeClass ( "flex" ) ;
aidgpopup . addClass ( "hidden" ) ;
}
function sendAidgImportRequest ( ) {
socket . send ( { 'cmd' : 'aidgimport' , 'data' : aidgpromptnum . val ( ) } ) ;
hideAidgPopup ( ) ;
aidgpromptnum . val ( "" ) ;
}
2021-05-22 11:28:40 +02:00
function showSaveAsPopup ( ) {
disableButtons ( [ saveas _accept ] ) ;
saveaspopup . removeClass ( "hidden" ) ;
saveaspopup . addClass ( "flex" ) ;
saveasinput . focus ( ) ;
}
function hideSaveAsPopup ( ) {
saveaspopup . removeClass ( "flex" ) ;
saveaspopup . addClass ( "hidden" ) ;
saveasinput . val ( "" ) ;
2021-09-01 00:22:30 +02:00
hide ( [ $ ( ".saveasoverwrite" ) , $ ( ".popuperror" ) ] ) ;
2021-05-22 11:28:40 +02:00
}
function sendSaveAsRequest ( ) {
2022-01-22 14:48:32 +01:00
socket . send ( { 'cmd' : 'saveasrequest' , 'data' : { "name" : saveasinput . val ( ) , "pins" : savepins . val ( ) } } ) ;
2021-05-22 11:28:40 +02:00
}
2022-03-07 01:51:35 +01:00
function showLoadModelPopup ( ) {
loadmodelpopup . removeClass ( "hidden" ) ;
loadmodelpopup . addClass ( "flex" ) ;
}
function hideLoadModelPopup ( ) {
loadmodelpopup . removeClass ( "flex" ) ;
loadmodelpopup . addClass ( "hidden" ) ;
loadmodelcontent . html ( "" ) ;
}
2021-05-22 11:28:40 +02:00
function showLoadPopup ( ) {
loadpopup . removeClass ( "hidden" ) ;
loadpopup . addClass ( "flex" ) ;
}
function hideLoadPopup ( ) {
loadpopup . removeClass ( "flex" ) ;
loadpopup . addClass ( "hidden" ) ;
loadcontent . html ( "" ) ;
}
2021-10-22 20:18:10 +02:00
function showSPPopup ( ) {
sppopup . removeClass ( "hidden" ) ;
sppopup . addClass ( "flex" ) ;
}
function hideSPPopup ( ) {
sppopup . removeClass ( "flex" ) ;
sppopup . addClass ( "hidden" ) ;
spcontent . html ( "" ) ;
}
2021-12-13 07:03:26 +01:00
function showUSPopup ( ) {
uspopup . removeClass ( "hidden" ) ;
uspopup . addClass ( "flex" ) ;
}
function hideUSPopup ( ) {
uspopup . removeClass ( "flex" ) ;
uspopup . addClass ( "hidden" ) ;
spcontent . html ( "" ) ;
}
2022-06-14 02:18:09 +02:00
function showSamplersPopup ( ) {
samplerspopup . removeClass ( "hidden" ) ;
samplerspopup . addClass ( "flex" ) ;
}
function hideSamplersPopup ( ) {
samplerspopup . removeClass ( "flex" ) ;
samplerspopup . addClass ( "hidden" ) ;
}
2022-03-07 01:51:35 +01:00
2022-06-15 01:39:11 +02:00
function buildLoadModelList ( ar , menu , breadcrumbs , showdelete ) {
2022-03-07 01:51:35 +01:00
disableButtons ( [ load _model _accept ] ) ;
loadmodelcontent . html ( "" ) ;
2022-06-09 00:42:44 +02:00
$ ( "#loadmodellistbreadcrumbs" ) . html ( "" ) ;
2022-06-13 19:48:45 +02:00
$ ( "#custommodelname" ) . addClass ( "hidden" ) ;
2022-03-07 01:51:35 +01:00
var i ;
2022-06-09 00:42:44 +02:00
for ( i = 0 ; i < breadcrumbs . length ; i ++ ) {
2022-06-09 01:39:04 +02:00
$ ( "#loadmodellistbreadcrumbs" ) . append ( "<button class=\"breadcrumbitem\" id='model_breadcrumbs" + i + "' name='" + ar [ 0 ] [ 1 ] + "' value='" + breadcrumbs [ i ] [ 0 ] + "'>" + breadcrumbs [ i ] [ 1 ] + "</button><font color=white>\\</font>" ) ;
2022-06-09 00:42:44 +02:00
$ ( "#model_breadcrumbs" + i ) . off ( "click" ) . on ( "click" , ( function ( ) {
return function ( ) {
socket . send ( { 'cmd' : 'selectmodel' , 'data' : $ ( this ) . attr ( "name" ) , 'folder' : $ ( this ) . attr ( "value" ) } ) ;
disableButtons ( [ load _model _accept ] ) ;
}
} ) ( i ) ) ;
}
2022-06-09 01:39:04 +02:00
if ( breadcrumbs . length > 0 ) {
$ ( "#loadmodellistbreadcrumbs" ) . append ( "<hr size='1'>" )
}
2022-03-07 01:51:35 +01:00
for ( i = 0 ; i < ar . length ; i ++ ) {
2022-06-15 01:11:30 +02:00
if ( Array . isArray ( ar [ i ] [ 0 ] ) ) {
full _path = ar [ i ] [ 0 ] [ 0 ] ;
folder = ar [ i ] [ 0 ] [ 1 ] ;
} else {
full _path = "" ;
folder = ar [ i ] [ 0 ] ;
}
2022-03-07 01:51:35 +01:00
var html
html = "<div class=\"flex\" > \
< div class = \ "loadlistpadding\"></div>"
2022-06-09 00:42:44 +02:00
//if the menu item is a link to another menu
2022-03-07 01:51:35 +01:00
if ( ar [ i ] [ 3 ] ) {
html = html + "<span class=\"loadlisticon loadmodellisticon-folder oi oi-folder allowed\" aria-hidden=\"true\"></span>"
} else {
2022-06-09 00:42:44 +02:00
//this is a model
2022-03-07 01:51:35 +01:00
html = html + "<div class=\"loadlistpadding\"></div>"
}
2022-06-15 01:11:30 +02:00
//now let's do the delete icon if applicable
2022-06-15 01:39:11 +02:00
if ( [ 'NeoCustom' , 'GPT2Custom' ] . includes ( menu ) && ! ar [ i ] [ 3 ] && showdelete ) {
2022-06-15 01:11:30 +02:00
html = html + "<span class=\"loadlisticon loadmodellisticon-folder oi oi-x allowed\" aria-hidden=\"true\" onclick='if(confirm(\"This will delete the selected folder with all contents. Are you sure?\")) { socket.send({\"cmd\": \"delete_model\", \"data\": \"" + full _path . replaceAll ( "\\" , "\\\\" ) + "\", \"menu\": \"" + menu + "\"});}'></span>"
2022-06-09 00:42:44 +02:00
} else {
2022-06-15 01:11:30 +02:00
html = html + "<div class=\"loadlistpadding\"></div>"
2022-06-09 00:42:44 +02:00
}
2022-06-15 01:11:30 +02:00
2022-03-07 01:51:35 +01:00
html = html + "<div class=\"loadlistpadding\" > < / d i v > \
2022-06-09 00:42:44 +02:00
< div class = \ "loadlistitem\" id=\"loadmodel" + i + "\" name=\"" + ar [ i ] [ 1 ] + "\" pretty_name=\"" + full _path + "\" > \
< div > "+folder+" < / d i v > \
2022-03-07 01:51:35 +01:00
< div class = \ "flex-push-right\">" + ar [ i ] [ 2 ] + " < / d i v > \
< / d i v > \
< / d i v > "
loadmodelcontent . append ( html ) ;
2022-03-12 20:21:11 +01:00
//If this is a menu
2022-03-07 01:51:35 +01:00
if ( ar [ i ] [ 3 ] ) {
$ ( "#loadmodel" + i ) . off ( "click" ) . on ( "click" , ( function ( ) {
return function ( ) {
2022-03-07 02:55:11 +01:00
socket . send ( { 'cmd' : 'list_model' , 'data' : $ ( this ) . attr ( "name" ) , 'pretty_name' : $ ( this ) . attr ( "pretty_name" ) } ) ;
2022-03-07 01:51:35 +01:00
disableButtons ( [ load _model _accept ] ) ;
}
} ) ( i ) ) ;
2022-03-12 20:21:11 +01:00
//If we're in the custom load menu (we need to send the path data back in that case)
2022-06-09 00:42:44 +02:00
} else if ( [ 'NeoCustom' , 'GPT2Custom' ] . includes ( menu ) ) {
2022-03-07 02:55:11 +01:00
$ ( "#loadmodel" + i ) . off ( "click" ) . on ( "click" , ( function ( ) {
return function ( ) {
socket . send ( { 'cmd' : 'selectmodel' , 'data' : $ ( this ) . attr ( "name" ) , 'path' : $ ( this ) . attr ( "pretty_name" ) } ) ;
highlightLoadLine ( $ ( this ) ) ;
}
} ) ( i ) ) ;
2022-06-13 19:48:45 +02:00
$ ( "#custommodelname" ) . removeClass ( "hidden" ) ;
$ ( "#custommodelname" ) [ 0 ] . setAttribute ( "menu" , menu ) ;
2022-03-12 20:21:11 +01:00
//Normal load
2022-03-07 01:51:35 +01:00
} else {
$ ( "#loadmodel" + i ) . off ( "click" ) . on ( "click" , ( function ( ) {
return function ( ) {
2022-06-07 01:21:10 +02:00
$ ( "#use_gpu_div" ) . addClass ( "hidden" ) ;
$ ( "#modelkey" ) . addClass ( "hidden" ) ;
$ ( "#modellayers" ) . addClass ( "hidden" ) ;
2022-03-07 01:51:35 +01:00
socket . send ( { 'cmd' : 'selectmodel' , 'data' : $ ( this ) . attr ( "name" ) } ) ;
highlightLoadLine ( $ ( this ) ) ;
}
} ) ( i ) ) ;
}
}
}
2021-05-22 11:28:40 +02:00
function buildLoadList ( ar ) {
disableButtons ( [ load _accept ] ) ;
loadcontent . html ( "" ) ;
showLoadPopup ( ) ;
var i ;
for ( i = 0 ; i < ar . length ; i ++ ) {
2021-09-01 00:22:30 +02:00
loadcontent . append ( "<div class=\"flex\" > \
< div class = \ "loadlistpadding\" > < / d i v > \
< span class = \ "loadlisticon loadlisticon-delete oi oi-x " + ( sman _allow _delete ? "allowed" : "" ) + "\" id=\"loaddelete" + i + "\" " + ( sman _allow _delete ? "title=\"Delete story\"" : "" ) + " aria-hidden=\"true\" > < / s p a n > \
< div class = \ "loadlistpadding\" > < / d i v > \
< span class = \ "loadlisticon loadlisticon-rename oi oi-pencil " + ( sman _allow _rename ? "allowed" : "" ) + "\" id=\"loadrename" + i + "\" " + ( sman _allow _rename ? "title=\"Rename story\"" : "" ) + " aria-hidden=\"true\" > < / s p a n > \
< div class = \ "loadlistpadding\" > < / d i v > \
< div class = \ "loadlistitem\" id=\"load" + i + "\" name=\"" + ar [ i ] . name + "\" > \
< div > "+ar[i].name+" < / d i v > \
< div class = \ "flex-push-right\">" + ar [ i ] . actions + " < / d i v > \
< / d i v > \
2021-05-22 11:28:40 +02:00
< / d i v > " ) ;
$ ( "#load" + i ) . on ( "click" , function ( ) {
enableButtons ( [ load _accept ] ) ;
socket . send ( { 'cmd' : 'loadselect' , 'data' : $ ( this ) . attr ( "name" ) } ) ;
highlightLoadLine ( $ ( this ) ) ;
} ) ;
2021-09-01 00:22:30 +02:00
$ ( "#loaddelete" + i ) . off ( "click" ) . on ( "click" , ( function ( name ) {
return function ( ) {
if ( ! sman _allow _delete ) {
return ;
}
$ ( "#loadcontainerdelete-storyname" ) . text ( name ) ;
$ ( "#btn_dsaccept" ) . off ( "click" ) . on ( "click" , ( function ( name ) {
return function ( ) {
hide ( [ $ ( ".saveasoverwrite" ) , $ ( ".popuperror" ) ] ) ;
socket . send ( { 'cmd' : 'deletestory' , 'data' : name } ) ;
}
} ) ( name ) ) ;
$ ( "#loadcontainerdelete" ) . removeClass ( "hidden" ) . addClass ( "flex" ) ;
}
} ) ( ar [ i ] . name ) ) ;
$ ( "#loadrename" + i ) . off ( "click" ) . on ( "click" , ( function ( name ) {
return function ( ) {
if ( ! sman _allow _rename ) {
return ;
}
$ ( "#newsavename" ) . val ( "" )
$ ( "#loadcontainerrename-storyname" ) . text ( name ) ;
2021-09-01 20:01:04 +02:00
var submit = ( function ( name ) {
2021-09-01 00:22:30 +02:00
return function ( ) {
hide ( [ $ ( ".saveasoverwrite" ) , $ ( ".popuperror" ) ] ) ;
socket . send ( { 'cmd' : 'renamestory' , 'data' : name , 'newname' : $ ( "#newsavename" ) . val ( ) } ) ;
}
} ) ( name ) ;
$ ( "#btn_rensaccept" ) . off ( "click" ) . on ( "click" , submit ) ;
2021-09-01 20:12:12 +02:00
$ ( "#newsavename" ) . off ( "keydown" ) . on ( "keydown" , function ( ev ) {
if ( ev . which == 13 && $ ( this ) . val ( ) != "" ) {
submit ( ) ;
}
} ) ;
2021-09-01 00:22:30 +02:00
$ ( "#loadcontainerrename" ) . removeClass ( "hidden" ) . addClass ( "flex" ) ;
$ ( "#newsavename" ) . val ( name ) . select ( ) ;
}
} ) ( ar [ i ] . name ) ) ;
2021-05-22 11:28:40 +02:00
}
}
2021-10-22 20:18:10 +02:00
function buildSPList ( ar ) {
disableButtons ( [ sp _accept ] ) ;
spcontent . html ( "" ) ;
showSPPopup ( ) ;
ar . push ( { filename : '' , name : "[None]" } )
for ( var i = 0 ; i < ar . length ; i ++ ) {
2022-01-18 22:30:09 +01:00
var author = ! ar [ i ] . author
2021-10-22 20:18:10 +02:00
? ''
2022-01-18 22:30:09 +01:00
: ar [ i ] . author . constructor === Array
? ar [ i ] . author . join ( ', ' )
: ar [ i ] . author ;
var n _tokens = ! ar [ i ] . n _tokens || ! Number . isSafeInteger ( ar [ i ] . n _tokens ) || ar [ i ] . n _tokens < 1
? ''
: "(" + ar [ i ] . n _tokens + " tokens)" ;
2021-10-22 20:25:25 +02:00
var filename = ar [ i ] . filename . replace ( /&/g , '&' ) . replace ( /</g , '<' ) . replace ( />/g , '>' ) . replace ( /"/g , '"' ) . replace ( /'/g , ''' ) . replace ( /(?=\r|\n)\r?\n?/g , '<br/>' ) ;
2021-10-22 20:18:10 +02:00
var name = ar [ i ] . name || ar [ i ] . filename ;
name = name . length > 120 ? name . slice ( 0 , 117 ) + '...' : name ;
2021-10-22 20:25:25 +02:00
name = name . replace ( /&/g , '&' ) . replace ( /</g , '<' ) . replace ( />/g , '>' ) . replace ( /"/g , '"' ) . replace ( /'/g , ''' ) . replace ( /(?=\r|\n)\r?\n?/g , '<br/>' ) ;
2021-10-22 20:18:10 +02:00
var desc = ar [ i ] . description || '' ;
desc = desc . length > 500 ? desc . slice ( 0 , 497 ) + '...' : desc ;
2021-10-22 20:25:25 +02:00
desc = desc . replace ( /&/g , '&' ) . replace ( /</g , '<' ) . replace ( />/g , '>' ) . replace ( /"/g , '"' ) . replace ( /'/g , ''' ) . replace ( /(?=\r|\n)\r?\n?/g , '<br/>' ) ;
2021-10-22 20:18:10 +02:00
spcontent . append ( "<div class=\"flex\" > \
< div class = \ "splistitem flex-row-container\" id=\"sp" + i + "\" name=\"" + ar [ i ] . filename + "\" > \
< div class = \ "flex-row\" > \
< div > "+name+" < / d i v > \
2021-10-22 20:25:25 +02:00
< div class = \ "flex-push-right splistitemsub\">" + filename + " < / d i v > \
2021-10-22 20:18:10 +02:00
< / d i v > \
< div class = \ "flex-row\" > \
< div > "+desc+" < / d i v > \
2022-01-18 22:30:09 +01:00
< div class = \ "flex-push-right splistitemsub\">" + author + "<br/>" + n _tokens + " < / d i v > \
2021-10-22 20:18:10 +02:00
< / d i v > \
< / d i v > \
< / d i v > " ) ;
$ ( "#sp" + i ) . on ( "click" , function ( ) {
enableButtons ( [ sp _accept ] ) ;
socket . send ( { 'cmd' : 'spselect' , 'data' : $ ( this ) . attr ( "name" ) } ) ;
highlightSPLine ( $ ( this ) ) ;
} ) ;
}
}
2021-12-13 07:03:26 +01:00
function buildUSList ( unloaded , loaded ) {
usunloaded . html ( "" ) ;
usloaded . html ( "" ) ;
showUSPopup ( ) ;
var i ;
var j ;
var el = usunloaded ;
var ar = unloaded ;
for ( j = 0 ; j < 2 ; j ++ ) {
for ( i = 0 ; i < ar . length ; i ++ ) {
el . append ( "<div class=\"flex\" > \
< div class = \ "uslistitem flex-row-container\" name=\"" + ar [ i ] . filename + "\" > \
< div class = \ "flex-row\" > \
< div > "+ar[i].modulename+" < / d i v > \
< div class = \ "flex-push-right uslistitemsub\"><" + ar [ i ] . filename + " & gt ; < / d i v > \
< / d i v > \
< div class = \ "flex-row\" > \
< div > "+ar[i].description+" < / d i v > \
< / d i v > \
< / d i v > \
< / d i v > " ) ;
}
el = usloaded ;
ar = loaded ;
}
}
2022-06-14 02:18:09 +02:00
function buildSamplerList ( samplers ) {
samplerslist . html ( "" ) ;
showSamplersPopup ( ) ;
var i ;
var samplers _lookup _table = [
"Top-k Sampling" ,
"Top-a Sampling" ,
"Top-p Sampling" ,
"Tail-free Sampling" ,
"Typical Sampling" ,
"Temperature" ,
]
for ( i = 0 ; i < samplers . length ; i ++ ) {
samplerslist . append ( "<div class=\"flex\" > \
< div class = \ "samplerslistitem flex-row-container\" sid=\"" + samplers [ i ] + "\" > \
< div class = \ "flex-row\" > \
< div > "+samplers_lookup_table[samplers[i]]+" < / d i v > \
< / d i v > \
< / d i v > \
< / d i v > " ) ;
}
}
2021-05-22 11:28:40 +02:00
function highlightLoadLine ( ref ) {
2021-09-01 20:21:07 +02:00
$ ( "#loadlistcontent > div > div.popuplistselected" ) . removeClass ( "popuplistselected" ) ;
2022-03-07 17:27:23 +01:00
$ ( "#loadmodellistcontent > div > div.popuplistselected" ) . removeClass ( "popuplistselected" ) ;
2021-05-22 11:28:40 +02:00
ref . addClass ( "popuplistselected" ) ;
}
2021-10-22 20:18:10 +02:00
function highlightSPLine ( ref ) {
$ ( "#splistcontent > div > div.popuplistselected" ) . removeClass ( "popuplistselected" ) ;
ref . addClass ( "popuplistselected" ) ;
}
2021-05-22 11:28:40 +02:00
function showNewStoryPopup ( ) {
nspopup . removeClass ( "hidden" ) ;
nspopup . addClass ( "flex" ) ;
}
function hideNewStoryPopup ( ) {
nspopup . removeClass ( "flex" ) ;
nspopup . addClass ( "hidden" ) ;
}
2021-08-19 12:54:44 +02:00
function showRandomStoryPopup ( ) {
rspopup . removeClass ( "hidden" ) ;
rspopup . addClass ( "flex" ) ;
2021-12-30 05:15:59 +01:00
if ( $ ( "#setrngpersist" ) . prop ( "checked" ) ) {
$ ( "#rngmemory" ) . val ( memorytext ) ;
}
2021-08-19 12:54:44 +02:00
}
function hideRandomStoryPopup ( ) {
rspopup . removeClass ( "flex" ) ;
rspopup . addClass ( "hidden" ) ;
}
2021-12-23 05:33:27 +01:00
function statFlash ( ref ) {
ref . addClass ( "status-flash" ) ;
setTimeout ( function ( ) {
ref . addClass ( "colorfade" ) ;
ref . removeClass ( "status-flash" ) ;
setTimeout ( function ( ) {
ref . removeClass ( "colorfade" ) ;
} , 1000 ) ;
} , 50 ) ;
}
function updateUSStatItems ( items , flash ) {
var stat _us = $ ( "#stat-us" ) ;
var stat _usactive = $ ( "#stat-usactive" ) ;
if ( flash || stat _usactive . find ( "li" ) . length != items . length ) {
statFlash ( stat _us . closest ( ".statusicon" ) . add ( "#usiconlabel" ) ) ;
}
stat _usactive . html ( "" ) ;
if ( items . length == 0 ) {
stat _us . html ( "No userscripts active" ) ;
$ ( "#usiconlabel" ) . html ( "" ) ;
stat _us . closest ( ".statusicon" ) . removeClass ( "active" ) ;
return ;
}
stat _us . html ( "Active userscripts:" ) ;
stat _us . closest ( ".statusicon" ) . addClass ( "active" ) ;
var i ;
for ( i = 0 ; i < items . length ; i ++ ) {
stat _usactive . append ( $ ( "<li filename=\"" + items [ i ] . filename + "\">" + items [ i ] . modulename + " <" + items [ i ] . filename + "></li>" ) ) ;
}
$ ( "#usiconlabel" ) . html ( items . length ) ;
}
function updateSPStatItems ( items ) {
var stat _sp = $ ( "#stat-sp" ) ;
var stat _spactive = $ ( "#stat-spactive" ) ;
var key = null ;
var old _val = stat _spactive . html ( ) ;
Object . keys ( items ) . forEach ( function ( k ) { key = k ; } ) ;
if ( key === null ) {
stat _sp . html ( "No soft prompt active" ) ;
stat _sp . closest ( ".statusicon" ) . removeClass ( "active" ) ;
stat _spactive . html ( "" ) ;
} else {
2022-01-18 22:30:09 +01:00
stat _sp . html ( "Active soft prompt (" + items [ key ] . n _tokens + " tokens):" ) ;
2021-12-23 05:33:27 +01:00
stat _sp . closest ( ".statusicon" ) . addClass ( "active" ) ;
stat _spactive . html ( ( items [ key ] . name || key ) + " <" + key + ">" ) ;
}
if ( stat _spactive . html ( ) !== old _val ) {
statFlash ( stat _sp . closest ( ".statusicon" ) ) ;
}
}
2021-05-29 11:46:03 +02:00
function setStartState ( ) {
enableSendBtn ( ) ;
enableButtons ( [ button _actmem , button _actwi ] ) ;
2022-01-22 01:02:56 +01:00
disableButtons ( [ button _actback , button _actfwd , button _actretry ] ) ;
2021-08-23 19:22:50 +02:00
hide ( [ wi _menu ] ) ;
2022-01-22 01:02:56 +01:00
show ( [ game _text , button _actmem , button _actwi , button _actback , button _actfwd , button _actretry ] ) ;
2021-05-29 11:46:03 +02:00
hideMessage ( ) ;
hideWaitAnimation ( ) ;
button _actmem . html ( "Memory" ) ;
button _actwi . html ( "W Info" ) ;
hideAidgPopup ( ) ;
hideSaveAsPopup ( ) ;
hideLoadPopup ( ) ;
hideNewStoryPopup ( ) ;
hidegenseqs ( ) ;
}
function parsegenseqs ( seqs ) {
seqselcontents . html ( "" ) ;
var i ;
for ( i = 0 ; i < seqs . length ; i ++ ) {
2022-02-03 14:08:43 +01:00
//setup selection data
text _data = "<table><tr><td width=100%><div class=\"seqselitem\" id=\"seqsel" + i + "\" n=\"" + i + "\">" + seqs [ i ] [ 0 ] + "</div></td><td width=10>"
//Now do the icon (pin/redo)
if ( seqs [ i ] [ 1 ] == "redo" ) {
text _data = text _data + "<span style=\"color: white\" class=\"oi oi-loop-circular\" title=\"Redo\" aria-hidden=\"true\" id=\"seqselpin" + i + "\" n=\"" + i + "\"></span>"
} else if ( seqs [ i ] [ 1 ] == "pinned" ) {
text _data = text _data + "<span style=\"color: white\" class=\"oi oi-pin\" title=\"Pin\" aria-hidden=\"true\" id=\"seqselpin" + i + "\" n=\"" + i + "\"></span>"
2022-01-21 21:30:37 +01:00
} else {
2022-02-03 14:08:43 +01:00
text _data = text _data + "<span style=\"color: grey\" class=\"oi oi-pin\" title=\"Pin\" aria-hidden=\"true\" id=\"seqselpin" + i + "\" n=\"" + i + "\"></span>"
2022-01-21 21:30:37 +01:00
}
2022-02-03 14:08:43 +01:00
text _data = text _data + "</td></tr></table>"
seqselcontents . append ( text _data ) ;
//setup on-click actions
2021-05-29 11:46:03 +02:00
$ ( "#seqsel" + i ) . on ( "click" , function ( ) {
socket . send ( { 'cmd' : 'seqsel' , 'data' : $ ( this ) . attr ( "n" ) } ) ;
} ) ;
2022-02-03 14:08:43 +01:00
//onclick for pin only
if ( seqs [ i ] [ 1 ] != "redo" ) {
$ ( "#seqselpin" + i ) . on ( "click" , function ( ) {
socket . send ( { 'cmd' : 'seqpin' , 'data' : $ ( this ) . attr ( "n" ) } ) ;
if ( $ ( this ) . attr ( "style" ) == "color: grey" ) {
console . log ( $ ( this ) . attr ( "style" ) ) ;
$ ( this ) . css ( { "color" : "white" } ) ;
console . log ( $ ( this ) . attr ( "style" ) ) ;
} else {
console . log ( $ ( this ) . attr ( "style" ) ) ;
$ ( this ) . css ( { "color" : "grey" } ) ;
console . log ( $ ( this ) . attr ( "style" ) ) ;
}
} ) ;
}
2021-05-29 11:46:03 +02:00
}
$ ( '#seqselmenu' ) . slideDown ( "slow" ) ;
}
function hidegenseqs ( ) {
$ ( '#seqselmenu' ) . slideUp ( "slow" , function ( ) {
seqselcontents . html ( "" ) ;
} ) ;
2021-08-26 21:15:42 +02:00
scrollToBottom ( ) ;
2021-05-29 11:46:03 +02:00
}
2021-08-19 13:18:01 +02:00
function setmodevisibility ( state ) {
if ( state ) { // Enabling
show ( [ button _mode ] ) ;
$ ( "#inputrow" ) . addClass ( "show_mode" ) ;
} else { // Disabling
hide ( [ button _mode ] ) ;
$ ( "#inputrow" ) . removeClass ( "show_mode" ) ;
}
}
2021-12-27 04:21:58 +01:00
function setchatnamevisibility ( state ) {
if ( state ) { // Enabling
show ( [ chat _name ] ) ;
} else { // Disabling
hide ( [ chat _name ] ) ;
}
}
2021-08-19 13:18:01 +02:00
function setadventure ( state ) {
adventure = state ;
2021-08-26 07:06:57 +02:00
if ( state ) {
game _text . addClass ( "adventure" ) ;
} else {
game _text . removeClass ( "adventure" ) ;
}
2021-08-19 13:18:01 +02:00
if ( ! memorymode ) {
setmodevisibility ( state ) ;
}
}
2021-12-26 01:51:32 +01:00
function setchatmode ( state ) {
chatmode = state ;
2021-12-27 04:21:58 +01:00
setchatnamevisibility ( state ) ;
2021-12-26 01:51:32 +01:00
}
2021-08-23 08:34:27 +02:00
function autofocus ( event ) {
if ( connected ) {
event . target . focus ( ) ;
} else {
event . preventDefault ( ) ;
}
}
2021-12-05 05:59:28 +01:00
function sortableOnStart ( event , ui ) {
}
function sortableOnStop ( event , ui ) {
if ( ui . item . hasClass ( "wilistitem" ) ) {
// When a WI entry is dragged and dropped, tell the server which WI
// entry was dropped and which WI entry comes immediately after the
// dropped position so that the server can internally move around
// the WI entries
2022-01-01 03:22:51 +01:00
var next _sibling = ui . item . next ( ".wilistitem" ) . attr ( "uid" ) ;
2021-12-05 05:59:28 +01:00
if ( next _sibling === undefined ) {
2022-01-01 03:22:51 +01:00
next _sibling = ui . item . next ( ) . next ( ) . attr ( "uid" ) ;
2021-12-05 05:59:28 +01:00
}
next _sibling = parseInt ( next _sibling ) ;
2021-12-05 08:50:42 +01:00
if ( Number . isNaN ( next _sibling ) ) {
$ ( this ) . sortable ( "cancel" ) ;
return ;
}
2022-01-01 03:22:51 +01:00
socket . send ( { 'cmd' : 'wimoveitem' , 'destination' : next _sibling , 'data' : parseInt ( ui . item . attr ( "uid" ) ) } ) ;
2021-12-05 05:59:28 +01:00
} else {
// Do the same thing for WI folders
var next _sibling = ui . item . next ( ".wisortable-container" ) . attr ( "folder-uid" ) ;
if ( next _sibling === undefined ) {
next _sibling = null ;
} else {
next _sibling = parseInt ( next _sibling ) ;
}
2021-12-05 08:50:42 +01:00
if ( Number . isNaN ( next _sibling ) ) {
$ ( this ) . sortable ( "cancel" ) ;
return ;
}
2021-12-05 05:59:28 +01:00
socket . send ( { 'cmd' : 'wimovefolder' , 'destination' : next _sibling , 'data' : parseInt ( ui . item . attr ( "folder-uid" ) ) } ) ;
}
}
2021-10-12 06:09:02 +02:00
function chunkOnTextInput ( event ) {
// The enter key does not behave correctly in almost all non-Firefox
// browsers, so we (attempt to) shim all enter keystrokes here to behave the
// same as in Firefox
if ( event . originalEvent . data . slice ( - 1 ) === '\n' ) {
event . preventDefault ( ) ;
var s = getSelection ( ) ; // WARNING: Do not use rangy.getSelection() instead of getSelection()
var r = s . getRangeAt ( 0 ) ;
// We prefer using document.execCommand here because it works best on
// mobile devices, but the other method is also here as
// a fallback
if ( document . queryCommandSupported && document . execCommand && document . queryCommandSupported ( 'insertHTML' ) ) {
2021-10-13 18:43:45 +02:00
document . execCommand ( 'insertHTML' , false , event . originalEvent . data . slice ( 0 , - 1 ) . replace ( /&/g , '&' ) . replace ( /</g , '<' ) . replace ( />/g , '>' ) . replace ( /"/g , '"' ) . replace ( /'/g , ''' ) . replace ( /(?=\r|\n)\r?\n?/g , '<br/>' ) + '<br id="_EDITOR_LINEBREAK_"/><span id="_EDITOR_SENTINEL_">|</span>' ) ;
2021-10-12 06:09:02 +02:00
var t = $ ( '#_EDITOR_SENTINEL_' ) . contents ( ) . filter ( function ( ) { return this . nodeType === 3 ; } ) [ 0 ] ;
} else {
var t = document . createTextNode ( '|' ) ;
2021-10-13 06:42:03 +02:00
var b = document . createElement ( 'br' ) ;
b . id = "_EDITOR_LINEBREAK_" ;
r . insertNode ( b ) ;
2021-10-12 06:09:02 +02:00
r . collapse ( false ) ;
r . insertNode ( t ) ;
}
r . selectNodeContents ( t ) ;
s . removeAllRanges ( ) ;
s . addRange ( r ) ;
if ( document . queryCommandSupported && document . execCommand && document . queryCommandSupported ( 'forwardDelete' ) ) {
r . collapse ( true ) ;
document . execCommand ( 'forwardDelete' ) ;
} else {
// deleteContents() sometimes breaks using the left
// arrow key in some browsers so we prefer the
// document.execCommand method
r . deleteContents ( ) ;
}
2021-10-13 06:42:03 +02:00
2022-07-01 19:12:57 +02:00
// In Chrome and Safari the added <br/> will go outside of the chunks if we press
2021-10-13 06:42:03 +02:00
// enter at the end of the story in the editor, so this is here
// to put the <br/> back in the right place
var br = $ ( "#_EDITOR_LINEBREAK_" ) [ 0 ] ;
if ( br . parentNode === game _text [ 0 ] ) {
2022-06-30 18:03:39 +02:00
var parent = br . previousSibling ;
2021-10-13 06:42:03 +02:00
if ( br . previousSibling . nodeType !== 1 ) {
2022-06-30 18:03:39 +02:00
parent = br . previousSibling . previousSibling ;
2021-10-13 06:42:03 +02:00
br . previousSibling . previousSibling . appendChild ( br . previousSibling ) ;
}
2022-06-30 18:03:39 +02:00
if ( parent . lastChild . tagName === "BR" ) {
2022-07-01 19:12:57 +02:00
parent . lastChild . remove ( ) ; // Chrome and Safari also insert an extra <br/> in this case for some reason so we need to remove it
if ( using _webkit _patch ) {
// Safari on iOS has a bug where it selects all text in the last chunk of the story when this happens so we collapse the selection to the end of the chunk in that case
setTimeout ( function ( ) {
var s = getSelection ( ) ;
var r = s . getRangeAt ( 0 ) ;
r . selectNodeContents ( parent ) ;
r . collapse ( false ) ;
s . removeAllRanges ( ) ;
s . addRange ( r ) ;
} , 2 ) ;
}
2022-06-30 18:03:39 +02:00
}
2021-10-13 06:42:03 +02:00
br . previousSibling . appendChild ( br ) ;
r . selectNodeContents ( br . parentNode ) ;
s . removeAllRanges ( ) ;
s . addRange ( r ) ;
r . collapse ( false ) ;
}
br . id = "" ;
if ( game _text [ 0 ] . lastChild . tagName === "BR" ) {
br . parentNode . appendChild ( game _text [ 0 ] . lastChild ) ;
}
2021-10-12 06:09:02 +02:00
return ;
}
}
2021-11-18 19:18:18 +01:00
// This gets run when one or more chunks are edited. The event occurs before
// the actual edits are made by the browser, so we are free to check which
// nodes are selected or stop the event from occurring.
function chunkOnBeforeInput ( event ) {
// Register all selected chunks as having been modified
applyChunkDeltas ( getSelectedNodes ( ) ) ;
// Fix editing across chunks and paragraphs in Firefox 93.0 and higher
if ( event . originalEvent . inputType === "deleteContentBackward" && document . queryCommandSupported && document . execCommand && document . queryCommandSupported ( 'delete' ) ) {
event . preventDefault ( ) ;
document . execCommand ( 'delete' ) ;
}
var s = rangy . getSelection ( ) ;
2022-04-10 09:04:31 +02:00
2021-11-18 19:18:18 +01:00
if ( buildChunkSetFromNodeArray ( getSelectedNodes ( ) ) . size === 0 ) {
var s = rangy . getSelection ( ) ;
var r = s . getRangeAt ( 0 ) ;
if ( document . queryCommandSupported && document . execCommand && document . queryCommandSupported ( 'insertHTML' ) ) {
document . execCommand ( 'insertHTML' , false , '<span id="_EDITOR_SENTINEL_">|</span>' ) ;
} else {
var t = document . createTextNode ( '|' ) ;
var b = document . createElement ( 'span' ) ;
b . id = "_EDITOR_SENTINEL_" ;
b . insertNode ( t ) ;
r . insertNode ( b ) ;
}
var sentinel = document . getElementById ( "_EDITOR_SENTINEL_" ) ;
if ( sentinel . nextSibling && sentinel . nextSibling . tagName === "CHUNK" ) {
r . selectNodeContents ( sentinel . nextSibling ) ;
r . collapse ( true ) ;
} else if ( sentinel . previousSibling && sentinel . previousSibling . tagName === "CHUNK" ) {
r . selectNodeContents ( sentinel . previousSibling ) ;
r . collapse ( false ) ;
}
s . removeAllRanges ( ) ;
s . addRange ( r ) ;
sentinel . parentNode . removeChild ( sentinel ) ;
}
}
2021-08-23 08:34:27 +02:00
function chunkOnKeyDown ( event ) {
2021-08-24 01:18:09 +02:00
// Make escape commit the changes (Originally we had Enter here to but its not required and nicer for users if we let them type freely
// You can add the following after 27 if you want it back to committing on enter : || (!event.shiftKey && event.keyCode == 13)
if ( event . keyCode == 27 ) {
2021-09-28 04:56:12 +02:00
override _focusout = true ;
game _text . blur ( ) ;
2021-08-23 08:34:27 +02:00
event . preventDefault ( ) ;
return ;
}
// Don't allow any edits if not connected to server
if ( ! connected ) {
event . preventDefault ( ) ;
return ;
}
// Prevent CTRL+B, CTRL+I and CTRL+U when editing chunks
if ( event . ctrlKey || event . metaKey ) { // metaKey is macOS's command key
switch ( event . keyCode ) {
case 66 :
case 98 :
case 73 :
case 105 :
case 85 :
case 117 :
event . preventDefault ( ) ;
return ;
}
}
}
2021-09-19 17:41:37 +02:00
function downloadStory ( format ) {
2021-09-19 17:59:31 +02:00
var filename _without _extension = storyname !== null ? storyname : "untitled" ;
2021-09-19 17:41:37 +02:00
var anchor = document . createElement ( 'a' ) ;
var actionlist = $ ( "chunk" ) ;
var actionlist _compiled = [ ] ;
for ( var i = 0 ; i < actionlist . length ; i ++ ) {
actionlist _compiled . push ( actionlist [ i ] . innerText . replace ( /\u00a0/g , " " ) ) ;
}
2021-10-13 06:42:03 +02:00
var last = actionlist _compiled [ actionlist _compiled . length - 1 ] ;
2021-12-05 05:59:28 +01:00
if ( last && last . slice ( - 1 ) === '\n' ) {
2021-10-13 06:42:03 +02:00
actionlist _compiled [ actionlist _compiled . length - 1 ] = last . slice ( 0 , - 1 ) ;
}
2021-09-19 17:41:37 +02:00
if ( format == "plaintext" ) {
2021-12-30 22:51:50 +01:00
var objectURL = URL . createObjectURL ( new Blob ( actionlist _compiled , { type : "text/plain; charset=UTF-8" } ) ) ;
2021-09-19 17:41:37 +02:00
anchor . setAttribute ( 'href' , objectURL ) ;
anchor . setAttribute ( 'download' , filename _without _extension + ".txt" ) ;
anchor . click ( ) ;
URL . revokeObjectURL ( objectURL ) ;
return ;
}
var wilist = $ ( ".wilistitem" ) ;
var wilist _compiled = [ ] ;
2021-12-05 05:59:28 +01:00
for ( var i = 0 ; i < wilist . length ; i ++ ) {
if ( wilist [ i ] . classList . contains ( "wilistitem-uninitialized" ) ) {
continue ;
}
2021-09-19 17:41:37 +02:00
var selective = wilist [ i ] . classList . contains ( "wilistitem-selective" ) ;
2021-12-05 17:39:59 +01:00
var folder = $ ( "#wilistitem" + i ) . parent ( ) . attr ( "folder-uid" ) ;
if ( folder === undefined ) {
folder = null ;
} else {
folder = parseInt ( folder ) ;
}
2021-09-19 17:41:37 +02:00
wilist _compiled . push ( {
key : selective ? $ ( "#wikeyprimary" + i ) . val ( ) : $ ( "#wikey" + i ) . val ( ) ,
keysecondary : $ ( "#wikeysecondary" + i ) . val ( ) ,
content : $ ( "#wientry" + i ) . val ( ) ,
2021-12-05 05:59:28 +01:00
comment : $ ( "#wicomment" + i ) . val ( ) ,
2021-12-05 17:39:59 +01:00
folder : folder ,
2021-09-19 17:41:37 +02:00
selective : selective ,
constant : wilist [ i ] . classList . contains ( "wilistitem-constant" ) ,
} ) ;
}
var prompt = actionlist _compiled . shift ( ) ;
if ( prompt === undefined ) {
prompt = "" ;
}
var objectURL = URL . createObjectURL ( new Blob ( [ JSON . stringify ( {
gamestarted : gamestarted ,
prompt : prompt ,
memory : memorytext ,
authorsnote : $ ( "#anoteinput" ) . val ( ) ,
2021-12-30 05:43:36 +01:00
anotetemplate : $ ( "#anotetemplate" ) . val ( ) ,
2021-09-19 17:41:37 +02:00
actions : actionlist _compiled ,
worldinfo : wilist _compiled ,
2021-12-05 05:59:28 +01:00
wifolders _d : wifolders _d ,
wifolders _l : wifolders _l ,
2021-12-30 22:51:50 +01:00
} , null , 3 ) ] , { type : "application/json; charset=UTF-8" } ) ) ;
2021-09-19 17:41:37 +02:00
anchor . setAttribute ( 'href' , objectURL ) ;
anchor . setAttribute ( 'download' , filename _without _extension + ".json" ) ;
anchor . click ( ) ;
URL . revokeObjectURL ( objectURL ) ;
}
2021-09-27 19:11:15 +02:00
function buildChunkSetFromNodeArray ( nodes ) {
var set = new Set ( ) ;
for ( var i = 0 ; i < nodes . length ; i ++ ) {
node = nodes [ i ] ;
while ( node !== null && node . tagName !== "CHUNK" ) {
node = node . parentNode ;
}
if ( node === null ) {
continue ;
}
set . add ( node . getAttribute ( "n" ) ) ;
}
return set ;
}
function getSelectedNodes ( ) {
var range = rangy . getSelection ( ) . getRangeAt ( 0 ) ; // rangy is not a typo
var nodes = range . getNodes ( [ 1 , 3 ] ) ;
nodes . push ( range . startContainer ) ;
nodes . push ( range . endContainer ) ;
return nodes
}
function applyChunkDeltas ( nodes ) {
var chunks = Array . from ( buildChunkSetFromNodeArray ( nodes ) ) ;
for ( var i = 0 ; i < chunks . length ; i ++ ) {
modified _chunks . add ( chunks [ i ] ) ;
2022-07-01 19:45:57 +02:00
all _modified _chunks . add ( chunks [ i ] ) ;
2021-09-27 19:11:15 +02:00
}
setTimeout ( function ( ) {
var chunks = Array . from ( modified _chunks ) ;
var selected _chunks = buildChunkSetFromNodeArray ( getSelectedNodes ( ) ) ;
for ( var i = 0 ; i < chunks . length ; i ++ ) {
var chunk = document . getElementById ( "n" + chunks [ i ] ) ;
2022-06-24 18:44:00 +02:00
if ( chunk && formatChunkInnerText ( chunk ) . trim ( ) . length != 0 && chunks [ i ] != '0' ) {
2021-09-27 19:11:15 +02:00
if ( ! selected _chunks . has ( chunks [ i ] ) ) {
modified _chunks . delete ( chunks [ i ] ) ;
2021-10-13 06:42:03 +02:00
socket . send ( { 'cmd' : 'inlineedit' , 'chunk' : chunks [ i ] , 'data' : formatChunkInnerText ( chunk ) } ) ;
2022-06-30 18:23:06 +02:00
if ( submit _throttle !== null ) {
submit _throttle ( 0 , _dosubmit ) ;
}
2021-09-27 19:11:15 +02:00
}
empty _chunks . delete ( chunks [ i ] ) ;
} else {
if ( ! selected _chunks . has ( chunks [ i ] ) ) {
modified _chunks . delete ( chunks [ i ] ) ;
2022-06-24 18:44:00 +02:00
socket . send ( { 'cmd' : 'inlineedit' , 'chunk' : chunks [ i ] , 'data' : formatChunkInnerText ( chunk ) } ) ;
2022-06-30 18:23:06 +02:00
if ( submit _throttle !== null ) {
submit _throttle ( 0 , _dosubmit ) ;
}
2021-09-27 19:11:15 +02:00
}
empty _chunks . add ( chunks [ i ] ) ;
}
}
} , 2 ) ;
}
function syncAllModifiedChunks ( including _selected _chunks = false ) {
var chunks = Array . from ( modified _chunks ) ;
var selected _chunks = buildChunkSetFromNodeArray ( getSelectedNodes ( ) ) ;
for ( var i = 0 ; i < chunks . length ; i ++ ) {
if ( including _selected _chunks || ! selected _chunks . has ( chunks [ i ] ) ) {
modified _chunks . delete ( chunks [ i ] ) ;
var chunk = document . getElementById ( "n" + chunks [ i ] ) ;
2021-10-13 06:42:03 +02:00
var data = chunk ? formatChunkInnerText ( document . getElementById ( "n" + chunks [ i ] ) ) : "" ;
2021-09-27 19:11:15 +02:00
if ( data . length == 0 ) {
empty _chunks . add ( chunks [ i ] ) ;
} else {
empty _chunks . delete ( chunks [ i ] ) ;
}
socket . send ( { 'cmd' : 'inlineedit' , 'chunk' : chunks [ i ] , 'data' : data } ) ;
2022-06-30 18:23:06 +02:00
if ( submit _throttle !== null ) {
submit _throttle ( 0 , _dosubmit ) ;
}
2021-09-27 19:11:15 +02:00
}
}
}
2021-09-28 04:21:14 +02:00
function restorePrompt ( ) {
2021-12-23 21:43:32 +01:00
if ( $ ( "#n0" ) . length && formatChunkInnerText ( $ ( "#n0" ) [ 0 ] ) . length === 0 ) {
$ ( "#n0" ) . remove ( ) ;
}
var shadow _text = $ ( "<b>" + game _text . html ( ) + "</b>" ) ;
var detected = false ;
var ref = null ;
try {
if ( shadow _text . length && shadow _text [ 0 ] . firstChild && ( shadow _text [ 0 ] . firstChild . nodeType === 3 || shadow _text [ 0 ] . firstChild . tagName === "BR" ) ) {
detected = true ;
ref = shadow _text ;
2022-01-04 20:41:31 +01:00
} else if ( game _text . length && game _text [ 0 ] . firstChild && ( game _text [ 0 ] . firstChild . nodeType === 3 || game _text [ 0 ] . firstChild . tagName === "BR" ) ) {
2021-12-23 21:43:32 +01:00
detected = true ;
ref = game _text ;
}
} catch ( e ) {
detected = false ;
}
if ( detected ) {
2021-09-28 04:21:14 +02:00
unbindGametext ( ) ;
2021-12-23 21:43:32 +01:00
var text = [ ] ;
while ( true ) {
if ( ref . length && ref [ 0 ] . firstChild && ref [ 0 ] . firstChild . nodeType === 3 ) {
text . push ( ref [ 0 ] . firstChild . textContent . replace ( /\u00a0/g , " " ) ) ;
} else if ( ref . length && ref [ 0 ] . firstChild && ref [ 0 ] . firstChild . tagName === "BR" ) {
text . push ( "\n" ) ;
} else {
break ;
}
ref [ 0 ] . removeChild ( ref [ 0 ] . firstChild ) ;
}
text = text . join ( "" ) . trim ( ) ;
if ( text . length ) {
saved _prompt = text ;
}
game _text [ 0 ] . innerHTML = "" ;
2021-09-28 04:21:14 +02:00
bindGametext ( ) ;
}
2021-12-23 21:43:32 +01:00
game _text . children ( ) . each ( function ( ) {
if ( this . tagName !== "CHUNK" ) {
this . parentNode . removeChild ( this ) ;
}
} ) ;
if ( ! detected ) {
game _text . children ( ) . each ( function ( ) {
if ( this . innerText . trim ( ) . length ) {
saved _prompt = this . innerText . trim ( ) ;
socket . send ( { 'cmd' : 'inlinedelete' , 'data' : this . getAttribute ( "n" ) } ) ;
2022-06-30 18:23:06 +02:00
if ( submit _throttle !== null ) {
submit _throttle ( 0 , _dosubmit ) ;
}
2021-12-23 21:43:32 +01:00
this . parentNode . removeChild ( this ) ;
return false ;
}
socket . send ( { 'cmd' : 'inlinedelete' , 'data' : this . getAttribute ( "n" ) } ) ;
2022-06-30 18:23:06 +02:00
if ( submit _throttle !== null ) {
submit _throttle ( 0 , _dosubmit ) ;
}
2021-12-23 21:43:32 +01:00
this . parentNode . removeChild ( this ) ;
} ) ;
2021-09-28 04:21:14 +02:00
}
var prompt _chunk = document . createElement ( "chunk" ) ;
prompt _chunk . setAttribute ( "n" , "0" ) ;
prompt _chunk . setAttribute ( "id" , "n0" ) ;
prompt _chunk . setAttribute ( "tabindex" , "-1" ) ;
prompt _chunk . innerText = saved _prompt ;
unbindGametext ( ) ;
game _text [ 0 ] . prepend ( prompt _chunk ) ;
bindGametext ( ) ;
modified _chunks . delete ( '0' ) ;
empty _chunks . delete ( '0' ) ;
socket . send ( { 'cmd' : 'inlineedit' , 'chunk' : '0' , 'data' : saved _prompt } ) ;
2022-06-30 18:23:06 +02:00
if ( submit _throttle !== null ) {
submit _throttle ( 0 , _dosubmit ) ;
}
2021-09-28 04:21:14 +02:00
}
2021-09-27 19:11:15 +02:00
function deleteEmptyChunks ( ) {
var chunks = Array . from ( empty _chunks ) ;
for ( var i = 0 ; i < chunks . length ; i ++ ) {
empty _chunks . delete ( chunks [ i ] ) ;
2021-09-28 04:21:14 +02:00
if ( chunks [ i ] === "0" ) {
// Don't delete the prompt
restorePrompt ( ) ;
} else {
socket . send ( { 'cmd' : 'inlinedelete' , 'data' : chunks [ i ] } ) ;
2022-06-30 18:23:06 +02:00
if ( submit _throttle !== null ) {
submit _throttle ( 0 , _dosubmit ) ;
}
2021-09-28 04:21:14 +02:00
}
2021-09-27 19:11:15 +02:00
}
2021-09-28 04:21:14 +02:00
if ( modified _chunks . has ( '0' ) ) {
modified _chunks . delete ( chunks [ i ] ) ;
2021-10-13 06:42:03 +02:00
socket . send ( { 'cmd' : 'inlineedit' , 'chunk' : chunks [ i ] , 'data' : formatChunkInnerText ( document . getElementById ( "n0" ) ) } ) ;
2022-06-30 18:23:06 +02:00
if ( submit _throttle !== null ) {
submit _throttle ( 0 , _dosubmit ) ;
}
2021-09-28 04:21:14 +02:00
}
2022-06-30 17:08:22 +02:00
if ( gamestarted ) {
saved _prompt = formatChunkInnerText ( $ ( "#n0" ) [ 0 ] ) ;
2021-09-28 04:21:14 +02:00
}
2021-09-27 19:11:15 +02:00
}
function highlightEditingChunks ( ) {
var chunks = $ ( 'chunk.editing' ) . toArray ( ) ;
var selected _chunks = buildChunkSetFromNodeArray ( getSelectedNodes ( ) ) ;
for ( var i = 0 ; i < chunks . length ; i ++ ) {
var chunk = chunks [ i ] ;
if ( ! selected _chunks . has ( chunks [ i ] . getAttribute ( "n" ) ) ) {
unbindGametext ( ) ;
$ ( chunk ) . removeClass ( 'editing' ) ;
bindGametext ( ) ;
}
}
chunks = Array . from ( selected _chunks ) ;
for ( var i = 0 ; i < chunks . length ; i ++ ) {
var chunk = $ ( "#n" + chunks [ i ] ) ;
unbindGametext ( ) ;
chunk . addClass ( 'editing' ) ;
bindGametext ( ) ;
}
}
2022-06-24 18:44:00 +02:00
function cleanupChunkWhitespace ( ) {
2022-06-30 17:08:22 +02:00
unbindGametext ( ) ;
2022-07-01 19:45:57 +02:00
var chunks = Array . from ( all _modified _chunks ) ;
for ( var i = 0 ; i < chunks . length ; i ++ ) {
var original _chunk = document . getElementById ( "n" + chunks [ i ] ) ;
if ( original _chunk === null || original _chunk . innerText . trim ( ) . length === 0 ) {
all _modified _chunks . delete ( chunks [ i ] ) ;
modified _chunks . delete ( chunks [ i ] ) ;
empty _chunks . add ( chunks [ i ] ) ;
}
}
2022-06-24 18:44:00 +02:00
// Merge empty chunks with the next chunk
var chunks = Array . from ( empty _chunks ) ;
chunks . sort ( function ( e ) { parseInt ( e ) } ) ;
for ( var i = 0 ; i < chunks . length ; i ++ ) {
2022-06-30 17:08:22 +02:00
if ( chunks [ i ] == "0" ) {
continue ;
}
2022-06-24 18:44:00 +02:00
var original _chunk = document . getElementById ( "n" + chunks [ i ] ) ;
2022-07-01 19:45:57 +02:00
if ( original _chunk === null ) {
continue ;
}
2022-06-24 18:44:00 +02:00
var chunk = original _chunk . nextSibling ;
while ( chunk ) {
if ( chunk . tagName === "CHUNK" ) {
break ;
}
chunk = chunk . nextSibling ;
}
if ( chunk ) {
chunk . innerText = original _chunk . innerText + chunk . innerText ;
2022-06-30 17:08:22 +02:00
if ( original _chunk . innerText . length != 0 && ! modified _chunks . has ( chunk . getAttribute ( "n" ) ) ) {
modified _chunks . add ( chunk . getAttribute ( "n" ) ) ;
}
2022-06-24 18:44:00 +02:00
}
original _chunk . innerText = "" ;
}
// Move whitespace at the end of non-empty chunks into the beginning of the next non-empty chunk
2022-07-01 19:45:57 +02:00
var chunks = Array . from ( all _modified _chunks ) ;
2022-06-24 18:44:00 +02:00
chunks . sort ( function ( e ) { parseInt ( e ) } ) ;
for ( var i = 0 ; i < chunks . length ; i ++ ) {
var original _chunk = document . getElementById ( "n" + chunks [ i ] ) ;
var chunk = original _chunk . nextSibling ;
while ( chunk ) {
if ( chunk . tagName === "CHUNK" && ! empty _chunks . has ( chunk . getAttribute ( "n" ) ) ) {
break ;
}
chunk = chunk . nextSibling ;
}
var ln = original _chunk . innerText . trimEnd ( ) . length ;
if ( chunk ) {
chunk . innerText = original _chunk . innerText . substring ( ln ) + chunk . innerText ;
2022-06-30 17:08:22 +02:00
if ( ln != original _chunk . innerText . length && ! modified _chunks . has ( chunk . getAttribute ( "n" ) ) ) {
modified _chunks . add ( chunk . getAttribute ( "n" ) ) ;
}
2022-06-24 18:44:00 +02:00
}
original _chunk . innerText = original _chunk . innerText . substring ( 0 , ln ) ;
}
2022-06-30 17:08:22 +02:00
bindGametext ( ) ;
2022-06-24 18:44:00 +02:00
}
2022-03-01 01:00:26 +01:00
// This gets run every time the text in a chunk is edited
// or a chunk is deleted
function chunkOnDOMMutate ( mutations , observer ) {
if ( ! gametext _bound || ! allowedit ) {
return ;
}
var nodes = [ ] ;
for ( var i = 0 ; i < mutations . length ; i ++ ) {
var mutation = mutations [ i ] ;
nodes = nodes . concat ( Array . from ( mutation . addedNodes ) , Array . from ( mutation . removedNodes ) ) ;
nodes . push ( mutation . target ) ;
}
applyChunkDeltas ( nodes ) ;
}
2021-09-27 19:11:15 +02:00
// This gets run every time you try to paste text into the editor
function chunkOnPaste ( event ) {
2021-11-18 19:18:18 +01:00
// Register the chunk we're pasting in as having been modified
applyChunkDeltas ( getSelectedNodes ( ) ) ;
2021-09-27 19:11:15 +02:00
// If possible, intercept paste events into the editor in order to always
// paste as plaintext
2021-10-13 18:51:31 +02:00
if ( event . originalEvent . clipboardData && document . queryCommandSupported && document . execCommand && document . queryCommandSupported ( 'insertHTML' ) ) {
2021-09-27 19:11:15 +02:00
event . preventDefault ( ) ;
2021-10-13 18:43:45 +02:00
document . execCommand ( 'insertHTML' , false , event . originalEvent . clipboardData . getData ( 'text/plain' ) . replace ( /&/g , '&' ) . replace ( /</g , '<' ) . replace ( />/g , '>' ) . replace ( /"/g , '"' ) . replace ( /'/g , ''' ) . replace ( /(?=\r|\n)\r?\n?/g , '<br/>' ) ) ;
2021-10-13 18:41:43 +02:00
} else if ( event . originalEvent . clipboardData ) {
event . preventDefault ( ) ;
var s = getSelection ( ) ; // WARNING: Do not use rangy.getSelection() instead of getSelection()
var r = s . getRangeAt ( 0 ) ;
r . deleteContents ( ) ;
2021-10-13 18:43:45 +02:00
var nodes = Array . from ( $ ( '<span>' + event . originalEvent . clipboardData . getData ( 'text/plain' ) . replace ( /&/g , '&' ) . replace ( /</g , '<' ) . replace ( />/g , '>' ) . replace ( /"/g , '"' ) . replace ( /'/g , ''' ) . replace ( /(?=\r|\n)\r?\n?/g , '<br/>' ) + '</span>' ) [ 0 ] . childNodes ) ;
2021-10-13 18:41:43 +02:00
for ( var i = 0 ; i < nodes . length ; i ++ ) {
r . insertNode ( nodes [ i ] ) ;
r . collapse ( false ) ;
}
}
2021-09-27 19:11:15 +02:00
}
2021-09-27 21:57:07 +02:00
// This gets run every time the caret moves in the editor
2021-09-30 23:52:35 +02:00
function _chunkOnSelectionChange ( event , do _blur _focus ) {
2021-09-28 06:48:37 +02:00
if ( ! gametext _bound || ! allowedit || override _focusout ) {
2021-09-28 04:56:12 +02:00
override _focusout = false ;
2021-09-27 19:11:15 +02:00
return ;
}
setTimeout ( function ( ) {
syncAllModifiedChunks ( ) ;
setTimeout ( function ( ) {
highlightEditingChunks ( ) ;
2021-09-27 23:44:22 +02:00
// Attempt to prevent Chromium-based browsers on Android from
// scrolling away from the current selection
2021-09-30 23:52:35 +02:00
if ( do _blur _focus && ! using _webkit _patch ) {
2021-09-30 20:13:54 +02:00
setTimeout ( function ( ) {
game _text . blur ( ) ;
game _text . focus ( ) ;
} , 144 ) ;
}
2021-09-27 19:11:15 +02:00
} , 2 ) ;
} , 2 ) ;
}
2021-09-30 23:52:35 +02:00
function chunkOnSelectionChange ( event ) {
return _chunkOnSelectionChange ( event , true ) ;
}
function chunkOnKeyDownSelectionChange ( event ) {
return _chunkOnSelectionChange ( event , false ) ;
}
2021-09-27 21:57:07 +02:00
// This gets run when you defocus the editor by clicking
2021-09-27 19:11:15 +02:00
// outside of the editor or by pressing escape or tab
function chunkOnFocusOut ( event ) {
2022-06-26 19:40:58 +02:00
if ( event !== "override" && ( ! gametext _bound || ! allowedit || event . target !== game _text [ 0 ] ) ) {
2021-09-27 19:11:15 +02:00
return ;
}
setTimeout ( function ( ) {
2021-09-27 22:04:42 +02:00
if ( document . activeElement === game _text [ 0 ] || game _text [ 0 ] . contains ( document . activeElement ) ) {
2021-09-27 19:11:15 +02:00
return ;
}
2022-06-24 18:44:00 +02:00
cleanupChunkWhitespace ( ) ;
2022-07-01 19:45:57 +02:00
all _modified _chunks = new Set ( ) ;
2021-09-27 19:11:15 +02:00
syncAllModifiedChunks ( true ) ;
setTimeout ( function ( ) {
2021-09-27 22:04:42 +02:00
var blurred = game _text [ 0 ] !== document . activeElement ;
2021-09-27 19:11:15 +02:00
if ( blurred ) {
deleteEmptyChunks ( ) ;
}
setTimeout ( function ( ) {
$ ( "chunk" ) . removeClass ( 'editing' ) ;
} , 2 ) ;
} , 2 ) ;
} , 2 ) ;
}
function bindGametext ( ) {
2022-03-01 01:00:26 +01:00
mutation _observer . observe ( game _text [ 0 ] , { characterData : true , childList : true , subtree : true } ) ;
2021-09-27 19:11:15 +02:00
gametext _bound = true ;
}
function unbindGametext ( ) {
2022-03-01 01:00:26 +01:00
mutation _observer . disconnect ( ) ;
2021-09-27 19:11:15 +02:00
gametext _bound = false ;
}
2022-07-28 05:13:08 +02:00
function endStream ( ) {
// Clear stream, the real text is about to be displayed.
ignore _stream = true ;
if ( stream _preview ) {
stream _preview . remove ( ) ;
stream _preview = null ;
}
}
2022-03-07 17:27:23 +01:00
function update _gpu _layers ( ) {
var gpu _layers
gpu _layers = 0 ;
for ( let i = 0 ; i < $ ( "#gpu_count" ) [ 0 ] . value ; i ++ ) {
gpu _layers += parseInt ( $ ( "#gpu_layers" + i ) [ 0 ] . value ) ;
2022-06-14 17:53:47 +02:00
$ ( "#gpu_layers_box_" + i ) [ 0 ] . value = $ ( "#gpu_layers" + i ) [ 0 ] . value ;
2022-03-07 17:27:23 +01:00
}
2022-06-20 04:53:30 +02:00
if ( $ ( "#disk_layers" ) . length > 0 ) {
gpu _layers += parseInt ( $ ( "#disk_layers" ) [ 0 ] . value ) ;
$ ( "#disk_layers_box" ) [ 0 ] . value = $ ( "#disk_layers" ) [ 0 ] . value ;
}
2022-03-07 17:27:23 +01:00
if ( gpu _layers > parseInt ( document . getElementById ( "gpu_layers_max" ) . innerHTML ) ) {
disableButtons ( [ load _model _accept ] ) ;
2022-06-09 14:42:35 +02:00
$ ( "#gpu_layers_current" ) . html ( "<span style='color: red'>" + gpu _layers + "/" + document . getElementById ( "gpu_layers_max" ) . innerHTML + "</span>" ) ;
2022-03-07 17:27:23 +01:00
} else {
enableButtons ( [ load _model _accept ] ) ;
2022-06-14 17:53:47 +02:00
$ ( "#gpu_layers_current" ) . html ( gpu _layers + "/" + document . getElementById ( "gpu_layers_max" ) . innerHTML ) ;
2022-03-07 17:27:23 +01:00
}
}
2022-03-12 20:21:11 +01:00
function RemoveAllButFirstOption ( selectElement ) {
var i , L = selectElement . options . length - 1 ;
for ( i = L ; i >= 1 ; i -- ) {
selectElement . remove ( i ) ;
}
}
2021-05-03 00:48:47 +02:00
//=================================================================//
// READY/RUNTIME
//=================================================================//
$ ( document ) . ready ( function ( ) {
2021-05-05 09:04:06 +02:00
// Bind UI references
2021-05-22 11:28:40 +02:00
connect _status = $ ( '#connectstatus' ) ;
2022-03-07 01:51:35 +01:00
button _loadmodel = $ ( '#btn_loadmodel' ) ;
2022-03-08 00:44:37 +01:00
button _showmodel = $ ( '#btn_showmodel' ) ;
2021-05-22 11:28:40 +02:00
button _newgame = $ ( '#btn_newgame' ) ;
2021-08-19 12:54:44 +02:00
button _rndgame = $ ( '#btn_rndgame' ) ;
2021-05-22 11:28:40 +02:00
button _save = $ ( '#btn_save' ) ;
button _saveas = $ ( '#btn_saveas' ) ;
button _savetofile = $ ( '#btn_savetofile' ) ;
2021-09-01 19:32:11 +02:00
button _download = $ ( '#btn_download' ) ;
2021-09-01 19:46:37 +02:00
button _downloadtxt = $ ( '#btn_downloadtxt' ) ;
2021-05-22 11:28:40 +02:00
button _load = $ ( '#btn_load' ) ;
button _loadfrfile = $ ( '#btn_loadfromfile' ) ;
button _import = $ ( "#btn_import" ) ;
2021-05-29 11:46:03 +02:00
button _importwi = $ ( "#btn_importwi" ) ;
2021-05-22 11:28:40 +02:00
button _impaidg = $ ( "#btn_impaidg" ) ;
button _settings = $ ( '#btn_settings' ) ;
button _format = $ ( '#btn_format' ) ;
2021-10-22 20:18:10 +02:00
button _softprompt = $ ( "#btn_softprompt" ) ;
2021-12-13 07:03:26 +01:00
button _userscripts = $ ( "#btn_userscripts" ) ;
2022-06-14 02:18:09 +02:00
button _samplers = $ ( "#btn_samplers" ) ;
2021-08-19 13:18:01 +02:00
button _mode = $ ( '#btnmode' )
button _mode _label = $ ( '#btnmode_label' )
2021-05-22 11:28:40 +02:00
button _send = $ ( '#btnsend' ) ;
button _actmem = $ ( '#btn_actmem' ) ;
button _actback = $ ( '#btn_actundo' ) ;
2022-01-21 21:30:37 +01:00
button _actfwd = $ ( '#btn_actredo' ) ;
2021-05-22 11:28:40 +02:00
button _actretry = $ ( '#btn_actretry' ) ;
button _actwi = $ ( '#btn_actwi' ) ;
game _text = $ ( '#gametext' ) ;
input _text = $ ( '#input_text' ) ;
message _text = $ ( '#messagefield' ) ;
2021-12-27 04:21:58 +01:00
chat _name = $ ( '#chatname' ) ;
2021-05-22 11:28:40 +02:00
settings _menu = $ ( "#settingsmenu" ) ;
format _menu = $ ( '#formatmenu' ) ;
anote _menu = $ ( '#anoterowcontainer' ) ;
2022-01-24 18:54:44 +01:00
debug _area = $ ( '#debugcontainer' ) ;
2021-05-22 11:28:40 +02:00
wi _menu = $ ( '#wimenu' ) ;
anote _input = $ ( '#anoteinput' ) ;
anote _labelcur = $ ( '#anotecur' ) ;
anote _slider = $ ( '#anotedepth' ) ;
popup = $ ( "#popupcontainer" ) ;
popup _title = $ ( "#popuptitletext" ) ;
popup _content = $ ( "#popupcontent" ) ;
popup _accept = $ ( "#btn_popupaccept" ) ;
popup _close = $ ( "#btn_popupclose" ) ;
aidgpopup = $ ( "#aidgpopupcontainer" ) ;
aidgpromptnum = $ ( "#aidgpromptnum" ) ;
aidg _accept = $ ( "#btn_aidgpopupaccept" ) ;
aidg _close = $ ( "#btn_aidgpopupclose" ) ;
saveaspopup = $ ( "#saveascontainer" ) ;
saveasinput = $ ( "#savename" ) ;
2022-01-22 01:02:56 +01:00
savepins = $ ( "#savepins" ) ;
2021-08-19 12:54:44 +02:00
topic = $ ( "#topic" ) ;
2021-05-22 11:28:40 +02:00
saveas _accept = $ ( "#btn_saveasaccept" ) ;
saveas _close = $ ( "#btn_saveasclose" ) ;
loadpopup = $ ( "#loadcontainer" ) ;
2022-03-07 01:51:35 +01:00
loadmodelpopup = $ ( "#loadmodelcontainer" ) ;
2021-05-22 11:28:40 +02:00
loadcontent = $ ( "#loadlistcontent" ) ;
2022-03-07 01:51:35 +01:00
loadmodelcontent = $ ( "#loadmodellistcontent" ) ;
2021-05-22 11:28:40 +02:00
load _accept = $ ( "#btn_loadaccept" ) ;
load _close = $ ( "#btn_loadclose" ) ;
2022-03-07 01:51:35 +01:00
load _model _accept = $ ( "#btn_loadmodelaccept" ) ;
load _model _close = $ ( "#btn_loadmodelclose" ) ;
2021-10-22 20:18:10 +02:00
sppopup = $ ( "#spcontainer" ) ;
spcontent = $ ( "#splistcontent" ) ;
sp _accept = $ ( "#btn_spaccept" ) ;
sp _close = $ ( "#btn_spclose" ) ;
2021-12-13 07:03:26 +01:00
uspopup = $ ( "#uscontainer" ) ;
usunloaded = $ ( "#uslistunloaded" ) ;
usloaded = $ ( "#uslistloaded" ) ;
us _accept = $ ( "#btn_usaccept" ) ;
us _close = $ ( "#btn_usclose" ) ;
2022-06-14 02:18:09 +02:00
samplerspopup = $ ( "#samplerscontainer" ) ;
samplerslist = $ ( "#samplerslist" ) ;
samplers _accept = $ ( "#btn_samplersaccept" ) ;
samplers _close = $ ( "#btn_samplersclose" ) ;
2021-05-22 11:28:40 +02:00
nspopup = $ ( "#newgamecontainer" ) ;
ns _accept = $ ( "#btn_nsaccept" ) ;
ns _close = $ ( "#btn_nsclose" ) ;
2021-08-19 12:54:44 +02:00
rspopup = $ ( "#rndgamecontainer" ) ;
rs _accept = $ ( "#btn_rsaccept" ) ;
rs _close = $ ( "#btn_rsclose" ) ;
2021-05-29 11:46:03 +02:00
seqselmenu = $ ( "#seqselmenu" ) ;
seqselcontents = $ ( "#seqselcontents" ) ;
2021-09-30 20:13:54 +02:00
2021-08-25 00:32:48 +02:00
// Connect to SocketIO server
2022-01-17 18:11:06 +01:00
socket = io . connect ( window . document . origin , { transports : [ 'polling' , 'websocket' ] , closeOnBeforeunload : false } ) ;
2022-06-30 15:44:04 +02:00
socket . on ( 'load_popup' , function ( data ) { load _popup ( data ) ; } ) ;
socket . on ( 'popup_items' , function ( data ) { popup _items ( data ) ; } ) ;
socket . on ( 'popup_breadcrumbs' , function ( data ) { popup _breadcrumbs ( data ) ; } ) ;
socket . on ( 'popup_edit_file' , function ( data ) { popup _edit _file ( data ) ; } ) ;
2022-06-30 21:57:27 +02:00
socket . on ( 'error_popup' , function ( data ) { error _popup ( data ) ; } ) ;
2022-01-17 18:11:06 +01:00
2021-05-03 00:48:47 +02:00
socket . on ( 'from_server' , function ( msg ) {
2022-03-07 18:33:35 +01:00
//console.log(msg);
2021-08-25 00:32:48 +02:00
if ( msg . cmd == "connected" ) {
2021-05-03 00:48:47 +02:00
// Connected to Server Actions
2021-09-01 00:22:30 +02:00
sman _allow _delete = msg . hasOwnProperty ( "smandelete" ) && msg . smandelete ;
sman _allow _rename = msg . hasOwnProperty ( "smanrename" ) && msg . smanrename ;
2021-08-23 08:34:27 +02:00
connected = true ;
2022-01-18 23:20:45 +01:00
if ( msg . hasOwnProperty ( "modelname" ) ) {
modelname = msg . modelname ;
}
refreshTitle ( ) ;
2022-06-14 02:18:09 +02:00
connect _status . html ( "<b>Connected to KoboldAI!</b>" ) ;
2021-05-07 20:32:10 +02:00
connect _status . removeClass ( "color_orange" ) ;
connect _status . addClass ( "color_green" ) ;
2021-05-13 07:26:42 +02:00
// Reset Menus
2022-06-10 20:47:52 +02:00
reset _menus ( ) ;
2021-08-23 08:34:27 +02:00
// Set up "Allow Editing"
2021-09-27 19:11:15 +02:00
$ ( 'body' ) . on ( 'input' , autofocus ) ;
$ ( '#allowediting' ) . prop ( 'checked' , allowedit ) . prop ( 'disabled' , false ) . change ( ) . off ( 'change' ) . on ( 'change' , function ( ) {
2021-08-23 08:34:27 +02:00
if ( allowtoggle ) {
2021-09-28 06:48:37 +02:00
allowedit = gamestarted && $ ( this ) . prop ( 'checked' ) ;
2021-09-27 22:04:42 +02:00
game _text . attr ( 'contenteditable' , allowedit ) ;
2021-08-23 08:34:27 +02:00
}
} ) ;
2021-10-01 01:00:15 +02:00
// A simple feature detection test to determine whether the user interface
// is using WebKit (Safari browser's rendering engine) because WebKit
// requires special treatment to work correctly with the KoboldAI editor
2021-10-01 04:58:54 +02:00
( function ( ) {
var active _element = document . activeElement ;
var c = document . createElement ( "chunk" ) ;
var t = document . createTextNode ( "KoboldAI" ) ;
c . appendChild ( t ) ;
game _text [ 0 ] . appendChild ( c ) ;
var r = rangy . createRange ( ) ;
r . setStart ( t , 6 ) ;
r . collapse ( true ) ;
var s = rangy . getSelection ( ) ;
s . removeAllRanges ( ) ;
s . addRange ( r ) ;
game _text . blur ( ) ;
game _text . focus ( ) ;
using _webkit _patch = rangy . getSelection ( ) . focusOffset !== 6 ;
c . removeChild ( t ) ;
game _text [ 0 ] . removeChild ( c ) ;
document . activeElement . blur ( ) ;
active _element . focus ( ) ;
} ) ( ) ;
2021-12-30 07:44:35 +01:00
$ ( "body" ) . addClass ( "connected" ) ;
2022-07-28 05:13:08 +02:00
} else if ( msg . cmd == "streamtoken" ) {
// Sometimes the stream_token messages will come in too late, after
// we have recieved the full text. This leads to some stray tokens
// appearing after the output. To combat this, we only allow tokens
// to be displayed after requesting and before recieving text.
if ( ignore _stream ) return ;
if ( ! $ ( "#setoutputstreaming" ) [ 0 ] . checked ) return ;
if ( ! stream _preview ) {
stream _preview = document . createElement ( "span" ) ;
game _text . append ( stream _preview ) ;
}
stream _preview . innerText += msg . data . join ( "" ) ;
scrollToBottom ( ) ;
2021-05-03 00:48:47 +02:00
} else if ( msg . cmd == "updatescreen" ) {
2021-09-01 20:01:04 +02:00
var _gamestarted = gamestarted ;
2021-08-19 13:18:01 +02:00
gamestarted = msg . gamestarted ;
if ( _gamestarted != gamestarted ) {
action _mode = 0 ;
changemode ( ) ;
}
2021-09-27 19:11:15 +02:00
unbindGametext ( ) ;
2021-09-27 23:55:54 +02:00
allowedit = gamestarted && $ ( "#allowediting" ) . prop ( 'checked' ) ;
game _text . attr ( 'contenteditable' , allowedit ) ;
2022-07-01 19:45:57 +02:00
all _modified _chunks = new Set ( ) ;
2021-09-27 19:11:15 +02:00
modified _chunks = new Set ( ) ;
empty _chunks = new Set ( ) ;
2021-05-03 00:48:47 +02:00
game _text . html ( msg . data ) ;
2021-10-13 06:42:03 +02:00
if ( game _text [ 0 ] . lastChild !== null && game _text [ 0 ] . lastChild . tagName === "CHUNK" ) {
game _text [ 0 ] . lastChild . appendChild ( document . createElement ( "br" ) ) ;
}
2021-09-27 19:11:15 +02:00
bindGametext ( ) ;
2021-09-28 04:21:14 +02:00
if ( gamestarted ) {
2021-10-13 06:42:03 +02:00
saved _prompt = formatChunkInnerText ( $ ( "#n0" ) [ 0 ] ) ;
2021-09-28 04:21:14 +02:00
}
2021-05-04 15:56:48 +02:00
// Scroll to bottom of text
2021-08-23 08:34:27 +02:00
if ( newly _loaded ) {
2021-08-26 21:15:42 +02:00
scrollToBottom ( ) ;
2021-08-23 08:34:27 +02:00
}
newly _loaded = false ;
2021-08-24 01:19:36 +02:00
} else if ( msg . cmd == "scrolldown" ) {
2021-08-26 21:15:42 +02:00
scrollToBottom ( ) ;
2021-06-15 06:59:08 +02:00
} else if ( msg . cmd == "updatechunk" ) {
2021-08-26 01:22:35 +02:00
hideMessage ( ) ;
2022-06-11 02:51:22 +02:00
if ( typeof submit _start !== 'undefined' ) {
$ ( "#runtime" ) [ 0 ] . innerHTML = ` Generation time: ${ Math . round ( ( Date . now ( ) - submit _start ) / 1000 ) } sec ` ;
delete submit _start ;
}
2021-10-13 06:42:03 +02:00
var index = msg . data . index ;
var html = msg . data . html ;
var existingChunk = game _text . children ( '#n' + index ) ;
var newChunk = $ ( html ) ;
2021-09-27 19:11:15 +02:00
unbindGametext ( ) ;
2021-06-15 06:59:08 +02:00
if ( existingChunk . length > 0 ) {
// Update existing chunk
2021-10-13 06:42:03 +02:00
if ( existingChunk [ 0 ] . nextSibling === null || existingChunk [ 0 ] . nextSibling . nodeType !== 1 || existingChunk [ 0 ] . nextSibling . tagName !== "CHUNK" ) {
newChunk [ 0 ] . appendChild ( document . createElement ( "br" ) ) ;
}
2021-06-15 06:59:08 +02:00
existingChunk . before ( newChunk ) ;
existingChunk . remove ( ) ;
2021-09-27 19:11:15 +02:00
} else if ( ! empty _chunks . has ( index . toString ( ) ) ) {
2021-06-15 06:59:08 +02:00
// Append at the end
2021-10-13 06:42:03 +02:00
unbindGametext ( ) ;
var lc = game _text [ 0 ] . lastChild ;
if ( lc . tagName === "CHUNK" && lc . lastChild !== null && lc . lastChild . tagName === "BR" ) {
lc . removeChild ( lc . lastChild ) ;
}
newChunk [ 0 ] . appendChild ( document . createElement ( "br" ) ) ;
2021-06-15 06:59:08 +02:00
game _text . append ( newChunk ) ;
2021-10-13 06:42:03 +02:00
bindGametext ( ) ;
2021-06-15 06:59:08 +02:00
}
2021-09-27 19:11:15 +02:00
bindGametext ( ) ;
2021-08-25 01:02:52 +02:00
hide ( [ $ ( '#curtain' ) ] ) ;
2021-06-15 06:59:08 +02:00
} else if ( msg . cmd == "removechunk" ) {
2021-08-26 01:22:35 +02:00
hideMessage ( ) ;
2021-10-13 06:42:03 +02:00
var index = msg . data ;
var element = game _text . children ( '#n' + index ) ;
if ( element . length ) {
unbindGametext ( ) ;
if ( ( element [ 0 ] . nextSibling === null || element [ 0 ] . nextSibling . nodeType !== 1 || element [ 0 ] . nextSibling . tagName !== "CHUNK" ) && element [ 0 ] . previousSibling !== null && element [ 0 ] . previousSibling . tagName === "CHUNK" ) {
element [ 0 ] . previousSibling . appendChild ( document . createElement ( "br" ) ) ;
}
element . remove ( ) ; // Remove the chunk
bindGametext ( ) ;
}
2021-08-25 01:02:52 +02:00
hide ( [ $ ( '#curtain' ) ] ) ;
2021-05-03 00:48:47 +02:00
} else if ( msg . cmd == "setgamestate" ) {
// Enable or Disable buttons
if ( msg . data == "ready" ) {
2022-07-28 05:13:08 +02:00
endStream ( ) ;
2021-05-03 00:48:47 +02:00
enableSendBtn ( ) ;
2022-01-22 01:02:56 +01:00
enableButtons ( [ button _actmem , button _actwi , button _actback , button _actfwd , button _actretry ] ) ;
2021-05-03 00:48:47 +02:00
hideWaitAnimation ( ) ;
2022-01-10 22:36:15 +01:00
gamestate = "ready" ;
2022-06-10 02:03:34 +02:00
favicon . stop _swap ( ) ;
2021-05-03 00:48:47 +02:00
} else if ( msg . data == "wait" ) {
2022-01-10 22:36:15 +01:00
gamestate = "wait" ;
2021-05-03 00:48:47 +02:00
disableSendBtn ( ) ;
2022-01-22 01:02:56 +01:00
disableButtons ( [ button _actmem , button _actwi , button _actback , button _actfwd , button _actretry ] ) ;
2021-05-03 00:48:47 +02:00
showWaitAnimation ( ) ;
2022-06-10 02:03:34 +02:00
favicon . start _swap ( ) ;
2021-05-03 00:48:47 +02:00
} else if ( msg . data == "start" ) {
2021-05-29 11:46:03 +02:00
setStartState ( ) ;
2022-01-10 22:36:15 +01:00
gamestate = "ready" ;
2022-06-10 02:03:34 +02:00
favicon . stop _swap ( ) ;
2021-05-03 00:48:47 +02:00
}
2021-10-22 20:18:10 +02:00
} else if ( msg . cmd == "allowsp" ) {
allowsp = ! ! msg . data ;
if ( allowsp ) {
button _softprompt . removeClass ( "hidden" ) ;
} else {
button _softprompt . addClass ( "hidden" ) ;
}
2021-09-19 17:41:37 +02:00
} else if ( msg . cmd == "setstoryname" ) {
storyname = msg . data ;
2022-01-18 23:20:45 +01:00
refreshTitle ( ) ;
2021-05-03 00:48:47 +02:00
} else if ( msg . cmd == "editmode" ) {
// Enable or Disable edit mode
if ( msg . data == "true" ) {
enterEditMode ( ) ;
} else {
exitEditMode ( ) ;
}
} else if ( msg . cmd == "setinputtext" ) {
2021-08-23 08:34:27 +02:00
// Set input box text for memory mode
2021-09-19 17:41:37 +02:00
if ( memorymode ) {
memorytext = msg . data ;
input _text . val ( msg . data ) ;
}
} else if ( msg . cmd == "setmemory" ) {
memorytext = msg . data ;
2021-08-23 08:34:27 +02:00
if ( memorymode ) {
input _text . val ( msg . data ) ;
}
2021-05-03 00:48:47 +02:00
} else if ( msg . cmd == "memmode" ) {
// Enable or Disable memory edit mode
if ( msg . data == "true" ) {
enterMemoryMode ( ) ;
} else {
exitMemoryMode ( ) ;
}
} else if ( msg . cmd == "errmsg" ) {
// Send error message
2022-01-17 03:09:10 +01:00
errMessage ( msg . data , "error" ) ;
} else if ( msg . cmd == "warnmsg" ) {
// Send warning message
errMessage ( msg . data , "warn" ) ;
} else if ( msg . cmd == "hidemsg" ) {
hideMessage ( ) ;
2021-05-03 00:48:47 +02:00
} else if ( msg . cmd == "texteffect" ) {
// Apply color highlight to line of text
newTextHighlight ( $ ( "#n" + msg . data ) )
2021-05-04 15:56:48 +02:00
} else if ( msg . cmd == "updatetemp" ) {
// Send current temp value to input
2022-04-26 21:27:28 +02:00
$ ( "#settempcur" ) . val ( msg . data ) ;
2022-05-29 01:14:26 +02:00
$ ( "#settemp" ) . val ( parseFloat ( msg . data ) ) . trigger ( "change" ) ;
2021-05-04 15:56:48 +02:00
} else if ( msg . cmd == "updatetopp" ) {
2021-05-07 20:32:10 +02:00
// Send current top p value to input
2022-04-26 21:27:28 +02:00
$ ( "#settoppcur" ) . val ( msg . data ) ;
2022-05-29 01:14:26 +02:00
$ ( "#settopp" ) . val ( parseFloat ( msg . data ) ) . trigger ( "change" ) ;
2021-08-19 14:47:57 +02:00
} else if ( msg . cmd == "updatetopk" ) {
// Send current top k value to input
2022-04-26 21:27:28 +02:00
$ ( "#settopkcur" ) . val ( msg . data ) ;
2022-05-29 01:14:26 +02:00
$ ( "#settopk" ) . val ( parseFloat ( msg . data ) ) . trigger ( "change" ) ;
2021-08-19 14:47:57 +02:00
} else if ( msg . cmd == "updatetfs" ) {
// Send current tfs value to input
2022-04-26 21:27:28 +02:00
$ ( "#settfscur" ) . val ( msg . data ) ;
2022-05-29 01:14:26 +02:00
$ ( "#settfs" ) . val ( parseFloat ( msg . data ) ) . trigger ( "change" ) ;
2022-03-27 22:25:50 +02:00
} else if ( msg . cmd == "updatetypical" ) {
// Send current typical value to input
2022-04-26 21:27:28 +02:00
$ ( "#settypicalcur" ) . val ( msg . data ) ;
2022-05-29 01:14:26 +02:00
$ ( "#settypical" ) . val ( parseFloat ( msg . data ) ) . trigger ( "change" ) ;
2022-06-11 04:28:20 +02:00
} else if ( msg . cmd == "updatetopa" ) {
// Send current top a value to input
$ ( "#settopacur" ) . val ( msg . data ) ;
$ ( "#settopa" ) . val ( parseFloat ( msg . data ) ) . trigger ( "change" ) ;
2021-05-04 15:56:48 +02:00
} else if ( msg . cmd == "updatereppen" ) {
2021-05-07 20:32:10 +02:00
// Send current rep pen value to input
2022-04-26 21:27:28 +02:00
$ ( "#setreppencur" ) . val ( msg . data ) ;
2022-05-29 01:14:26 +02:00
$ ( "#setreppen" ) . val ( parseFloat ( msg . data ) ) . trigger ( "change" ) ;
2022-01-24 21:30:38 +01:00
} else if ( msg . cmd == "updatereppenslope" ) {
// Send current rep pen value to input
2022-04-26 21:27:28 +02:00
$ ( "#setreppenslopecur" ) . val ( msg . data ) ;
2022-05-29 01:14:26 +02:00
$ ( "#setreppenslope" ) . val ( parseFloat ( msg . data ) ) . trigger ( "change" ) ;
2022-01-24 21:30:38 +01:00
} else if ( msg . cmd == "updatereppenrange" ) {
// Send current rep pen value to input
2022-04-26 21:27:28 +02:00
$ ( "#setreppenrangecur" ) . val ( msg . data ) ;
2022-05-29 01:14:26 +02:00
$ ( "#setreppenrange" ) . val ( parseFloat ( msg . data ) ) . trigger ( "change" ) ;
2021-05-04 15:56:48 +02:00
} else if ( msg . cmd == "updateoutlen" ) {
2021-05-07 20:32:10 +02:00
// Send current output amt value to input
2022-04-26 21:27:28 +02:00
$ ( "#setoutputcur" ) . val ( msg . data ) ;
2022-05-29 01:14:26 +02:00
$ ( "#setoutput" ) . val ( parseInt ( msg . data ) ) . trigger ( "change" ) ;
2021-05-07 20:32:10 +02:00
} else if ( msg . cmd == "updatetknmax" ) {
// Send current max tokens value to input
2022-04-26 21:27:28 +02:00
$ ( "#settknmaxcur" ) . val ( msg . data ) ;
2022-05-29 01:14:26 +02:00
$ ( "#settknmax" ) . val ( parseInt ( msg . data ) ) . trigger ( "change" ) ;
2021-05-07 20:32:10 +02:00
} else if ( msg . cmd == "updateikgen" ) {
// Send current max tokens value to input
2022-04-26 21:27:28 +02:00
$ ( "#setikgencur" ) . val ( msg . data ) ;
2022-05-29 01:14:26 +02:00
$ ( "#setikgen" ) . val ( parseInt ( msg . data ) ) . trigger ( "change" ) ;
2021-05-04 15:56:48 +02:00
} else if ( msg . cmd == "setlabeltemp" ) {
// Update setting label with value from server
2022-04-26 21:27:28 +02:00
$ ( "#settempcur" ) . val ( msg . data ) ;
2021-05-04 15:56:48 +02:00
} else if ( msg . cmd == "setlabeltopp" ) {
// Update setting label with value from server
2022-04-26 21:27:28 +02:00
$ ( "#settoppcur" ) . val ( msg . data ) ;
2021-08-19 14:47:57 +02:00
} else if ( msg . cmd == "setlabeltopk" ) {
// Update setting label with value from server
2022-04-26 21:27:28 +02:00
$ ( "#settopkcur" ) . val ( msg . data ) ;
2021-08-19 14:47:57 +02:00
} else if ( msg . cmd == "setlabeltfs" ) {
// Update setting label with value from server
2022-04-26 21:27:28 +02:00
$ ( "#settfscur" ) . val ( msg . data ) ;
2022-03-27 22:25:50 +02:00
} else if ( msg . cmd == "setlabeltypical" ) {
// Update setting label with value from server
2022-04-26 21:27:28 +02:00
$ ( "#settypicalcur" ) . val ( msg . data ) ;
2022-06-11 04:28:20 +02:00
} else if ( msg . cmd == "setlabeltypical" ) {
// Update setting label with value from server
$ ( "#settopa" ) . val ( msg . data ) ;
2021-05-04 15:56:48 +02:00
} else if ( msg . cmd == "setlabelreppen" ) {
// Update setting label with value from server
2022-04-26 21:27:28 +02:00
$ ( "#setreppencur" ) . val ( msg . data ) ;
2022-01-24 21:30:38 +01:00
} else if ( msg . cmd == "setlabelreppenslope" ) {
// Update setting label with value from server
2022-04-26 21:27:28 +02:00
$ ( "#setreppenslopecur" ) . val ( msg . data ) ;
2022-01-24 21:30:38 +01:00
} else if ( msg . cmd == "setlabelreppenrange" ) {
// Update setting label with value from server
2022-04-26 21:27:28 +02:00
$ ( "#setreppenrangecur" ) . val ( msg . data ) ;
2021-05-04 15:56:48 +02:00
} else if ( msg . cmd == "setlabeloutput" ) {
// Update setting label with value from server
2022-04-26 21:27:28 +02:00
$ ( "#setoutputcur" ) . val ( msg . data ) ;
2021-05-07 20:32:10 +02:00
} else if ( msg . cmd == "setlabeltknmax" ) {
// Update setting label with value from server
2022-04-26 21:27:28 +02:00
$ ( "#settknmaxcur" ) . val ( msg . data ) ;
2021-05-07 20:32:10 +02:00
} else if ( msg . cmd == "setlabelikgen" ) {
// Update setting label with value from server
2022-04-26 21:27:28 +02:00
$ ( "#setikgencur" ) . val ( msg . data ) ;
2021-05-07 20:32:10 +02:00
} else if ( msg . cmd == "updateanotedepth" ) {
2021-05-05 09:04:06 +02:00
// Send current Author's Note depth value to input
anote _slider . val ( parseInt ( msg . data ) ) ;
anote _labelcur . html ( msg . data ) ;
} else if ( msg . cmd == "setlabelanotedepth" ) {
// Update setting label with value from server
anote _labelcur . html ( msg . data ) ;
} else if ( msg . cmd == "getanote" ) {
// Request contents of Author's Note field
var txt = anote _input . val ( ) ;
2021-12-30 05:43:36 +01:00
socket . send ( { 'cmd' : 'anote' , 'template' : $ ( "#anotetemplate" ) . val ( ) , 'data' : txt } ) ;
2021-05-05 09:04:06 +02:00
} else if ( msg . cmd == "setanote" ) {
// Set contents of Author's Note field
anote _input . val ( msg . data ) ;
2021-12-30 05:43:36 +01:00
} else if ( msg . cmd == "setanotetemplate" ) {
// Set contents of Author's Note Template field
$ ( "#anotetemplate" ) . val ( msg . data ) ;
2022-06-10 20:47:52 +02:00
} else if ( msg . cmd == "reset_menus" ) {
reset _menus ( ) ;
2021-05-07 20:32:10 +02:00
} else if ( msg . cmd == "addsetting" ) {
// Add setting controls
addSetting ( msg . data ) ;
2021-05-11 01:17:10 +02:00
} else if ( msg . cmd == "addformat" ) {
// Add setting controls
addFormat ( msg . data ) ;
} else if ( msg . cmd == "updatefrmttriminc" ) {
// Update toggle state
2021-05-29 11:46:03 +02:00
$ ( "#frmttriminc" ) . prop ( 'checked' , msg . data ) . change ( ) ;
2021-05-11 01:17:10 +02:00
} else if ( msg . cmd == "updatefrmtrmblln" ) {
// Update toggle state
2021-05-29 11:46:03 +02:00
$ ( "#frmtrmblln" ) . prop ( 'checked' , msg . data ) . change ( ) ;
2021-05-11 01:17:10 +02:00
} else if ( msg . cmd == "updatefrmtrmspch" ) {
// Update toggle state
2021-05-29 11:46:03 +02:00
$ ( "#frmtrmspch" ) . prop ( 'checked' , msg . data ) . change ( ) ;
2021-05-11 01:17:10 +02:00
} else if ( msg . cmd == "updatefrmtadsnsp" ) {
// Update toggle state
2021-05-29 11:46:03 +02:00
$ ( "#frmtadsnsp" ) . prop ( 'checked' , msg . data ) . change ( ) ;
2021-10-23 17:30:48 +02:00
} else if ( msg . cmd == "updatesingleline" ) {
// Update toggle state
$ ( "#singleline" ) . prop ( 'checked' , msg . data ) . change ( ) ;
2022-07-28 05:13:08 +02:00
} else if ( msg . cmd == "updateoutputstreaming" ) {
// Update toggle state
$ ( "#setoutputstreaming" ) . prop ( 'checked' , msg . data ) . change ( ) ;
2021-05-11 01:17:10 +02:00
} else if ( msg . cmd == "allowtoggle" ) {
// Allow toggle change states to propagate
allowtoggle = msg . data ;
2021-12-23 05:33:27 +01:00
} else if ( msg . cmd == "usstatitems" ) {
updateUSStatItems ( msg . data , msg . flash ) ;
} else if ( msg . cmd == "spstatitems" ) {
updateSPStatItems ( msg . data ) ;
2021-05-11 06:27:34 +02:00
} else if ( msg . cmd == "popupshow" ) {
// Show/Hide Popup
popupShow ( msg . data ) ;
2021-09-01 00:22:30 +02:00
} else if ( msg . cmd == "hidepopupdelete" ) {
// Hide the dialog box that asks you to confirm deletion of a story
$ ( "#loadcontainerdelete" ) . removeClass ( "flex" ) . addClass ( "hidden" ) ;
hide ( [ $ ( ".saveasoverwrite" ) , $ ( ".popuperror" ) ] ) ;
} else if ( msg . cmd == "hidepopuprename" ) {
// Hide the story renaming dialog box
$ ( "#loadcontainerrename" ) . removeClass ( "flex" ) . addClass ( "hidden" ) ;
hide ( [ $ ( ".saveasoverwrite" ) , $ ( ".popuperror" ) ] ) ;
2021-05-11 06:27:34 +02:00
} else if ( msg . cmd == "addimportline" ) {
// Add import popup entry
addImportLine ( msg . data ) ;
} else if ( msg . cmd == "clearpopup" ) {
// Clear previous contents of popup
popup _content . html ( "" ) ;
2021-05-13 07:26:42 +02:00
} else if ( msg . cmd == "wimode" ) {
// Enable or Disable WI edit mode
if ( msg . data == "true" ) {
enterWiMode ( ) ;
} else {
exitWiMode ( ) ;
}
2021-12-05 05:59:28 +01:00
} else if ( msg . cmd == "wiupdate" ) {
var selective = $ ( "#wilistitem" + msg . num ) [ 0 ] . classList . contains ( "wilistitem-selective" ) ;
if ( selective ) {
$ ( "#wikeyprimary" + msg . num ) . val ( msg . data . key ) ;
} else {
$ ( "#wikey" + msg . num ) . val ( msg . data . key ) ;
}
$ ( "#wikeysecondary" + msg . num ) . val ( msg . data . keysecondary ) ;
$ ( "#wientry" + msg . num ) . val ( msg . data . content ) ;
$ ( "#wicomment" + msg . num ) . val ( msg . data . comment ) ;
adjustWiCommentHeight ( $ ( "#wicomment" + msg . num ) [ 0 ] ) ;
} else if ( msg . cmd == "wifolderupdate" ) {
$ ( "#wifoldername" + msg . uid ) . val ( msg . data . name ) ;
adjustWiFolderNameHeight ( $ ( "#wifoldername" + msg . uid ) [ 0 ] ) ;
} else if ( msg . cmd == "wiexpand" ) {
expandWiLine ( msg . data ) ;
} else if ( msg . cmd == "wiexpandfolder" ) {
expandWiFolderLine ( msg . data ) ;
2021-12-22 19:12:35 +01:00
} else if ( msg . cmd == "wifoldercollapsecontent" ) {
collapseWiFolderContent ( msg . data ) ;
} else if ( msg . cmd == "wifolderexpandcontent" ) {
expandWiFolderContent ( msg . data ) ;
2021-12-05 05:59:28 +01:00
} else if ( msg . cmd == "wiselon" ) {
enableWiSelective ( msg . data ) ;
} else if ( msg . cmd == "wiseloff" ) {
disableWiSelective ( msg . data ) ;
} else if ( msg . cmd == "wiconstanton" ) {
enableWiConstant ( msg . data ) ;
} else if ( msg . cmd == "wiconstantoff" ) {
disableWiConstant ( msg . data ) ;
2021-05-13 07:26:42 +02:00
} else if ( msg . cmd == "addwiitem" ) {
// Add WI entry to WI Menu
addWiLine ( msg . data ) ;
2021-12-05 05:59:28 +01:00
} else if ( msg . cmd == "addwifolder" ) {
addWiFolder ( msg . uid , msg . data ) ;
} else if ( msg . cmd == "wistart" ) {
// Save scroll position for later so we can restore it later
wiscroll = $ ( "#gamescreen" ) . scrollTop ( ) ;
2021-05-13 07:26:42 +02:00
// Clear previous contents of WI list
wi _menu . html ( "" ) ;
2021-12-05 05:59:28 +01:00
// Save wifolders_d and wifolders_l
wifolders _d = msg . wifolders _d ;
wifolders _l = msg . wifolders _l ;
} else if ( msg . cmd == "wifinish" ) {
// Allow drag-and-drop rearranging of world info entries (via JQuery UI's "sortable widget")
$ ( "#gamescreen" ) . sortable ( {
items : "#wimenu .wisortable-body > :not(.wisortable-excluded):not(.wisortable-excluded-dynamic), #wimenu .wisortable-container[folder-uid]:not(.wisortable-excluded):not(.wisortable-excluded-dynamic)" ,
containment : "#wimenu" ,
connectWith : "#wimenu .wisortable-body" ,
handle : ".wihandle" ,
start : sortableOnStart ,
stop : sortableOnStop ,
2021-12-05 06:34:44 +01:00
placeholder : "wisortable-placeholder" ,
2021-12-05 08:50:42 +01:00
delay : 2 ,
2021-12-05 05:59:28 +01:00
cursor : "move" ,
tolerance : "pointer" ,
2021-12-05 06:34:44 +01:00
opacity : 0.21 ,
2021-12-05 05:59:28 +01:00
revert : 173 ,
scrollSensitivity : 64 ,
scrollSpeed : 10 ,
} ) ;
// Restore previously-saved scroll position
$ ( "#gamescreen" ) . scrollTop ( wiscroll ) ;
} else if ( msg . cmd == "requestwiitem" ) {
2021-05-13 07:26:42 +02:00
// Package WI contents and send back to server
returnWiList ( msg . data ) ;
2021-05-22 11:28:40 +02:00
} else if ( msg . cmd == "saveas" ) {
// Show Save As prompt
showSaveAsPopup ( ) ;
2022-01-18 23:20:45 +01:00
} else if ( msg . cmd == "gamesaved" ) {
setGameSaved ( msg . data ) ;
2021-05-22 11:28:40 +02:00
} else if ( msg . cmd == "hidesaveas" ) {
// Hide Save As prompt
hideSaveAsPopup ( ) ;
} else if ( msg . cmd == "buildload" ) {
// Send array of save files to load UI
buildLoadList ( msg . data ) ;
2021-10-22 20:18:10 +02:00
} else if ( msg . cmd == "buildsp" ) {
buildSPList ( msg . data ) ;
2021-12-13 07:03:26 +01:00
} else if ( msg . cmd == "buildus" ) {
buildUSList ( msg . data . unloaded , msg . data . loaded ) ;
2022-06-14 02:18:09 +02:00
} else if ( msg . cmd == "buildsamplers" ) {
buildSamplerList ( msg . data ) ;
2021-05-22 11:28:40 +02:00
} else if ( msg . cmd == "askforoverwrite" ) {
// Show overwrite warning
2021-09-01 00:22:30 +02:00
show ( [ $ ( ".saveasoverwrite" ) ] ) ;
} else if ( msg . cmd == "popuperror" ) {
// Show error in the current dialog box
$ ( ".popuperror" ) . text ( msg . data ) ;
show ( [ $ ( ".popuperror" ) ] ) ;
2021-05-29 11:46:03 +02:00
} else if ( msg . cmd == "genseqs" ) {
// Parse generator sequences to UI
parsegenseqs ( msg . data ) ;
} else if ( msg . cmd == "hidegenseqs" ) {
// Collapse genseqs menu
hidegenseqs ( ) ;
2021-12-27 04:21:58 +01:00
} else if ( msg . cmd == "setchatname" ) {
chat _name . val ( msg . data ) ;
2021-05-29 11:46:03 +02:00
} else if ( msg . cmd == "setlabelnumseq" ) {
// Update setting label with value from server
$ ( "#setnumseqcur" ) . html ( msg . data ) ;
} else if ( msg . cmd == "updatenumseq" ) {
// Send current max tokens value to input
$ ( "#setnumseqcur" ) . html ( msg . data ) ;
2022-05-29 01:14:26 +02:00
$ ( "#setnumseq" ) . val ( parseInt ( msg . data ) ) . trigger ( "change" ) ;
2021-05-29 11:46:03 +02:00
} else if ( msg . cmd == "setlabelwidepth" ) {
// Update setting label with value from server
$ ( "#setwidepthcur" ) . html ( msg . data ) ;
} else if ( msg . cmd == "updatewidepth" ) {
// Send current max tokens value to input
$ ( "#setwidepthcur" ) . html ( msg . data ) ;
2022-05-29 01:14:26 +02:00
$ ( "#setwidepth" ) . val ( parseInt ( msg . data ) ) . trigger ( "change" ) ;
2021-05-29 11:46:03 +02:00
} else if ( msg . cmd == "updateuseprompt" ) {
// Update toggle state
$ ( "#setuseprompt" ) . prop ( 'checked' , msg . data ) . change ( ) ;
2021-08-19 13:18:01 +02:00
} else if ( msg . cmd == "updateadventure" ) {
// Update toggle state
$ ( "#setadventure" ) . prop ( 'checked' , msg . data ) . change ( ) ;
// Update adventure state
setadventure ( msg . data ) ;
2021-12-26 01:51:32 +01:00
} else if ( msg . cmd == "updatechatmode" ) {
// Update toggle state
$ ( "#setchatmode" ) . prop ( 'checked' , msg . data ) . change ( ) ;
// Update chatmode state
setchatmode ( msg . data ) ;
2021-11-03 17:18:48 +01:00
} else if ( msg . cmd == "updatedynamicscan" ) {
// Update toggle state
$ ( "#setdynamicscan" ) . prop ( 'checked' , msg . data ) . change ( ) ;
2021-12-16 12:47:44 +01:00
} else if ( msg . cmd == "updatenopromptgen" ) {
// Update toggle state
$ ( "#setnopromptgen" ) . prop ( 'checked' , msg . data ) . change ( ) ;
2022-03-20 19:12:11 +01:00
} else if ( msg . cmd == "updateautosave" ) {
// Update toggle state
$ ( "#autosave" ) . prop ( 'checked' , msg . data ) . change ( ) ;
2021-12-30 05:15:59 +01:00
} else if ( msg . cmd == "updaterngpersist" ) {
// Update toggle state
$ ( "#setrngpersist" ) . prop ( 'checked' , msg . data ) . change ( ) ;
if ( ! $ ( "#setrngpersist" ) . prop ( "checked" ) ) {
$ ( "#rngmemory" ) . val ( "" ) ;
}
2022-01-16 05:31:07 +01:00
} else if ( msg . cmd == "updatenogenmod" ) {
// Update toggle state
$ ( "#setnogenmod" ) . prop ( 'checked' , msg . data ) . change ( ) ;
2022-06-28 19:21:05 +02:00
} else if ( msg . cmd == "updatefulldeterminism" ) {
// Update toggle state
$ ( "#setfulldeterminism" ) . prop ( 'checked' , msg . data ) . change ( ) ;
2021-08-20 00:37:59 +02:00
} else if ( msg . cmd == "runs_remotely" ) {
2021-11-05 00:33:17 +01:00
remote = true ;
hide ( [ button _savetofile , button _import , button _importwi ] ) ;
2022-01-24 18:54:44 +01:00
} else if ( msg . cmd == "debug_info" ) {
$ ( "#debuginfo" ) . val ( msg . data ) ;
} else if ( msg . cmd == "set_debug" ) {
if ( msg . data ) {
debug _area . removeClass ( "hidden" ) ;
} else {
debug _area . addClass ( "hidden" ) ;
}
2022-03-07 01:51:35 +01:00
} else if ( msg . cmd == 'show_model_menu' ) {
2022-06-09 14:42:35 +02:00
//console.log(msg)
2022-06-07 01:21:10 +02:00
$ ( "#use_gpu_div" ) . addClass ( "hidden" ) ;
$ ( "#modelkey" ) . addClass ( "hidden" ) ;
$ ( "#modellayers" ) . addClass ( "hidden" ) ;
$ ( "#oaimodel" ) . addClass ( "hidden" )
2022-06-15 01:39:11 +02:00
buildLoadModelList ( msg . data , msg . menu , msg . breadcrumbs , msg . showdelete ) ;
2022-06-07 01:21:10 +02:00
} else if ( msg . cmd == 'selected_model_info' ) {
enableButtons ( [ load _model _accept ] ) ;
$ ( "#oaimodel" ) . addClass ( "hidden" )
2022-06-07 19:47:10 +02:00
$ ( "#oaimodel" ) [ 0 ] . options [ 0 ] . selected = true ;
2022-06-07 01:21:10 +02:00
if ( msg . key ) {
$ ( "#modelkey" ) . removeClass ( "hidden" ) ;
$ ( "#modelkey" ) [ 0 ] . value = msg . key _value ;
} else {
$ ( "#modelkey" ) . addClass ( "hidden" ) ;
2022-06-07 19:47:10 +02:00
2022-06-07 01:21:10 +02:00
}
2022-06-07 14:22:10 +02:00
if ( msg . url ) {
$ ( "#modelurl" ) . removeClass ( "hidden" ) ;
} else {
$ ( "#modelurl" ) . addClass ( "hidden" ) ;
}
2022-06-07 01:21:10 +02:00
if ( msg . gpu ) {
2022-03-07 17:27:23 +01:00
$ ( "#use_gpu_div" ) . removeClass ( "hidden" ) ;
2022-03-07 01:51:35 +01:00
} else {
2022-03-07 17:27:23 +01:00
$ ( "#use_gpu_div" ) . addClass ( "hidden" ) ;
2022-03-07 01:51:35 +01:00
}
2022-06-07 01:21:10 +02:00
if ( msg . breakmodel ) {
var html ;
$ ( "#modellayers" ) . removeClass ( "hidden" ) ;
html = "" ;
2022-06-09 14:42:35 +02:00
for ( let i = 0 ; i < msg . gpu _names . length ; i ++ ) {
2022-06-14 17:53:47 +02:00
html += "GPU " + i + " " + msg . gpu _names [ i ] + ": " ;
html += '<input inputmode="numeric" id="gpu_layers_box_' + i + '" class="justifyright flex-push-right model_layers" value="' + msg . break _values [ i ] + '" ' ;
html += 'onblur=\'$("#gpu_layers' + i + '")[0].value=$("#gpu_layers_box_' + i + '")[0].value;update_gpu_layers();\'>' ;
html += "<input type='range' class='form-range airange' min='0' max='" + msg . layer _count + "' step='1' value='" + msg . break _values [ i ] + "' id='gpu_layers" + i + "' onchange='update_gpu_layers();'>" ;
2022-06-09 14:42:35 +02:00
}
2022-06-20 04:53:30 +02:00
html += "Disk cache: " ;
html += '<input inputmode="numeric" id="disk_layers_box" class="justifyright flex-push-right model_layers" value="' + msg . disk _break _value + '" ' ;
html += 'onblur=\'$("#disk_layers")[0].value=$("#disk_layers_box")[0].value;update_gpu_layers();\'>' ;
html += "<input type='range' class='form-range airange' min='0' max='" + msg . layer _count + "' step='1' value='" + msg . disk _break _value + "' id='disk_layers' onchange='update_gpu_layers();'>" ;
2022-06-07 01:21:10 +02:00
$ ( "#model_layer_bars" ) . html ( html ) ;
$ ( "#gpu_layers_max" ) . html ( msg . layer _count ) ;
$ ( "#gpu_count" ) [ 0 ] . value = msg . gpu _count ;
update _gpu _layers ( ) ;
2022-03-07 01:51:35 +01:00
} else {
2022-06-07 01:21:10 +02:00
$ ( "#modellayers" ) . addClass ( "hidden" ) ;
2022-03-07 17:27:23 +01:00
}
2022-06-07 01:21:10 +02:00
} else if ( msg . cmd == 'oai_engines' ) {
$ ( "#oaimodel" ) . removeClass ( "hidden" )
selected _item = 0 ;
2022-06-07 19:47:10 +02:00
length = $ ( "#oaimodel" ) [ 0 ] . options . length ;
for ( let i = 0 ; i < length ; i ++ ) {
$ ( "#oaimodel" ) [ 0 ] . options . remove ( 1 ) ;
}
2022-06-07 01:21:10 +02:00
msg . data . forEach ( function ( item , index ) {
var option = document . createElement ( "option" ) ;
option . value = item [ 0 ] ;
option . text = item [ 1 ] ;
if ( msg . online _model == item [ 0 ] ) {
selected _item = index + 1 ;
}
$ ( "#oaimodel" ) [ 0 ] . appendChild ( option ) ;
if ( selected _item != "" ) {
$ ( "#oaimodel" ) [ 0 ] . options [ selected _item ] . selected = true ;
}
} )
2022-03-07 20:20:25 +01:00
} else if ( msg . cmd == 'show_model_name' ) {
$ ( "#showmodelnamecontent" ) . html ( "<div class=\"flex\"><div class=\"loadlistpadding\"></div><div class=\"loadlistitem\">" + msg . data + "</div></div>" ) ;
$ ( "#showmodelnamecontainer" ) . removeClass ( "hidden" ) ;
2022-03-11 17:31:41 +01:00
} else if ( msg . cmd == 'hide_model_name' ) {
$ ( "#showmodelnamecontainer" ) . addClass ( "hidden" ) ;
2022-06-06 18:49:40 +02:00
//console.log("Closing window");
2022-03-11 17:31:41 +01:00
} else if ( msg . cmd == 'model_load_status' ) {
$ ( "#showmodelnamecontent" ) . html ( "<div class=\"flex\"><div class=\"loadlistpadding\"></div><div class=\"loadlistitem\" style='align: left'>" + msg . data + "</div></div>" ) ;
$ ( "#showmodelnamecontainer" ) . removeClass ( "hidden" ) ;
2022-06-06 18:49:40 +02:00
//console.log(msg.data);
2022-03-12 20:21:11 +01:00
} else if ( msg . cmd == 'oai_engines' ) {
RemoveAllButFirstOption ( $ ( "#oaimodel" ) [ 0 ] ) ;
for ( const engine of msg . data ) {
var opt = document . createElement ( 'option' ) ;
opt . value = engine [ 0 ] ;
opt . innerHTML = engine [ 1 ] ;
$ ( "#oaimodel" ) [ 0 ] . appendChild ( opt ) ;
}
2021-05-03 00:48:47 +02:00
}
2021-08-25 00:32:48 +02:00
} ) ;
2021-05-03 00:48:47 +02:00
socket . on ( 'disconnect' , function ( ) {
2021-08-23 08:34:27 +02:00
connected = false ;
2021-12-30 07:44:35 +01:00
$ ( "body" ) . removeClass ( "connected" ) ;
2021-05-07 20:32:10 +02:00
connect _status . html ( "<b>Lost connection...</b>" ) ;
connect _status . removeClass ( "color_green" ) ;
connect _status . addClass ( "color_orange" ) ;
2021-12-23 05:33:27 +01:00
updateUSStatItems ( [ ] , false ) ;
updateSPStatItems ( { } ) ;
2021-05-03 00:48:47 +02:00
} ) ;
2021-09-27 19:11:15 +02:00
2021-09-27 21:57:07 +02:00
// Register editing events
2021-10-12 06:09:02 +02:00
game _text . on ( 'textInput' ,
chunkOnTextInput
2021-11-18 19:18:18 +01:00
) . on ( 'beforeinput' ,
chunkOnBeforeInput
2021-10-12 06:09:02 +02:00
) . on ( 'keydown' ,
2021-09-27 19:11:15 +02:00
chunkOnKeyDown
) . on ( 'paste' ,
chunkOnPaste
2021-09-27 22:33:24 +02:00
) . on ( 'click' ,
2021-09-27 19:11:15 +02:00
chunkOnSelectionChange
) . on ( 'keydown' ,
2021-09-30 23:52:35 +02:00
chunkOnKeyDownSelectionChange
2021-09-27 19:11:15 +02:00
) . on ( 'focusout' ,
chunkOnFocusOut
) ;
2022-03-01 01:00:26 +01:00
mutation _observer = new MutationObserver ( chunkOnDOMMutate ) ;
2022-06-30 17:31:54 +02:00
$ ( "#gamescreen" ) . on ( 'click' , function ( e ) {
if ( this !== e . target ) {
return ;
}
document . activeElement . blur ( ) ;
} ) ;
2021-09-27 19:11:15 +02:00
// This is required for the editor to work correctly in Firefox on desktop
// because the gods of HTML and JavaScript say so
$ ( document . body ) . on ( 'focusin' , function ( event ) {
setTimeout ( function ( ) {
2021-09-27 22:04:42 +02:00
if ( document . activeElement !== game _text [ 0 ] && game _text [ 0 ] . contains ( document . activeElement ) ) {
game _text [ 0 ] . focus ( ) ;
2021-09-27 19:11:15 +02:00
}
} , 2 ) ;
} ) ;
2022-06-06 03:06:09 +02:00
var us _click _handler = function ( ev ) {
setTimeout ( function ( ) {
if ( us _dragging ) {
return ;
}
var target = $ ( ev . target ) . closest ( ".uslistitem" ) [ 0 ] ;
if ( $ . contains ( document . getElementById ( "uslistunloaded" ) , target ) ) {
document . getElementById ( "uslistloaded" ) . appendChild ( target ) ;
} else {
document . getElementById ( "uslistunloaded" ) . appendChild ( target ) ;
}
} , 10 ) ;
}
2022-06-14 02:18:09 +02:00
var samplers _click _handler = function ( ev ) {
setTimeout ( function ( ) {
if ( samplers _dragging ) {
return ;
}
var target = $ ( ev . target ) . closest ( ".samplerslistitem" ) ;
var next = target . parent ( ) . next ( ) . find ( ".samplerslistitem" ) ;
if ( ! next . length ) {
return ;
}
next . parent ( ) . after ( target . parent ( ) ) ;
} , 10 ) ;
}
2021-12-13 07:03:26 +01:00
// Make the userscripts menu sortable
var us _sortable _settings = {
2021-12-22 19:12:35 +01:00
placeholder : "ussortable-placeholder" ,
2022-06-06 03:06:09 +02:00
start : function ( ) { us _dragging = true ; } ,
stop : function ( ) { us _dragging = false ; } ,
2021-12-13 07:03:26 +01:00
delay : 2 ,
cursor : "move" ,
tolerance : "pointer" ,
opacity : 0.21 ,
revert : 173 ,
scrollSensitivity : 64 ,
scrollSpeed : 10 ,
}
2022-06-06 03:06:09 +02:00
usunloaded . sortable ( $ . extend ( {
2021-12-13 07:03:26 +01:00
connectWith : "#uslistloaded" ,
2022-06-06 03:06:09 +02:00
} , us _sortable _settings ) ) . on ( "click" , ".uslistitem" , us _click _handler ) ;
usloaded . sortable ( $ . extend ( {
2021-12-13 07:03:26 +01:00
connectWith : "#uslistunloaded" ,
2022-06-06 03:06:09 +02:00
} , us _sortable _settings ) ) . on ( "click" , ".uslistitem" , us _click _handler ) ;
2021-12-13 07:03:26 +01:00
2022-06-14 02:18:09 +02:00
// Make the samplers menu sortable
var samplers _sortable _settings = {
placeholder : "samplerssortable-placeholder" ,
start : function ( ) { samplers _dragging = true ; } ,
stop : function ( ) { samplers _dragging = false ; } ,
delay : 2 ,
cursor : "move" ,
tolerance : "pointer" ,
opacity : 0.21 ,
revert : 173 ,
scrollSensitivity : 64 ,
scrollSpeed : 10 ,
}
samplerslist . sortable ( $ . extend ( {
} , samplers _sortable _settings ) ) . on ( "click" , ".samplerslistitem" , samplers _click _handler ) ;
2021-05-03 00:48:47 +02:00
// Bind actions to UI buttons
button _send . on ( "click" , function ( ev ) {
dosubmit ( ) ;
} ) ;
2021-08-19 13:18:01 +02:00
button _mode . on ( "click" , function ( ev ) {
changemode ( ) ;
} ) ;
2021-05-03 00:48:47 +02:00
button _actretry . on ( "click" , function ( ev ) {
2022-07-28 05:13:08 +02:00
ignore _stream = false ;
2021-08-25 20:42:37 +02:00
hideMessage ( ) ;
2021-12-27 04:21:58 +01:00
socket . send ( { 'cmd' : 'retry' , 'chatname' : chatmode ? chat _name . val ( ) : undefined , 'data' : '' } ) ;
2021-05-29 11:46:03 +02:00
hidegenseqs ( ) ;
2021-05-03 00:48:47 +02:00
} ) ;
button _actback . on ( "click" , function ( ev ) {
2021-08-25 20:42:37 +02:00
hideMessage ( ) ;
2021-05-03 00:48:47 +02:00
socket . send ( { 'cmd' : 'back' , 'data' : '' } ) ;
2021-05-29 11:46:03 +02:00
hidegenseqs ( ) ;
2021-05-03 00:48:47 +02:00
} ) ;
2022-01-21 21:30:37 +01:00
button _actfwd . on ( "click" , function ( ev ) {
hideMessage ( ) ;
2022-01-24 21:15:45 +01:00
//hidegenseqs();
2022-01-21 21:30:37 +01:00
socket . send ( { 'cmd' : 'redo' , 'data' : '' } ) ;
} ) ;
2021-05-03 00:48:47 +02:00
button _actmem . on ( "click" , function ( ev ) {
socket . send ( { 'cmd' : 'memory' , 'data' : '' } ) ;
} ) ;
2021-05-22 11:28:40 +02:00
button _savetofile . on ( "click" , function ( ev ) {
socket . send ( { 'cmd' : 'savetofile' , 'data' : '' } ) ;
2021-05-03 00:48:47 +02:00
} ) ;
2021-05-22 11:28:40 +02:00
button _loadfrfile . on ( "click" , function ( ev ) {
2021-11-05 00:33:17 +01:00
if ( remote ) {
$ ( "#remote-save-select" ) . click ( ) ;
} else {
socket . send ( { 'cmd' : 'loadfromfile' , 'data' : '' } ) ;
}
} ) ;
$ ( "#remote-save-select" ) . on ( "change" , function ( ) {
var reader = new FileReader ( ) ;
var file = $ ( "#remote-save-select" ) [ 0 ] . files [ 0 ] ;
reader . addEventListener ( "load" , function ( response ) {
socket . send ( { 'cmd' : 'loadfromstring' , 'filename' : file . name , 'data' : response . target . result } ) ;
} , false ) ;
reader . readAsText ( file ) ;
2021-05-03 00:48:47 +02:00
} ) ;
2021-05-11 06:27:34 +02:00
button _import . on ( "click" , function ( ev ) {
socket . send ( { 'cmd' : 'import' , 'data' : '' } ) ;
} ) ;
2021-05-29 11:46:03 +02:00
button _importwi . on ( "click" , function ( ev ) {
socket . send ( { 'cmd' : 'importwi' , 'data' : '' } ) ;
} ) ;
2021-05-04 15:56:48 +02:00
button _settings . on ( "click" , function ( ev ) {
$ ( '#settingsmenu' ) . slideToggle ( "slow" ) ;
} ) ;
2021-05-11 01:17:10 +02:00
button _format . on ( "click" , function ( ev ) {
$ ( '#formatmenu' ) . slideToggle ( "slow" ) ;
} ) ;
2021-05-11 06:27:34 +02:00
popup _close . on ( "click" , function ( ev ) {
socket . send ( { 'cmd' : 'importcancel' , 'data' : '' } ) ;
2021-05-04 15:56:48 +02:00
} ) ;
2021-05-11 06:27:34 +02:00
popup _accept . on ( "click" , function ( ev ) {
socket . send ( { 'cmd' : 'importaccept' , 'data' : '' } ) ;
} ) ;
2021-05-13 07:26:42 +02:00
button _actwi . on ( "click" , function ( ev ) {
socket . send ( { 'cmd' : 'wi' , 'data' : '' } ) ;
} ) ;
2021-05-16 11:29:39 +02:00
button _impaidg . on ( "click" , function ( ev ) {
2021-12-30 22:33:28 +01:00
if ( connected ) {
showAidgPopup ( ) ;
}
2021-05-16 11:29:39 +02:00
} ) ;
aidg _close . on ( "click" , function ( ev ) {
hideAidgPopup ( ) ;
} ) ;
aidg _accept . on ( "click" , function ( ev ) {
sendAidgImportRequest ( ) ;
} ) ;
2021-05-11 06:27:34 +02:00
2021-05-22 11:28:40 +02:00
button _save . on ( "click" , function ( ev ) {
socket . send ( { 'cmd' : 'saverequest' , 'data' : '' } ) ;
} ) ;
button _saveas . on ( "click" , function ( ev ) {
2021-12-30 22:33:28 +01:00
if ( connected ) {
showSaveAsPopup ( ) ;
}
2021-05-22 11:28:40 +02:00
} ) ;
saveas _close . on ( "click" , function ( ev ) {
hideSaveAsPopup ( ) ;
socket . send ( { 'cmd' : 'clearoverwrite' , 'data' : '' } ) ;
} ) ;
saveas _accept . on ( "click" , function ( ev ) {
sendSaveAsRequest ( ) ;
} ) ;
2021-09-01 19:32:11 +02:00
button _download . on ( "click" , function ( ev ) {
2021-09-19 23:16:01 +02:00
downloadStory ( 'json' ) ;
2021-09-01 19:32:11 +02:00
} ) ;
2021-09-01 19:46:37 +02:00
button _downloadtxt . on ( "click" , function ( ev ) {
2021-12-30 22:37:48 +01:00
if ( connected ) {
downloadStory ( 'plaintext' ) ;
}
2021-09-01 19:46:37 +02:00
} ) ;
2021-05-22 11:28:40 +02:00
button _load . on ( "click" , function ( ev ) {
socket . send ( { 'cmd' : 'loadlistrequest' , 'data' : '' } ) ;
} ) ;
2021-10-22 20:18:10 +02:00
button _softprompt . on ( "click" , function ( ev ) {
socket . send ( { 'cmd' : 'splistrequest' , 'data' : '' } ) ;
} ) ;
2021-12-13 07:03:26 +01:00
button _userscripts . on ( "click" , function ( ev ) {
socket . send ( { 'cmd' : 'uslistrequest' , 'data' : '' } ) ;
} ) ;
2022-06-14 02:18:09 +02:00
button _samplers . on ( "click" , function ( ev ) {
socket . send ( { 'cmd' : 'samplerlistrequest' , 'data' : '' } ) ;
} ) ;
2021-05-22 11:28:40 +02:00
load _close . on ( "click" , function ( ev ) {
hideLoadPopup ( ) ;
} ) ;
2022-03-07 01:51:35 +01:00
load _model _close . on ( "click" , function ( ev ) {
2022-03-07 17:57:33 +01:00
$ ( "#modellayers" ) . addClass ( "hidden" ) ;
2022-03-07 01:51:35 +01:00
hideLoadModelPopup ( ) ;
} ) ;
2021-05-22 11:28:40 +02:00
load _accept . on ( "click" , function ( ev ) {
2021-12-22 18:19:36 +01:00
hideMessage ( ) ;
2021-08-23 08:34:27 +02:00
newly _loaded = true ;
2021-05-22 11:28:40 +02:00
socket . send ( { 'cmd' : 'loadrequest' , 'data' : '' } ) ;
hideLoadPopup ( ) ;
} ) ;
2022-03-07 01:51:35 +01:00
load _model _accept . on ( "click" , function ( ev ) {
hideMessage ( ) ;
2022-03-07 17:27:23 +01:00
var gpu _layers ;
var message ;
2022-06-07 01:21:10 +02:00
if ( $ ( "#modellayers" ) [ 0 ] . classList . contains ( 'hidden' ) ) {
2022-03-07 17:27:23 +01:00
gpu _layers = ","
} else {
gpu _layers = ""
for ( let i = 0 ; i < $ ( "#gpu_count" ) [ 0 ] . value ; i ++ ) {
gpu _layers += $ ( "#gpu_layers" + i ) [ 0 ] . value + "," ;
}
}
2022-06-20 04:53:30 +02:00
var disk _layers = $ ( "#disk_layers" ) . length > 0 ? $ ( "#disk_layers" ) [ 0 ] . value : 0 ;
message = { 'cmd' : 'load_model' , 'use_gpu' : $ ( '#use_gpu' ) [ 0 ] . checked , 'key' : $ ( '#modelkey' ) [ 0 ] . value , 'gpu_layers' : gpu _layers . slice ( 0 , - 1 ) , 'disk_layers' : disk _layers , 'url' : $ ( '#modelurl' ) [ 0 ] . value , 'online_model' : $ ( '#oaimodel' ) [ 0 ] . value } ;
2022-03-07 17:27:23 +01:00
socket . send ( message ) ;
2022-03-07 01:51:35 +01:00
loadmodelcontent . html ( "" ) ;
hideLoadModelPopup ( ) ;
} ) ;
2021-10-22 20:18:10 +02:00
sp _close . on ( "click" , function ( ev ) {
hideSPPopup ( ) ;
} ) ;
sp _accept . on ( "click" , function ( ev ) {
2021-12-22 18:19:36 +01:00
hideMessage ( ) ;
2021-10-22 20:18:10 +02:00
socket . send ( { 'cmd' : 'sprequest' , 'data' : '' } ) ;
hideSPPopup ( ) ;
} ) ;
2021-12-13 07:03:26 +01:00
us _close . on ( "click" , function ( ev ) {
socket . send ( { 'cmd' : 'usloaded' , 'data' : usloaded . find ( ".uslistitem" ) . map ( function ( ) { return $ ( this ) . attr ( "name" ) ; } ) . toArray ( ) } ) ;
hideUSPopup ( ) ;
} ) ;
us _accept . on ( "click" , function ( ev ) {
2021-12-22 18:19:36 +01:00
hideMessage ( ) ;
2021-12-13 07:03:26 +01:00
socket . send ( { 'cmd' : 'usloaded' , 'data' : usloaded . find ( ".uslistitem" ) . map ( function ( ) { return $ ( this ) . attr ( "name" ) ; } ) . toArray ( ) } ) ;
socket . send ( { 'cmd' : 'usload' , 'data' : '' } ) ;
hideUSPopup ( ) ;
} ) ;
2022-06-14 02:18:09 +02:00
samplers _close . on ( "click" , function ( ev ) {
hideSamplersPopup ( ) ;
} ) ;
samplers _accept . on ( "click" , function ( ev ) {
hideMessage ( ) ;
socket . send ( { 'cmd' : 'samplers' , 'data' : samplerslist . find ( ".samplerslistitem" ) . map ( function ( ) { return parseInt ( $ ( this ) . attr ( "sid" ) ) ; } ) . toArray ( ) } ) ;
hideSamplersPopup ( ) ;
} ) ;
2021-05-22 11:28:40 +02:00
2022-03-07 01:51:35 +01:00
button _loadmodel . on ( "click" , function ( ev ) {
showLoadModelPopup ( ) ;
socket . send ( { 'cmd' : 'list_model' , 'data' : 'mainmenu' } ) ;
} ) ;
2022-03-08 00:44:37 +01:00
button _showmodel . on ( "click" , function ( ev ) {
socket . send ( { 'cmd' : 'show_model' , 'data' : '' } ) ;
} ) ;
2022-03-07 01:51:35 +01:00
2021-05-22 11:28:40 +02:00
button _newgame . on ( "click" , function ( ev ) {
2021-12-30 22:33:28 +01:00
if ( connected ) {
showNewStoryPopup ( ) ;
}
2021-05-22 11:28:40 +02:00
} ) ;
ns _accept . on ( "click" , function ( ev ) {
2021-12-22 18:19:36 +01:00
hideMessage ( ) ;
2021-05-22 11:28:40 +02:00
socket . send ( { 'cmd' : 'newgame' , 'data' : '' } ) ;
hideNewStoryPopup ( ) ;
} ) ;
ns _close . on ( "click" , function ( ev ) {
hideNewStoryPopup ( ) ;
2021-08-19 12:54:44 +02:00
} ) ;
2021-09-01 19:05:24 +02:00
$ ( "#btn_dsclose" ) . on ( "click" , function ( ) {
$ ( "#loadcontainerdelete" ) . removeClass ( "flex" ) . addClass ( "hidden" ) ;
hide ( [ $ ( ".saveasoverwrite" ) , $ ( ".popuperror" ) ] ) ;
} ) ;
2021-09-01 19:10:21 +02:00
$ ( "#newsavename" ) . on ( "input" , function ( ev ) {
if ( $ ( this ) . val ( ) == "" ) {
disableButtons ( [ $ ( "#btn_rensaccept" ) ] ) ;
} else {
enableButtons ( [ $ ( "#btn_rensaccept" ) ] ) ;
}
hide ( [ $ ( ".saveasoverwrite" ) , $ ( ".popuperror" ) ] ) ;
2021-09-01 19:05:24 +02:00
} ) ;
$ ( "#btn_rensclose" ) . on ( "click" , function ( ) {
$ ( "#loadcontainerrename" ) . removeClass ( "flex" ) . addClass ( "hidden" ) ;
hide ( [ $ ( ".saveasoverwrite" ) , $ ( ".popuperror" ) ] ) ;
} ) ;
2021-08-19 12:54:44 +02:00
button _rndgame . on ( "click" , function ( ev ) {
2021-12-30 22:33:28 +01:00
if ( connected ) {
showRandomStoryPopup ( ) ;
}
2021-08-19 12:54:44 +02:00
} ) ;
rs _accept . on ( "click" , function ( ev ) {
2022-07-28 05:13:08 +02:00
ignore _stream = false ;
2021-12-22 18:19:36 +01:00
hideMessage ( ) ;
2021-12-30 05:15:59 +01:00
socket . send ( { 'cmd' : 'rndgame' , 'memory' : $ ( "#rngmemory" ) . val ( ) , 'data' : topic . val ( ) } ) ;
2021-08-19 12:54:44 +02:00
hideRandomStoryPopup ( ) ;
} ) ;
rs _close . on ( "click" , function ( ev ) {
hideRandomStoryPopup ( ) ;
2021-05-22 11:28:40 +02:00
} ) ;
2021-05-23 04:06:10 +02:00
anote _slider . on ( "input" , function ( ) {
socket . send ( { 'cmd' : 'anotedepth' , 'data' : $ ( this ) . val ( ) } ) ;
} ) ;
2021-12-05 05:59:28 +01:00
// Dynamically change vertical size of world info "Comment" text box
wi _menu . on ( "input" , ".wicomment > textarea" , function ( ) {
adjustWiCommentHeight ( this ) ;
} ) ;
// Dynamically change vertical size of world info folder name text box
wi _menu . on ( "input" , ".wifoldername > div > textarea" , function ( ) {
adjustWiFolderNameHeight ( this ) ;
} ) ;
2021-05-22 11:28:40 +02:00
saveasinput . on ( "input" , function ( ) {
if ( saveasinput . val ( ) == "" ) {
disableButtons ( [ saveas _accept ] ) ;
} else {
enableButtons ( [ saveas _accept ] ) ;
}
2021-09-01 00:22:30 +02:00
hide ( [ $ ( ".saveasoverwrite" ) , $ ( ".popuperror" ) ] ) ;
2021-05-22 11:28:40 +02:00
} ) ;
2021-05-03 00:48:47 +02:00
// Bind Enter button to submit
input _text . keydown ( function ( ev ) {
if ( ev . which == 13 && ! shift _down ) {
do _clear _ent = true ;
2022-01-10 22:36:15 +01:00
dosubmit ( true ) ;
2021-05-03 00:48:47 +02:00
} else if ( ev . which == 16 ) {
shift _down = true ;
}
} ) ;
2021-05-05 09:04:06 +02:00
// Enter to submit, but not if holding shift
2021-05-03 00:48:47 +02:00
input _text . keyup ( function ( ev ) {
if ( ev . which == 13 && do _clear _ent ) {
input _text . val ( "" ) ;
do _clear _ent = false ;
} else if ( ev . which == 16 ) {
shift _down = false ;
}
} ) ;
2021-05-16 11:29:39 +02:00
aidgpromptnum . keydown ( function ( ev ) {
if ( ev . which == 13 ) {
sendAidgImportRequest ( ) ;
}
} ) ;
2021-05-22 11:28:40 +02:00
saveasinput . keydown ( function ( ev ) {
if ( ev . which == 13 && saveasinput . val ( ) != "" ) {
sendSaveAsRequest ( ) ;
}
} ) ;
2021-05-03 00:48:47 +02:00
2022-01-18 23:20:45 +01:00
$ ( [ input _text , anote _input , $ ( "#gamescreen" ) ] ) . map ( $ . fn . toArray ) . on ( "input" , function ( ) {
setGameSaved ( false ) ;
} ) ;
2022-01-17 18:11:06 +01:00
$ ( window ) . on ( "beforeunload" , function ( ) {
2022-01-18 23:20:45 +01:00
if ( ! gamesaved ) {
2022-01-17 18:11:06 +01:00
return true ;
}
} ) ;
} ) ;
2022-06-30 15:44:04 +02:00
var popup _deleteable = false ;
var popup _editable = false ;
2022-06-30 21:57:27 +02:00
var popup _renameable = false ;
2022-06-30 15:44:04 +02:00
function load _popup ( data ) {
2022-07-01 01:13:05 +02:00
document . getElementById ( 'spcontainer' ) . classList . add ( 'hidden' ) ;
document . getElementById ( 'uscontainer' ) . classList . add ( 'hidden' ) ;
2022-06-30 15:44:04 +02:00
popup _deleteable = data . deleteable ;
popup _editable = data . editable ;
2022-06-30 21:57:27 +02:00
popup _renameable = data . renameable ;
2022-06-30 15:44:04 +02:00
var popup = document . getElementById ( "popup" ) ;
2022-06-30 21:57:27 +02:00
var popup _title = document . getElementById ( "popup_title" ) ;
popup _title . textContent = data . popup _title ;
2022-06-30 15:44:04 +02:00
var popup _list = document . getElementById ( "popup_list" ) ;
//first, let's clear out our existing data
while ( popup _list . firstChild ) {
popup _list . removeChild ( popup _list . firstChild ) ;
}
var breadcrumbs = document . getElementById ( 'popup_breadcrumbs' ) ;
while ( breadcrumbs . firstChild ) {
breadcrumbs . removeChild ( breadcrumbs . firstChild ) ;
}
2022-06-30 21:57:27 +02:00
if ( data . upload ) {
const dropArea = document . getElementById ( 'popup_list' ) ;
dropArea . addEventListener ( 'dragover' , ( event ) => {
event . stopPropagation ( ) ;
event . preventDefault ( ) ;
// Style the drag-and-drop as a "copy file" operation.
event . dataTransfer . dropEffect = 'copy' ;
} ) ;
dropArea . addEventListener ( 'drop' , ( event ) => {
event . stopPropagation ( ) ;
event . preventDefault ( ) ;
const fileList = event . dataTransfer . files ;
for ( file of fileList ) {
reader = new FileReader ( ) ;
reader . onload = function ( event ) {
socket . emit ( "upload_file" , { 'filename' : file . name , "data" : event . target . result } ) ;
} ;
reader . readAsArrayBuffer ( file ) ;
}
} ) ;
} else {
}
2022-06-30 15:44:04 +02:00
popup . classList . remove ( "hidden" ) ;
//adjust accept button
2022-06-30 21:57:27 +02:00
if ( data . call _back == "" ) {
2022-07-01 01:13:05 +02:00
document . getElementById ( "popup_accept" ) . classList . add ( "hidden" ) ;
2022-06-30 21:57:27 +02:00
} else {
2022-07-01 01:13:05 +02:00
document . getElementById ( "popup_accept" ) . classList . remove ( "hidden" ) ;
2022-06-30 21:57:27 +02:00
var accept = document . getElementById ( "popup_accept" ) ;
accept . classList . add ( "disabled" ) ;
accept . setAttribute ( "emit" , data . call _back ) ;
accept . setAttribute ( "selected_value" , "" ) ;
accept . onclick = function ( ) {
socket . emit ( this . emit , this . getAttribute ( "selected_value" ) ) ;
document . getElementById ( "popup" ) . classList . add ( "hidden" ) ;
} ;
}
2022-06-30 15:44:04 +02:00
}
function popup _items ( data ) {
var popup _list = document . getElementById ( 'popup_list' ) ;
//first, let's clear out our existing data
while ( popup _list . firstChild ) {
popup _list . removeChild ( popup _list . firstChild ) ;
}
2022-06-30 21:57:27 +02:00
document . getElementById ( 'popup_upload_input' ) . value = "" ;
2022-06-30 15:44:04 +02:00
for ( item of data ) {
var list _item = document . createElement ( "span" ) ;
list _item . classList . add ( "item" ) ;
//create the folder icon
var folder _icon = document . createElement ( "span" ) ;
folder _icon . classList . add ( "folder_icon" ) ;
if ( item [ 0 ] ) {
folder _icon . classList . add ( "oi" ) ;
folder _icon . setAttribute ( 'data-glyph' , "folder" ) ;
}
list _item . append ( folder _icon ) ;
//create the edit icon
var edit _icon = document . createElement ( "span" ) ;
edit _icon . classList . add ( "edit_icon" ) ;
if ( ( popup _editable ) && ! ( item [ 0 ] ) ) {
edit _icon . classList . add ( "oi" ) ;
2022-06-30 21:57:27 +02:00
edit _icon . setAttribute ( 'data-glyph' , "spreadsheet" ) ;
edit _icon . title = "Edit"
2022-06-30 15:44:04 +02:00
edit _icon . id = item [ 1 ] ;
edit _icon . onclick = function ( ) {
socket . emit ( "popup_edit" , this . id ) ;
} ;
}
list _item . append ( edit _icon ) ;
2022-06-30 21:57:27 +02:00
//create the rename icon
var rename _icon = document . createElement ( "span" ) ;
rename _icon . classList . add ( "rename_icon" ) ;
if ( ( popup _renameable ) && ! ( item [ 0 ] ) ) {
rename _icon . classList . add ( "oi" ) ;
rename _icon . setAttribute ( 'data-glyph' , "pencil" ) ;
rename _icon . title = "Rename"
rename _icon . id = item [ 1 ] ;
rename _icon . setAttribute ( "filename" , item [ 2 ] ) ;
rename _icon . onclick = function ( ) {
var new _name = prompt ( "Please enter new filename for \n" + this . getAttribute ( "filename" ) ) ;
if ( new _name != null ) {
socket . emit ( "popup_rename" , { "file" : this . id , "new_name" : new _name } ) ;
}
} ;
}
list _item . append ( rename _icon ) ;
2022-06-30 15:44:04 +02:00
//create the delete icon
var delete _icon = document . createElement ( "span" ) ;
delete _icon . classList . add ( "delete_icon" ) ;
if ( popup _deleteable ) {
delete _icon . classList . add ( "oi" ) ;
delete _icon . setAttribute ( 'data-glyph' , "x" ) ;
2022-06-30 21:57:27 +02:00
delete _icon . title = "Delete"
2022-06-30 15:44:04 +02:00
delete _icon . id = item [ 1 ] ;
delete _icon . setAttribute ( "folder" , item [ 0 ] ) ;
delete _icon . onclick = function ( ) {
if ( this . getAttribute ( "folder" ) == "true" ) {
if ( window . confirm ( "Do you really want to delete this folder and ALL files under it?" ) ) {
socket . emit ( "popup_delete" , this . id ) ;
}
} else {
if ( window . confirm ( "Do you really want to delete this file?" ) ) {
socket . emit ( "popup_delete" , this . id ) ;
}
}
} ;
}
list _item . append ( delete _icon ) ;
//create the actual item
var popup _item = document . createElement ( "span" ) ;
popup _item . classList . add ( "file" ) ;
popup _item . id = item [ 1 ] ;
popup _item . setAttribute ( "folder" , item [ 0 ] ) ;
popup _item . setAttribute ( "valid" , item [ 3 ] ) ;
popup _item . textContent = item [ 2 ] ;
popup _item . onclick = function ( ) {
var accept = document . getElementById ( "popup_accept" ) ;
if ( this . getAttribute ( "valid" ) == "true" ) {
2022-06-30 21:57:27 +02:00
accept . classList . remove ( "disabled" ) ;
2022-06-30 15:44:04 +02:00
accept . setAttribute ( "selected_value" , this . id ) ;
} else {
console . log ( "not valid" ) ;
accept . setAttribute ( "selected_value" , "" ) ;
2022-06-30 21:57:27 +02:00
accept . classList . add ( "disabled" ) ;
2022-06-30 15:44:04 +02:00
if ( this . getAttribute ( "folder" ) == "true" ) {
console . log ( "folder" ) ;
socket . emit ( "popup_change_folder" , this . id ) ;
}
}
} ;
list _item . append ( popup _item ) ;
popup _list . append ( list _item ) ;
}
}
function popup _breadcrumbs ( data ) {
var breadcrumbs = document . getElementById ( 'popup_breadcrumbs' )
while ( breadcrumbs . firstChild ) {
breadcrumbs . removeChild ( breadcrumbs . firstChild ) ;
}
for ( item of data ) {
var button = document . createElement ( "button" ) ;
button . id = item [ 0 ] ;
button . textContent = item [ 1 ] ;
button . classList . add ( "breadcrumbitem" ) ;
button . onclick = function ( ) {
socket . emit ( "popup_change_folder" , this . id ) ;
} ;
breadcrumbs . append ( button ) ;
var span = document . createElement ( "span" ) ;
span . textContent = "\\" ;
breadcrumbs . append ( span ) ;
}
}
function popup _edit _file ( data ) {
var popup _list = document . getElementById ( 'popup_list' ) ;
2022-07-20 00:50:03 +02:00
var accept = document . getElementById ( "popup_accept" ) ;
accept . classList . add ( "btn-secondary" ) ;
accept . classList . remove ( "btn-primary" ) ;
accept . textContent = "Save" ;
2022-06-30 15:44:04 +02:00
//first, let's clear out our existing data
while ( popup _list . firstChild ) {
popup _list . removeChild ( popup _list . firstChild ) ;
}
var accept = document . getElementById ( "popup_accept" ) ;
accept . setAttribute ( "selected_value" , "" ) ;
accept . onclick = function ( ) {
var textarea = document . getElementById ( "filecontents" ) ;
socket . emit ( "popup_change_file" , { "file" : textarea . getAttribute ( "filename" ) , "data" : textarea . value } ) ;
document . getElementById ( "popup" ) . classList . add ( "hidden" ) ;
2022-07-20 00:50:03 +02:00
this . classList . add ( "hidden" ) ;
2022-06-30 15:44:04 +02:00
} ;
var textarea = document . createElement ( "textarea" ) ;
textarea . classList . add ( "fullwidth" ) ;
textarea . rows = 25 ;
textarea . id = "filecontents"
textarea . setAttribute ( "filename" , data . file ) ;
textarea . value = data . text ;
textarea . onblur = function ( ) {
var accept = document . getElementById ( "popup_accept" ) ;
2022-07-20 00:50:03 +02:00
accept . classList . remove ( "hidden" ) ;
accept . classList . remove ( "btn-secondary" ) ;
accept . classList . add ( "btn-primary" ) ;
2022-06-30 15:44:04 +02:00
} ;
popup _list . append ( textarea ) ;
}
2022-06-30 21:57:27 +02:00
function error _popup ( data ) {
alert ( data ) ;
}
function upload _file ( file _box ) {
var fileList = file _box . files ;
for ( file of fileList ) {
reader = new FileReader ( ) ;
reader . onload = function ( event ) {
socket . emit ( "upload_file" , { 'filename' : file . name , "data" : event . target . result } ) ;
} ;
reader . readAsArrayBuffer ( file ) ;
}
}