fix: cai dumper crashing if chat had no messages
This commit is contained in:
parent
d6e05e6e5b
commit
7087f39d5a
|
@ -35,6 +35,8 @@ And you'll reach the page that should show the `Download` link.
|
||||||
|
|
||||||
## Changelog
|
## Changelog
|
||||||
|
|
||||||
|
- **v1.4:**
|
||||||
|
- Fixed a bug where the `Download` link wouldn't show up for a given bot if you had a conversation with it where all of the messages were deleted.
|
||||||
- **v1.3:**
|
- **v1.3:**
|
||||||
- Implemented support for downloading a character's definitions from the Character Editor page.
|
- Implemented support for downloading a character's definitions from the Character Editor page.
|
||||||
- Fixed a bug where the `Download` link was not showing up on some bots that had trailing whitespace in their names (e.g. `2B `).
|
- Fixed a bug where the `Download` link was not showing up on some bots that had trailing whitespace in their names (e.g. `2B `).
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
// @namespace Violentmonkey Scripts
|
// @namespace Violentmonkey Scripts
|
||||||
// @match https://beta.character.ai/*
|
// @match https://beta.character.ai/*
|
||||||
// @grant none
|
// @grant none
|
||||||
// @version 1.3
|
// @version 1.4
|
||||||
// @author 0x000011b
|
// @author 0x000011b
|
||||||
// @description Allows downloading saved chat messages and character definitions from CharacterAI.
|
// @description Allows downloading saved chat messages and character definitions from CharacterAI.
|
||||||
// @downloadURL https://git.fuwafuwa.moe/waifu-collective/toolbox/raw/branch/master/extras/characterai-dumper/characterai-dumper.user.js
|
// @downloadURL https://git.fuwafuwa.moe/waifu-collective/toolbox/raw/branch/master/extras/characterai-dumper/characterai-dumper.user.js
|
||||||
|
@ -11,9 +11,9 @@
|
||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
|
|
||||||
const log = (firstArg, ...remainingArgs) =>
|
const log = (firstArg, ...remainingArgs) =>
|
||||||
console.log(`[CharacterAI Dumper v1.3] ${firstArg}`, ...remainingArgs);
|
console.log(`[CharacterAI Dumper v1.4] ${firstArg}`, ...remainingArgs);
|
||||||
log.error = (firstArg, ...remainingArgs) =>
|
log.error = (firstArg, ...remainingArgs) =>
|
||||||
console.error(`[CharacterAI Dumper v1.3] ${firstArg}`, ...remainingArgs);
|
console.error(`[CharacterAI Dumper v1.4] ${firstArg}`, ...remainingArgs);
|
||||||
|
|
||||||
// Endpoints to intercept.
|
// Endpoints to intercept.
|
||||||
const CHARACTER_INFO_URL = "https://beta.character.ai/chat/character/info/";
|
const CHARACTER_INFO_URL = "https://beta.character.ai/chat/character/info/";
|
||||||
|
@ -145,20 +145,22 @@ const anonymizeHistories = (histories) => {
|
||||||
// _and_ bot messages, we might've seen more names to redact, so let's go
|
// _and_ bot messages, we might've seen more names to redact, so let's go
|
||||||
// back to the first message and attempt to redact it again just in case we
|
// back to the first message and attempt to redact it again just in case we
|
||||||
// have new names.
|
// have new names.
|
||||||
namesToReplace.forEach((nameToReplace) => {
|
if (history.msgs.length) {
|
||||||
if (!nameToReplace) {
|
namesToReplace.forEach((nameToReplace) => {
|
||||||
return;
|
if (!nameToReplace) {
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const replacementRegex = new RegExp(
|
const replacementRegex = new RegExp(
|
||||||
"\\b" + escapeStringForRegExp(nameToReplace) + "\\b",
|
"\\b" + escapeStringForRegExp(nameToReplace) + "\\b",
|
||||||
"g"
|
"g"
|
||||||
);
|
);
|
||||||
history.msgs[0].text = history.msgs[0].text.replace(
|
history.msgs[0].text = history.msgs[0].text.replace(
|
||||||
replacementRegex,
|
replacementRegex,
|
||||||
"[NAME_IN_MESSAGE_REDACTED]"
|
"[NAME_IN_MESSAGE_REDACTED]"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This was modified in-place, but we return it here for simplicity at the
|
// This was modified in-place, but we return it here for simplicity at the
|
||||||
|
|
Loading…
Reference in New Issue