Janitor Ripper

Download Janitor AI characters as Tavern JSON files (compatible with SillyTavern)

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name        Janitor Ripper
// @namespace   Violentmonkey Scripts
// @match       https://janitorai.com/*
// @grant       none
// @version     1.6
// @author      -
// @description Download Janitor AI characters as Tavern JSON files (compatible with SillyTavern)
// @license MIT
// ==/UserScript==


const delay = (ms) => new Promise((res) => setTimeout(res, ms));

function docReady(fn) {
    // see if DOM is already available
    if (document.readyState === "complete" || document.readyState === "interactive") {
        // call on next available tick
        setInterval(fn, 100);
    } else {
        document.addEventListener("DOMContentLoaded", fn);
    }
}

async function addDownloadButton() {
  let dropdown;

  while (!dropdown) {
  dropdown = document.querySelector('.css-3f016y');

  // Not yet ready
    if (!dropdown) {
    await delay(100);

    }
  }

  const existing = document.getElementById('downloadTavernButton');

  if (existing) {
    return;
  }

  const li = document.createElement('button');
  li.setAttribute('class', 'chakra-menu__menuitem css-18esm8n');
  li.setAttribute('role', 'menuitem');
  li.setAttribute('type', 'button');
  li.setAttribute('tabindex', '-1');
  li.innerText = 'Download Tavern JSON';
  li.setAttribute('id', 'downloadTavernButton');
  li.addEventListener('click', onDownloadClick);
  dropdown.prepend(li);
}

function getAccessToken(){

  for (let i = 0; i < localStorage.length; i++) {
    const item = localStorage.key(i);
    if (item.endsWith('auth-token')) {
      const token = JSON.parse(localStorage.getItem(item));
      return token['access_token'];
    }
  }
}

function download(content, fileName, contentType) {
    const a = document.createElement("a");
    const file = new Blob([content], { type: contentType });
    a.href = URL.createObjectURL(file);
    a.download = fileName;
    a.click();
}

async function onDownloadClick() {
  const fetchUrl = location.href.replace('janitorai.com', 'kim.janitorai.com');
  const characterIndex = fetchUrl.indexOf('_character');
  var newUrl = "";
  if (characterIndex !== -1) {
    newUrl = fetchUrl.substring(0, characterIndex); // 10 is the length of "_character"
  }
  const result = await fetch(newUrl, { headers: { 'Authorization': `Bearer ${getAccessToken()}`}});

  if (!result.ok) {
    alert('Could not download JSON');
    return;
  }
  console.log(newUrl);
  const data = await result.json();
  const tavernJson = JSON.stringify({
      'name': data['name'],
      'description': data['description'], // Most of them have description/personality fields reversed (blame Zoltan editor for it)
      'scenario': data['scenario'],
      'first_mes': data['first_message'],
      'personality': data['personality'],
      'mes_example': data['example_dialogs'],
  });
  download(tavernJson, `${data['name']}.json`, 'application/json');

}

docReady(addDownloadButton);