forked from city-unit/st-extension-example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
56 lines (48 loc) · 2.02 KB
/
Copy pathindex.js
File metadata and controls
56 lines (48 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// The main script for the extension
// The following are examples of some basic extension functionality
//You'll likely need to import extension_settings, getContext, and loadExtensionSettings from extensions.js
import { extension_settings, getContext, loadExtensionSettings } from "../../../extensions.js";
//You'll likely need to import some other functions from the main script
import { saveSettingsDebounced } from "../../../../script.js";
// Keep track of where your extension is located, name should match repo name
const extensionName = "st-extension-example";
const extensionFolderPath = `scripts/extensions/third-party/${extensionName}`;
const extensionSettings = extension_settings[extensionName];
const defaultSettings = {};
function mark_out_of_context(data) {
const siblings = [];
let prev = document.getElementsByClassName('lastInContext');
if (prev.length > 0) {
prev = prev[0].previousElementSibling;
} else {
return;
}
while (prev) {
siblings.unshift(prev);
prev = prev.previousElementSibling;
}
document.querySelectorAll('.out-of-context').forEach(element => {
element.classList.remove('out-of-context');
});
console.log(siblings);
for (const ooc of siblings) {
ooc.classList.add("out-of-context");
}
}
// Loads the extension settings if they exist, otherwise initializes them to the defaults.
async function loadSettings() {
//Create the settings if they don't exist
extension_settings[extensionName] = extension_settings[extensionName] || {};
if (Object.keys(extension_settings[extensionName]).length === 0) {
Object.assign(extension_settings[extensionName], defaultSettings);
}
}
// This function is called when the extension is loaded
jQuery(async () => {
// Load settings when starting things up (if you have any)
loadSettings();
const { eventSource, event_types } = SillyTavern.getContext();
eventSource.on(event_types.CHARACTER_MESSAGE_RENDERED, mark_out_of_context);
eventSource.on(event_types.MORE_MESSAGES_LOADED, mark_out_of_context);
more_messages_loaded
});