NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name Обработка текста // @namespace markupTextScript // @description Добавляет кнопку для обработки текста. // @match *://10.*.54.*/ // @grant none // @version 1.4 // @author Alexey <hello@h3ro.ru> // @license MIT // ==/UserScript== /* Кнопка для нового вида интерфейса */ // if ($('div.col div.btn-toolbar').length) { // $('div.col div.btn-toolbar').prepend(`<button id="markup" class="btn btn-outline-primary"><i class="far fa-edit"></i> Обработать</button>`); // } /* Кнопка для старого вида интерфейса */ if ($('div.btn-toolbar').length) { $('div.btn-toolbar').prepend(`<button id="markup" class="mr-2 btn btn-outline-primary"><i class="far fa-edit"></i> Обработать</button>`); } $(document).on('click', '#markup', function(){ var text = $('#data').val(); /* На всякий случай пишем исходный текст в консоль */ console.log(`Исходный текст: ${text}`); /* Удаление лишних пробелов */ text = text.replace(/\s+/g, ' '); /* Исправление старой разметки (актуально для 3-ого уровня) */ text = text.replace(/NOIOSE/gi, 'NOISE'); text = text.replace(/\(фио: Марвин\)/gi, '(ибот: Марвин)'); text = text.replace(/\(фио: Шмарвин\)/gi, '(ибот: Шмарвин)'); text = text.replace(/\(фио: Хуярвин\)/gi, '(ибот: Хуярвин)'); /* Расстановка пробелов */ text = text.replace(/\/\//gi, ' // '); text = text.replace(/ :/gi, ': '); text = text.replace(/:/gi, ': '); text = text.replace(/\(\s+/gi, '('); text = text.replace(/\s+\)/gi, ')'); text = text.replace(/\(\(/gi, '( ('); text = text.replace(/\)\)/gi, ') )'); text = text.replace(/ \./gi, '. '); text = text.replace(/\./gi, '. '); text = text.replace(/ ,/gi, ', '); text = text.replace(/,/gi, ', '); text = text.replace(/ !/gi, '! '); text = text.replace(/!/gi, '! '); text = text.replace(/ \?/gi, '? '); text = text.replace(/\?/gi, '? '); text = text.replace(/\)\./gi, ') .'); text = text.replace(/\)\?/gi, ') ?'); text = text.replace(/\),/gi, ') ,'); text = text.replace(/\)!/gi, ') !'); text = text.replace(/\)\(/gi, ') ('); text = text.replace(/=\./gi, '= .'); text = text.replace(/=\?/gi, '= ?'); text = text.replace(/=,/gi, '= ,'); text = text.replace(/=!/gi, '= !'); text = text.replace(/=\)/gi, '= )'); text = text.replace(/\)/gi, ') '); text = text.replace(/\)(.+?)\(/gi, ') $1 ('); text = text.replace(/\s+/g, ' '); text = text.trim(); $('#data').val(text); });