// ==UserScript==
// @name 【SillyTavern / ST酒馆】html代码注入器
// @name:zh 【ST酒馆】html代码注入器
// @name:zh-CN 【ST酒馆】html代码注入器
// @name:en 【SillyTavern】 HTML Code Injector
// @namespace https://greasyfork.org/users/Qianzhuo
// @version 1.0.20
// @description 可以让ST酒馆独立运行html代码 (Inject HTML code into SillyTavern pages.)
// @description:zh 可以让ST酒馆独立运行html代码
// @description:zh-CN 可以让ST酒馆独立运行html代码
// @description:en Inject HTML code into SillyTavern pages.
// @author Qianzhuo
// @match *://localhost:8000/*
// @match *://127.0.0.1:8000/*
// @match *://*/*:8000/*
// @include /^https?:\/\/.*:8000\//
// @grant GM_setValue
// @grant GM_getValue
// @require https://code.jquery.com/jquery-3.6.0.min.js
// @license CC BY-NC 4.0
// @downloadURL none
// ==/UserScript==
/*
【SillyTavern / ST酒馆】html代码注入器 © 2024 by Qianzhuo is licensed under CC BY-NC 4.0. To view a copy of this license, visit https://creativecommons.org/licenses/by-nc/4.0/
*/
(function () {
'use strict';
let isInjectionEnabled = false;
let displayMode = GM_getValue('displayMode', 1); // 从存储中获取,默认为1
let lastMesTextContent = '';
// 存储激活楼层的设置
let activationMode = GM_getValue('activationMode', 'all'); // 默认激活所有楼层
let customStartFloor = GM_getValue('customStartFloor', 1);
let customEndFloor = GM_getValue('customEndFloor', -1); // -1 表示最后一层
// 创建设置面板
const settingsPanel = document.createElement('div');
settingsPanel.innerHTML = `
`;
settingsPanel.id = 'html-injector-settings';
settingsPanel.style.cssText = `
position: fixed;
top: 0;
left: 0;
right: 0;
background-color: #1e1e1e;
border-bottom: 1px solid #454545;
padding: 20px;
z-index: 9999;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
box-shadow: 0 2px 10px rgba(0,0,0,0.3);
display: none;
color: #d4d4d4;
overflow-y: auto;
max-height: 50vh;
`;
document.body.appendChild(settingsPanel);
// 处理激活楼层的设置
document.getElementById('activation-mode').addEventListener('change', function () {
const customSettings = document.getElementById('custom-floor-settings');
const lastNSettings = document.getElementById('last-n-settings');
customSettings.style.display = this.value === 'custom' ? 'block' : 'none';
lastNSettings.style.display = this.value === 'lastN' ? 'block' : 'none';
activationMode = this.value;
GM_setValue('activationMode', activationMode);
if (isInjectionEnabled) {
removeInjectedIframes();
injectHtmlCode();
}
});
document.getElementById('custom-start-floor').addEventListener('change', function () {
customStartFloor = parseInt(this.value);
GM_setValue('customStartFloor', customStartFloor);
if (isInjectionEnabled) {
removeInjectedIframes();
injectHtmlCode();
}
});
document.getElementById('custom-end-floor').addEventListener('change', function () {
customEndFloor = parseInt(this.value);
GM_setValue('customEndFloor', customEndFloor);
if (isInjectionEnabled) {
removeInjectedIframes();
injectHtmlCode();
}
});
document.getElementById('last-n-floors').addEventListener('change', function () {
customEndFloor = parseInt(this.value);
GM_setValue('customEndFloor', customEndFloor);
if (isInjectionEnabled) {
removeInjectedIframes();
injectHtmlCode();
}
});
// 创建开关
function createToggleSwitch(id) {
const toggleSwitch = document.createElement('label');
toggleSwitch.className = 'switch';
toggleSwitch.innerHTML = `