Advertisement
Guest User

Untitled

a guest
Feb 3rd, 2024
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 17.95 KB | Cryptocurrency | 0 0
  1. // ==UserScript==
  2. // @name         Генератор хуйни
  3. // @namespace    Генератор_хуйни
  4. // @version      1.3
  5. // @description  Создай хуйню!
  6. // @author       Анонимус
  7. // @include      *://2ch.*
  8. // @icon         https://i.imgur.com/XK5x1Zr.png
  9. // @grant        GM_getValue
  10. // @grant        GM_setValue
  11. // @grant        GM_addStyle
  12. // ==/UserScript==
  13.  
  14. /*
  15.     КАК УСТАНОВИТЬ:
  16.  
  17.     ЗАХОДИМ СЮДА https://www.tampermonkey.net/ ИЛИ СЮДА https://violentmonkey.github.io/
  18.     УСТАНАВЛИВАЕМ РАСШИРЕНИЕ С ОДНОГО ИЗ ЭТИХ САЙТОВ
  19.     НАЖИМАЕМ НА ИКОНКУ РАСШИРЕНИЯ И "Создать новый скрипт"
  20.     КОПИРУЕМ ВЕСЬ ТЕКСТ ОТСЮДА (ГАЙД ЗАКОММЕНТИРОВАН, ЕГО ТОЖЕ МОЖНО СКОПИРОВАТЬ)
  21.     ВСТАВЛЯЕМ ЕГО В ОГРОМНОЕ ПОЛЕ ВВОДА
  22.     НАЖИМАЕМ CTRL+S
  23.     ПЕРЕЗАГРУЖАЕМ СТРАНИЦУ С ДВАЧЕМ, ЕСЛИ ОНА БЫЛА ОТКРЫТА ДО ЭТОГО
  24.     ЖМЁМ КНОПКУ "Насрать хуйни" ПОД ПОЛЕМ ДЛЯ НАПИСАНИЯ ПОСТА
  25.     PROFIT
  26.  
  27.     КАК УСТАНОВИТЬ НОВУЮ ВЕРСИЮ:
  28.     НАЖИМАЕМ НА ИКОНКУ РАСШИРЕНИЯ И "Панель управления"
  29.     НАЖИМАЕМ НА "Генератор хуйни"
  30.     В ОГРОМНОМ ПОЛЕ ВВОДА ЗАМЕНЯЕМ СТАРЫЙ КОД НА НОВЫЙ
  31.     НАЖИМАЕМ CTRL+S
  32.     PROFIT
  33. */
  34.  
  35. const storage = GM_getValue('storage') ?? {};
  36.  
  37. const elementHtml = `
  38.     <label style='user-select: none;'>
  39.        <a id='hg-generate'><strong>Насрать хуйни</strong></a>
  40.        <a id='hg-config-button'><strong>[настройки]</strong></a>
  41.  
  42.        <div id='hg-config-wrapper' style='display: none;'>
  43.            <div id='hg-config'>
  44.                <label><!-- Костыль-заглушка, нажатие на верхние ссылки триггерит ближайший инпут. --><input style='display: none;'/></label>
  45.                <label>Длина слова <input id='hg-word-min' value='5' class='input'/>-<input id='hg-word-max' value='10' class='input'/></label>
  46.                <label>Длина предложения <input id='hg-sentence-min' value='5' class='input'/>-<input id='hg-sentence-max' value='10' class='input'/></label>
  47.                <label>Длина параграфа <input id='hg-paragraph-min' value='5' class='input'/>-<input id='hg-paragraph-max' value='10' class='input'/></label>
  48.                <label>Знаки припинания <select id='hg-punctuation' value='5'><option>Точки</option><option>Все</option><option>Нет</option></select></label>
  49.                <label>Мелкобуквенность <input id='hg-melkobukva' type='checkbox'/></label>
  50.                <label>Многострочность <input id='hg-mnogostrok' type='checkbox'/></label>
  51.                <label>Новая строка после генерации <input id='hg-newline' type='checkbox'/></label>
  52.                <br/>
  53.                <label>Генераторы аватарок: <a href='https://make.girls.moe/' target='_blank'>говниме</a> <a href='https://thisponydoesnotexist.net/' target='_blank'>кони</a></label>
  54.            </div>
  55.        </div>
  56.     </label>
  57. `;
  58.  
  59. GM_addStyle(`
  60.     #hg-config > * {
  61.         margin: 2px 0;
  62.     }
  63.  
  64.     #hg-config {
  65.         display: flex;
  66.         flex-direction: column;
  67.     }
  68.  
  69.     #hg-config input:not([type]) {
  70.         max-width: 50px;
  71.     }
  72. `);
  73.  
  74. const element = document.createElement('div');
  75.  
  76. (function() {
  77.     'use strict';
  78.  
  79.     element.innerHTML = elementHtml;
  80.     const area = document.querySelector('form#postform .postarea');
  81.     area.parentNode.insertBefore(element, area.nextSibling.nextSibling.nextSibling);
  82.  
  83.     element.querySelector('#hg-generate').onclick = () => {
  84.         const cfg = buildConfig();
  85.         if (!cfg) return;
  86.         const text = paragraph(cfg);
  87.         for (const field of document.querySelectorAll('#shampoo')) field.value += text;
  88.     };
  89.  
  90.     const configWrapper = element.querySelector('#hg-config-wrapper');
  91.     element.querySelector('#hg-config-button').onclick = () => {
  92.         configWrapper.style.display = configWrapper.style.display ? '' : 'none';
  93.     };
  94.  
  95.     initInputStorageSync('hg-word-min');
  96.     initInputStorageSync('hg-word-max');
  97.     initInputStorageSync('hg-sentence-min');
  98.     initInputStorageSync('hg-sentence-max');
  99.     initInputStorageSync('hg-paragraph-min');
  100.     initInputStorageSync('hg-paragraph-max');
  101.  
  102.     initCheckboxStorageSync('hg-melkobukva');
  103.     initCheckboxStorageSync('hg-mnogostrok');
  104.     initCheckboxStorageSync('hg-newline');
  105.  
  106.     initSelectStorageSync('hg-punctuation');
  107. })();
  108.  
  109. function buildConfig() {
  110.     const cfg = {
  111.         wordLengthMin: parseInt(element.querySelector('#hg-word-min').value),
  112.         wordLengthMax: parseInt(element.querySelector('#hg-word-max').value),
  113.         sentenceLengthMin: parseInt(element.querySelector('#hg-sentence-min').value),
  114.         sentenceLengthMax: parseInt(element.querySelector('#hg-sentence-max').value),
  115.         paragraphLengthMin: parseInt(element.querySelector('#hg-paragraph-min').value),
  116.         paragraphLengthMax: parseInt(element.querySelector('#hg-paragraph-max').value),
  117.  
  118.         melkobukva: element.querySelector('#hg-melkobukva').checked,
  119.         mnogostrok: element.querySelector('#hg-mnogostrok').checked,
  120.         insertNewLine: element.querySelector('#hg-newline').checked,
  121.  
  122.         punctuation: element.querySelector('#hg-punctuation').selectedIndex,
  123.     };
  124.  
  125.     if (cfg.wordLengthMin == NaN || cfg.wordLengthMax == NaN ||
  126.         cfg.wordLengthMin < 1 ||
  127.         cfg.wordLengthMin > cfg.wordLengthMax) { alert('Неверная длина слова'); return; }
  128.  
  129.     if (cfg.sentenceLengthMin == NaN || cfg.sentenceLengthMax == NaN ||
  130.         cfg.sentenceLengthMin < 1 ||
  131.         cfg.sentenceLengthMin > cfg.sentenceLengthMax) { alert('Неверная длина предложения'); return; }
  132.  
  133.     if (cfg.paragraphLengthMin == NaN || cfg.paragraphLengthMax == NaN ||
  134.         cfg.paragraphLengthMin < 1 ||
  135.         cfg.paragraphLengthMin > cfg.paragraphLengthMax) { alert('Неверная длина параграфа'); return; }
  136.  
  137.     return cfg;
  138. }
  139.  
  140. function initInputStorageSync(id) {
  141.     const el = element.querySelector('#' + id);
  142.     const valueKey = id + '_value';
  143.     if (storage[valueKey] !== undefined) el.value = storage[valueKey];
  144.     el.oninput = () => {
  145.         storage[valueKey] = el.value;
  146.         saveStorage();
  147.     }
  148. }
  149.  
  150. function initCheckboxStorageSync(id) {
  151.     const el = element.querySelector('#' + id);
  152.     const valueKey = id + '_value';
  153.     if (storage[valueKey] !== undefined) el.checked = storage[valueKey];
  154.     el.onchange = () => {
  155.         storage[valueKey] = el.checked;
  156.         saveStorage();
  157.     }
  158. }
  159.  
  160. function initSelectStorageSync(id) {
  161.     const el = element.querySelector('#' + id);
  162.     const valueKey = id + '_value';
  163.     if (storage[valueKey] !== undefined) el.selectedIndex = storage[valueKey];
  164.     el.onchange = () => {
  165.         storage[valueKey] = el.selectedIndex;
  166.         saveStorage();
  167.     }
  168. }
  169.  
  170. function saveStorage() {
  171.     GM_setValue('storage', storage);
  172. }
  173.  
  174. function choice(chances) {
  175.     const roll = Math.random();
  176.     return chances.find(i => roll <= i[1])[0]
  177. }
  178.  
  179. function word(cfg) {
  180.     const lenght = cfg.wordLengthMin + Math.round(Math.random() * (cfg.wordLengthMax - cfg.wordLengthMin)) - 1;
  181.  
  182.     let letter = choice(chancesForFirstLetter);
  183.     let result = letter;
  184.  
  185.     for (let i = 0; i < lenght; i++) {
  186.         const nextLetter = choice(chances[letter]);
  187.         result += nextLetter;
  188.         letter = nextLetter;
  189.     }
  190.  
  191.     return result;
  192. }
  193.  
  194. function sentence(cfg) {
  195.     let result = Array.apply(null, Array(cfg.sentenceLengthMin + Math.round(Math.random() * (cfg.sentenceLengthMax - cfg.sentenceLengthMin)))).map(i => word(cfg)).join(' ');
  196.  
  197.     if (!cfg.melkobukva) result = result.charAt(0).toUpperCase() + result.slice(1);
  198.  
  199.     return result;
  200. }
  201.  
  202. function paragraph(cfg) {
  203.     const length = cfg.paragraphLengthMin + Math.round(Math.random() * (cfg.paragraphLengthMax - cfg.paragraphLengthMin));
  204.     let result = '';
  205.     for (let i = 0; i < length; i++) {
  206.         result += sentence(cfg);
  207.  
  208.         switch(cfg.punctuation) {
  209.             case 0:
  210.                 result += '. ';
  211.                 break;
  212.             case 1:
  213.                 result += choice(punctuationChances);
  214.                 break;
  215.             case 2:
  216.                 result += ' ';
  217.                 break;
  218.         }
  219.  
  220.         if (cfg.mnogostrok && i < length - 1) result += '\n';
  221.     }
  222.  
  223.     if (cfg.insertNewLine) result += '\n\n';
  224.     return result;
  225. }
  226.  
  227. // Шансы в формате {'буква': [('буква после', %шанс буквы% + %предыдущий шанс буквы%)]}
  228.  
  229. const chances = {
  230.     'а': [['б', 0.02535211], ['в', 0.090140834], ['г', 0.10985914], ['д', 0.12112674], ['е', 0.15211265], ['ж', 0.16901405], ['з', 0.23098586], ['и', 0.23661967], ['й', 0.24788727], ['к', 0.3042253], ['л', 0.3887323], ['м', 0.43661964], ['н', 0.5887323], ['п', 0.6197182], ['р', 0.6760562], ['с', 0.74929565], ['т', 0.8422534], ['у', 0.853521], ['ф', 0.8563379], ['х', 0.87323934], ['ц', 0.912676], ['ч', 0.93239427], ['ш', 0.94084495], ['щ', 0.94366187], ['ю', 0.96338016], ['я', 1], ],
  231.     'б': [['а', 0.084337346], ['е', 0.18072289], ['и', 0.22891566], ['к', 0.25301206], ['л', 0.3373494], ['н', 0.36144578], ['о', 0.57831323], ['р', 0.6385542], ['с', 0.68674695], ['у', 0.7831325], ['х', 0.7951807], ['щ', 0.8433734], ['ъ', 0.8554216], ['ы', 0.9638553], ['ю', 0.9879517], ['я', 1], ],
  232.     'в': [['а', 0.1965812], ['в', 0.20512821], ['е', 0.37606838], ['з', 0.3888889], ['и', 0.47008547], ['к', 0.47863248], ['л', 0.52136755], ['м', 0.5256411], ['н', 0.59401715], ['о', 0.78632486], ['р', 0.8034189], ['с', 0.8376069], ['т', 0.86752146], ['у', 0.880342], ['ш', 0.897436], ['ы', 1], ],
  233.     'г': [['а', 0.09782608], ['д', 0.11956521], ['е', 0.17391303], ['и', 0.27173913], ['л', 0.32608694], ['м', 0.3369565], ['н', 0.34782606], ['о', 0.8369564], ['р', 0.96739113], ['с', 0.9782607], ['у', 1], ],
  234.     'д': [['а', 0.16666663], ['в', 0.18939391], ['е', 0.4393938], ['ж', 0.44696954], ['и', 0.5757574], ['к', 0.58333313], ['л', 0.61363614], ['н', 0.712121], ['о', 0.81818163], ['п', 0.8257574], ['р', 0.84848464], ['с', 0.8712119], ['у', 0.9545452], ['х', 0.96212095], ['ы', 0.97727245], ['ь', 0.9848482], ['я', 1], ],
  235.     'е': [['а', 0.007481297], ['б', 0.009975063], ['в', 0.024937656], ['г', 0.057356607], ['д', 0.11471321], ['е', 0.12718204], ['ж', 0.13965087], ['з', 0.16708228], ['и', 0.17206982], ['й', 0.21446383], ['к', 0.2668329], ['л', 0.36907732], ['м', 0.436409], ['н', 0.640898], ['о', 0.65087306], ['п', 0.6558606], ['р', 0.73566115], ['с', 0.8628433], ['т', 0.93017495], ['ф', 0.9351625], ['х', 0.9576064], ['ц', 0.9601001], ['ч', 0.98753154], ['ш', 0.9950128], ['я', 1], ],
  236.     'ж': [['а', 0.125], ['д', 0.40000004], ['е', 0.62500006], ['и', 0.8000001], ['н', 1], ],
  237.     'з': [['а', 0.20792076], ['б', 0.23762372], ['в', 0.31683165], ['г', 0.3465346], ['д', 0.4653465], ['ж', 0.47524747], ['и', 0.51485145], ['к', 0.5346534], ['л', 0.5544554], ['м', 0.60396034], ['н', 0.78217816], ['о', 0.8514851], ['р', 0.88118804], ['у', 0.930693], ['ы', 0.96039593], ['ь', 0.9702969], ['я', 1], ],
  238.     'и': [['а', 0.010025063], ['б', 0.01754386], ['в', 0.07268172], ['г', 0.08270678], ['д', 0.097744375], ['е', 0.21303257], ['ж', 0.2180451], ['з', 0.2706767], ['и', 0.31328323], ['й', 0.36591482], ['к', 0.39097747], ['л', 0.41604012], ['м', 0.4761905], ['н', 0.56390977], ['о', 0.5764411], ['п', 0.5814536], ['р', 0.63408524], ['с', 0.69172937], ['т', 0.7694236], ['у', 0.7744361], ['ф', 0.7794486], ['х', 0.79949874], ['ц', 0.8070175], ['ч', 0.87969923], ['ш', 0.88471174], ['ю', 0.9072681], ['я', 1], ],
  239.     'й': [['д', 0.05263158], ['м', 0.10526316], ['н', 0.42105263], ['р', 0.5263158], ['с', 0.68421054], ['т', 0.84210527], ['ч', 0.8947368], ['ш', 1], ],
  240.     'к': [['а', 0.15189874], ['в', 0.15822786], ['е', 0.1772152], ['и', 0.3417722], ['л', 0.386076], ['м', 0.39240512], ['н', 0.41139245], ['о', 0.70886093], ['р', 0.7531647], ['с', 0.79113936], ['т', 0.9177216], ['у', 0.993671], ['ц', 1], ],
  241.     'л': [['а', 0.100529104], ['г', 0.10582011], ['е', 0.28042325], ['и', 0.4656084], ['л', 0.50264543], ['н', 0.52380943], ['о', 0.69312155], ['с', 0.69841254], ['у', 0.73015857], ['ь', 0.9153437], ['ю', 0.9365077], ['я', 1], ],
  242.     'м': [['а', 0.16129029], ['в', 0.1693548], ['е', 0.37903214], ['и', 0.5403224], ['л', 0.54838693], ['м', 0.56451595], ['н', 0.61290306], ['о', 0.8306449], ['п', 0.862903], ['у', 0.9193546], ['ы', 1], ],
  243.     'н': [['а', 0.13157901], ['г', 0.13684218], ['д', 0.13947375], ['е', 0.22368431], ['и', 0.47105262], ['к', 0.47631577], ['н', 0.56842107], ['о', 0.77368414], ['р', 0.7789473], ['с', 0.80789465], ['т', 0.85789466], ['у', 0.8736841], ['ф', 0.8763157], ['ц', 0.8789473], ['ч', 0.8815789], ['ы', 0.95526314], ['ь', 0.9605263], ['я', 1], ],
  244.     'о': [['б', 0.060194183], ['в', 0.18834953], ['г', 0.27184469], ['д', 0.33980584], ['е', 0.36116508], ['ж', 0.38834953], ['з', 0.44466022], ['и', 0.4524272], ['й', 0.49902916], ['к', 0.5087379], ['л', 0.5572816], ['м', 0.64077675], ['н', 0.6912622], ['о', 0.7048544], ['п', 0.71650493], ['р', 0.7766991], ['с', 0.89902925], ['т', 0.9650487], ['ф', 0.9669904], ['х', 0.9708739], ['ц', 0.9825244], ['ч', 0.9864079], ['ш', 0.99029136], ['щ', 0.99417484], ['я', 1], ],
  245.     'п': [['а', 0.024], ['е', 0.15200001], ['и', 0.16000001], ['л', 0.19200002], ['н', 0.20000002], ['о', 0.5279999], ['п', 0.54399985], ['р', 0.9279996], ['у', 0.9599996], ['ц', 0.96799964], ['ь', 0.9919996], ['я', 1], ],
  246.     'р': [['а', 0.2835819], ['в', 0.29477593], ['г', 0.30596995], ['д', 0.3097013], ['е', 0.45149228], ['ж', 0.4626863], ['з', 0.46641764], ['и', 0.60820866], ['к', 0.61194], ['м', 0.6194027], ['н', 0.64179075], ['о', 0.8694025], ['с', 0.9104473], ['т', 0.92537266], ['у', 0.9477607], ['ч', 0.9514921], ['ш', 0.95895475], ['ы', 0.9813428], ['ь', 0.98507416], ['я', 1], ],
  247.     'с': [['а', 0.030303031], ['б', 0.033333335], ['в', 0.04848485], ['д', 0.051515155], ['е', 0.09696971], ['и', 0.14242426], ['к', 0.26969695], ['л', 0.3363636], ['м', 0.3393939], ['н', 0.3515151], ['о', 0.46969688], ['п', 0.52727264], ['р', 0.53333324], ['с', 0.5878787], ['т', 0.87272704], ['у', 0.90303004], ['х', 0.92121184], ['ц', 0.92424214], ['ч', 0.92727244], ['ш', 0.93636334], ['ь', 0.94545424], ['я', 1], ],
  248.     'т': [['а', 0.105263196], ['в', 0.21981433], ['е', 0.36532518], ['и', 0.5479877], ['к', 0.5603716], ['л', 0.56965953], ['м', 0.5758515], ['н', 0.6160992], ['о', 0.7368423], ['р', 0.80185777], ['с', 0.8359135], ['у', 0.8730652], ['ы', 0.88854504], ['ь', 0.9969042], ['я', 1], ],
  249.     'у': [['а', 0.086538464], ['б', 0.09615385], ['г', 0.13461539], ['д', 0.22115386], ['е', 0.24038462], ['ж', 0.27884617], ['к', 0.28846157], ['л', 0.3269231], ['м', 0.37500003], ['н', 0.41346157], ['п', 0.4615385], ['р', 0.53846157], ['с', 0.6057693], ['т', 0.6923077], ['х', 0.7115385], ['ч', 0.82692313], ['ш', 0.8365385], ['щ', 0.91346157], ['ю', 1], ],
  250.     'ф': [['а', 0.23076925], ['и', 0.61538464], ['л', 0.7692308], ['о', 0.84615386], ['с', 0.9230769], ['у', 1], ],
  251.     'х': [['а', 0.10344827], ['е', 0.20689654], ['м', 0.2413793], ['н', 0.44827586], ['о', 0.89655167], ['р', 0.96551716], ['с', 1], ],
  252.     'ц': [['а', 0.032258064], ['е', 0.29032257], ['и', 1], ],
  253.     'ч': [['а', 0.15116279], ['е', 0.75581414], ['и', 0.8604653], ['н', 0.98837227], ['т', 1], ],
  254.     'ш': [['а', 0.03448276], ['е', 0.34482756], ['и', 0.7586206], ['к', 0.8275861], ['л', 0.9310344], ['н', 1], ],
  255.     'щ': [['а', 0.11538462], ['е', 0.61538464], ['и', 0.8846154], ['н', 0.923077], ['р', 0.96153855], ['ь', 1], ],
  256.     'ъ': [['е', 1], ],
  257.     'ы': [['в', 0.064935066], ['д', 0.077922076], ['е', 0.24675325], ['й', 0.37662336], ['к', 0.4025974], ['л', 0.45454544], ['м', 0.5324675], ['п', 0.5454545], ['р', 0.58441556], ['с', 0.6363636], ['т', 0.66233766], ['х', 0.90909094], ['ч', 0.935065], ['ш', 1], ],
  258.     'ь': [['е', 0.040816326], ['з', 0.08163265], ['к', 0.14285713], ['н', 0.5918367], ['с', 0.67346936], ['т', 0.75510204], ['ч', 0.7755102], ['ш', 0.8163265], ['ю', 0.9795918], ['я', 1], ],
  259.     'э': [['к', 0.3529412], ['л', 0.4117647], ['с', 0.47058824], ['т', 1], ],
  260.     'ю': [['б', 0.03448276], ['д', 0.06896552], ['р', 0.13793103], ['т', 0.51724136], ['ч', 0.62068963], ['щ', 0.96551716], ['э', 1], ],
  261.     'я': [['в', 0.04347826], ['д', 0.108695656], ['е', 0.21739131], ['м', 0.2826087], ['н', 0.32608694], ['с', 0.34782606], ['т', 0.7391304], ['х', 0.8260869], ['ш', 0.847826], ['ю', 0.95652163], ['я', 1], ],
  262.     'ё': [['м', 0.14285715], ['н', 0.42857146], ['с', 0.5714286], ['т', 1], ],
  263. }
  264.  
  265.  
  266. const chancesForFirstLetter = [
  267.     ['а', 0.018950438],
  268.     ['б', 0.06268221],
  269.     ['в', 0.15160352],
  270.     ['г', 0.17346941],
  271.     ['д', 0.20991257],
  272.     ['е', 0.2230321],
  273.     ['ж', 0.23032074],
  274.     ['з', 0.25510207],
  275.     ['и', 0.31195337],
  276.     ['к', 0.3644315],
  277.     ['л', 0.37317786],
  278.     ['м', 0.41253644],
  279.     ['н', 0.47667637],
  280.     ['о', 0.54373175],
  281.     ['п', 0.65451896],
  282.     ['р', 0.71865886],
  283.     ['с', 0.8556851],
  284.     ['т', 0.9008746],
  285.     ['у', 0.92565596],
  286.     ['ф', 0.93586004],
  287.     ['х', 0.9431487],
  288.     ['ц', 0.94752187],
  289.     ['ч', 0.9723032],
  290.     ['ш', 0.97376096],
  291.     ['э', 0.99708456],
  292.     ['я', 1],
  293. ]
  294.  
  295. const punctuationChances = [
  296.     ['. ', 0.5],
  297.     ['! ', 0.75],
  298.     ['? ', 1],
  299. ];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement