// ==UserScript==
// @name AniList - Activity Templates
// @namespace https://www.youtube.com/c/NurarihyonMaou/
// @version 1.1
// @description Script that gives you the possibility to create Activity Templates on AniList
// @author NurarihyonMaou
// @match https://anilist.co/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=anilist.co
// @grant GM_setValue
// @grant GM_getValue
// @require http://code.jquery.com/jquery-3.5.1.min.js
// @downloadURL https://update.greasyfork.icu/scripts/444161/AniList%20-%20Activity%20Templates.user.js
// @updateURL https://update.greasyfork.icu/scripts/444161/AniList%20-%20Activity%20Templates.meta.js
// ==/UserScript==
const $ = window.jQuery;
let currentText = '', templateName = '';
let templates = [], templateID, templatesList;
let markdown_editor, textArea, inputTemplateName, templateSelector;
let plus = '';
let minus = '';
let save = '';
let backspace = jQuery.Event("keypress");
backspace.which = 8;
let enter = jQuery.Event("keypress");
backspace.which = 13;
(function init() {
markdown_editor = document.getElementsByClassName("markdown-editor");
if (markdown_editor.length > 0) {
textArea = document.getElementsByClassName("el-textarea__inner")
$(textArea).after("");
inputTemplateName = document.getElementById("templateName");
$(markdown_editor).append("
" + plus + "
" + minus + "
" + save + "
");
$(markdown_editor).append("");
templateSelector = $("body select#templatesList");
function loadTemplatesList() {
if (GM_getValue('templates') != undefined)
templates = GM_getValue('templates');
templatesList = "";
for (let template = 0; template < templates.length; template++) {
if (template == templateID) templatesList += "";
else templatesList += "";
}
$(templateSelector).html(templatesList);
templatesList = null;
}
loadTemplatesList();
$(inputTemplateName).on('input', function () {
templateName = $(this).val();
});
$(textArea).on('input', function () {
currentText = $(this).val();
});
function loadTemplate(id) {
templateID = id;
currentText = templates[id][1];
templateName = templates[id][0];
$(textArea).val(templates[id][1]);
$(inputTemplateName).val(templates[id][0]);
}
$(templateSelector).on('click', function () {
if ($(this).val() == undefined)
return;
if ($(this).val() == -1) {
templateID = null;
$(textArea).val('');
$(inputTemplateName).val('');
}
else loadTemplate($(this).val());
});
$("body div#addT").click(function () {
if (templateName == '' || currentText == '')
return;
templates.push([[templateName], [currentText]]);
templateID = templates.length - 1;
GM_setValue("templates", templates);
loadTemplatesList();
});
$("body div#removeT").click(function () {
if (templateID == null)
return;
let deleteConfirmation;
deleteConfirmation = confirm("Are You sure that You want to delete - " + templates[templateID][0]);
if (deleteConfirmation == false)
return;
templates.splice(templateID, 1);
templateID = null;
$(textArea).val('');
$(inputTemplateName).val('');
GM_setValue("templates", templates);
loadTemplatesList();
});
$("body div#updateT").click(function () {
templates[templateID][0] = templateName;
templates[templateID][1] = currentText;
GM_setValue("templates", templates);
loadTemplatesList();
});
} else {
setTimeout(init, 0);
}
})();