Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LenAnderson/ce286b219cee4aaff639cbf38ee6c2e2 to your computer and use it in GitHub Desktop.
Save LenAnderson/ce286b219cee4aaff639cbf38ee6c2e2 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name SillyTavern - WI Next Content Shortcut
// @namespace http://tampermonkey.net/
// @version 2024-04-06
// @description try to take over the world!
// @author LenAnderson
// @match http://localhost:8000
// @grant none
// ==/UserScript==
(function() {
'use strict';
function debounce(func, timeout = 300) {
let timer;
return (...args) => {
clearTimeout(timer);
timer = setTimeout(() => { func.apply(this, args); }, timeout);
};
}
const wait = async(millis)=>(new Promise(resolve=>setTimeout(resolve,millis)));
const init = ()=>{
const taList = Array.from(document.querySelectorAll('#world_popup .world_entry_form [name="content"]'));
for (const ta of taList) {
ta.addEventListener('keydown', async(evt)=>{
if (!(evt.ctrlKey && evt.key == 'Enter')) return;
evt.preventDefault();
evt.stopPropagation();
const tas = Array.from(document.querySelectorAll('#world_popup .world_entry_form [name="content"]'));
const idx = tas.indexOf(ta);
let newTa;
if (idx + 1 >= tas.length) {
const pagi = document.querySelector('#world_popup #world_info_pagination');
const next = pagi.querySelector('.paginationjs-next');
if (next.classList.contains('disabled')) return;
next.click();
while (ta.closest('body')) await wait(100);
newTa = document.querySelector('#world_popup .world_entry_form [name="content"]');
} else {
newTa = tas[idx+1];
}
const entry = newTa.closest('.world_entry');
if (entry.querySelector('.inline-drawer-toggle .inline-drawer-icon.down')) {
entry.querySelector('.inline-drawer-toggle').click();
}
entry.scrollIntoView();
newTa.focus();
});
}
};
init();
const mo = new MutationObserver(debounce(init));
mo.observe(document.body, {childList:true, subtree:true, attributes:true});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment