Специально для руководства Chilli | by R.Onix

Специально для руководства CHilli | by R.Onix

Versione datata 06/05/2024. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         Специально для руководства Chilli | by R.Onix
// @namespace    https://forum.blackrussia.online
// @version      1
// @description  Специально для руководства CHilli | by R.Onix
// @author       Roman_Onix
// @match        https://forum.blackrussia.online/threads/*
// @include      https://forum.blackrussia.online/threads/
// @grant        none
// @license 	 MIT
// @icon https://grizly.club/uploads/posts/2023-08/1691524743_grizly-club-p-kartinki-znachok-blek-rasha-bez-fona-1.png
// ==/UserScript==

(function () {
  'use strict';
const UNACCEPT_PREFIX = 4; // Prefix that will be set when thread closes
const ACCEPT_PREFIX = 8; // Prefix that will be set when thread accepted
const RESHENO_PREFIX = 6; // Prefix that will be set when solving the problem
const PIN_PREFIX = 2; // Prefix that will be set when thread pins
const GA_PREFIX = 12; // Prefix that will be set when thread send to ga
const COMMAND_PREFIX = 10; // Prefix that will be set when thread send to project team
const WATCHED_PREFIX = 9;
const TEX_PREFIX = 13;
const CLOSE_PREFIX = 7;
const buttons = [
 {
	  title: '| На рассмотрение |',
	  content:
		"[B][CENTER][COLOR=rgb(255, 0, 0)][FONT=times new roman]{{ greeting }}, уважаемый [/COLOR]{{ user.name }} [/CENTER][/B]"+
        "[CENTER][url=https://postimages.org/][img]https://i.postimg.cc/NGJ4XCRp/W9QTj.png[/img][/url][/CENTER]"+
		"[B][CENTER][COLOR=rgb(209, 213, 216)][FONT=times new roman] Ваша жалоба взята на [COLOR=#fff700]рассмотрение[/COLOR], ожидайте вердикта.[/COLOR][/CENTER][/B]<br><br>"+
                "[B][CENTER][COLOR=#fff700][FONT=times new roman][COLOR=#fff700]На рассмотрении[/COLOR][/FONT][/CENTER][/B]",
	  prefix: PIN_PREFIX,
	  status: true,
},
    {
	  title: '| Одобрено |',
	  content:
		"[B][CENTER][COLOR=rgb(255, 0, 0)][FONT=times new roman]{{ greeting }}, уважаемый [/COLOR]{{ user.name }} [/CENTER][/B]"+
        "[CENTER][url=https://postimages.org/][img]https://i.postimg.cc/NGJ4XCRp/W9QTj.png[/img][/url][/CENTER]"+
		"[B][CENTER][COLOR=lavender][FONT=times new roman] Ваша жалоба [COLOR=#00FF00]одобрена[/COLOR], Администратор выдал наказание по ошибке.[/B]<br><br>"+
                "[B][CENTER][COLOR=#00FF00]Одобрено[/COLOR] ",
       prefix: ACCEPT_PREFIX,
	  status: false,
},
 {
	  title: '| Верно выдал наказание|',
	  content:
		"[B][CENTER][COLOR=rgb(255, 0, 0)][FONT=times new roman]{{ greeting }}, уважаемый [/COLOR]{{ user.name }} [/CENTER][/B]"+
        "[CENTER][url=https://postimages.org/][img]https://i.postimg.cc/NGJ4XCRp/W9QTj.png[/img][/url][/CENTER]"+
		"[B][CENTER][COLOR=lavender][FONT=times new roman] Ваша жалоба [COLOR=#FF0000]отказана[/COLOR], Администратор выдал наказание  верно.[/B]<br><br>"+
                "[B][CENTER][COLOR=#FF0000]Отказано[/COLOR]",
      prefix: UNACCEPT_PREFIX,
	  status: false,
},
     {
	  title: '| Недостаточно доказательств |',
	  content:
		"[B][CENTER][COLOR=rgb(255, 0, 0)][FONT=times new roman]{{ greeting }}, уважаемый [/COLOR]{{ user.name }} [/CENTER][/B]"+
        "[CENTER][url=https://postimages.org/][img]https://i.postimg.cc/NGJ4XCRp/W9QTj.png[/img][/url][/CENTER]"+
		"[B][CENTER][COLOR=lavender][FONT=times new roman] Ваша жалоба [COLOR=#FF0000]отказана[/COLOR], недостаточно доказательств.[/B] <br><br>"+
                "[B][CENTER][COLOR=#FF0000]Отказано[/COLOR]",
      prefix: UNACCEPT_PREFIX,
	  status: false,
},
     {
	  title: '| Не относится к разделу |',
	  content:
		"[B][CENTER][COLOR=rgb(255, 0, 0)][FONT=times new roman]{{ greeting }}, уважаемый [/COLOR]{{ user.name }} [/CENTER][/B]"+
        "[CENTER][url=https://postimages.org/][img]https://i.postimg.cc/NGJ4XCRp/W9QTj.png[/img][/url][/CENTER]"+
		"[B][CENTER][COLOR=lavender][FONT=times new roman] Ваше сообщение никоим образом не относится к предназначению данного раздела.[/B]<br><br>"+
                "[B][CENTER][COLOR=#FF0000]Закрыто[/COLOR]",
      prefix: CLOSE_PREFIX,
	  status: false,
},
];

$(document).ready(() => {
	// Загрузка скрипта для обработки шаблонов
	$('body').append('<script src="https://cdn.jsdelivr.net/npm/handlebars@latest/dist/handlebars.js"></script>');

	// Добавление кнопок при загрузке страницы
	addButton('Меню', 'selectAnswer');
	addButton('Одобрить✅', 'ACCEPT_PREFIX');
	addButton('Отказать⛔', 'UNACCEPT_PREFIX');
        addButton('Закрыто⛔', 'CLOSE_PREFIX');
        addButton('На рассмотрение💫', 'PIN_PREFIX');


	// Поиск информации о теме
	const threadData = getThreadData();

	$('button#pin').click(() => editThreadData(PIN_PREFIX, true));
	$('button#accepted').click(() => editThreadData(ACCEPT_PREFIX, false));
	$('button#teamProject').click(() => editThreadData(COMMAND_PREFIX, true));
	$('button#unaccept').click(() => editThreadData(UNACCEPT_PREFIX, false));

	$(`button#selectAnswer`).click(() => {
		XF.alert(buttonsMarkup(buttons), null, 'Выберите ответ:');
		buttons.forEach((btn, id) => {
			if(id > 0) {
				$(`button#answers-${id}`).click(() => pasteContent(id, threadData, true));
			} else {
				$(`button#answers-${id}`).click(() => pasteContent(id, threadData, false));
			}
		});
	});
});

function addButton(name, id) {
$('.button--icon--reply').before(
  `<button type="button" class="button rippleButton" id="${id}" style="margin: 3px;">${name}</button>`
);
}

function buttonsMarkup(buttons) {
return `<div class="select_answer">${buttons
  .map(
	(btn, i) =>
	  `<button id="answers-${i}" class="button--primary button ` +
	  `rippleButton" style="margin:5px"><span class="button-text">${btn.title}</span></button>`
  )
  .join('')}</div>`;
}

function pasteContent(id, data = {}, send = false) {
	const template = Handlebars.compile(buttons[id].content);
	if ($('.fr-element.fr-view p').text() === '') $('.fr-element.fr-view p').empty();

	$('span.fr-placeholder').empty();
	$('div.fr-element.fr-view p').append(template(data));
	$('a.overlay-titleCloser').trigger('click');

	if(send == true){
		editThreadData(buttons[id].prefix, buttons[id].status);
		$('.button--icon.button--icon--reply.rippleButton').trigger('click');
	}
}

function getThreadData() {
const authorID = $('a.username')[0].attributes['data-user-id'].nodeValue;
const authorName = $('a.username').html();
const hours = new Date().getHours();
return {
  user: {
	id: authorID,
	name: authorName,
	mention: `[USER=${authorID}]${authorName}[/USER]`,
  },
  greeting: () =>
	4 < hours && hours <= 11
	  ? 'Доброе утро'
	  : 11 < hours && hours <= 17
	  ? 'Добрый день'
	  : 17 < hours && hours <= 21
	  ? 'Добрый вечер'
	  : 'Доброй ночи',
};
}

function editThreadData(prefix, pin = false) {
// Получаем заголовок темы, так как он необходим при запросе
	const threadTitle = $('.p-title-value')[0].lastChild.textContent;

	if(pin == false){
		fetch(`${document.URL}edit`, {
		  method: 'POST',
		  body: getFormData({
			prefix_id: prefix,
			title: threadTitle,
			_xfToken: XF.config.csrf,
			_xfRequestUri: document.URL.split(XF.config.url.fullBase)[1],
			_xfWithData: 1,
			_xfResponseType: 'json',
		  }),
		}).then(() => location.reload());
	}
	if(pin == true){
		fetch(`${document.URL}edit`, {
		  method: 'POST',
		  body: getFormData({
			prefix_id: prefix,
			title: threadTitle,
			sticky: 1,
			_xfToken: XF.config.csrf,
			_xfRequestUri: document.URL.split(XF.config.url.fullBase)[1],
			_xfWithData: 1,
			_xfResponseType: 'json',
		  }),
		}).then(() => location.reload());
	}
}

function getFormData(data) {
	const formData = new FormData();
	Object.entries(data).forEach(i => formData.append(i[0], i[1]));
	return formData;
  }
})();