Больше шуток

This commit is contained in:
2023-03-27 16:51:45 +04:00
parent f90f0c542b
commit f9cbc4461d
8 changed files with 166 additions and 189 deletions
+11 -11
View File
@@ -6,6 +6,16 @@ import { Joke, JokeSettings } from "./joke";
* @author Kozhilya
*/
export class AprilFoolsJokeClass {
/**
* Проверка вероятности
*
* @param {number} chance Вероятность срабатывания
* @returns {boolean} Флаг срабатывания (true - сработало)
*/
static check(chance: number): boolean {
return Math.random() < 0.01 * chance;
}
/**
* Добавление шутки
*
@@ -29,16 +39,6 @@ export class AprilFoolsJokeClass {
}
}
/**
* Проверка вероятности
*
* @param {number} chance Вероятность срабатывания
* @returns {boolean} Флаг срабатывания (true - сработало)
*/
check(chance: number): boolean {
return Math.random() < 0.01 * chance;
}
/**
* Запуск шутки
*
@@ -51,7 +51,7 @@ export class AprilFoolsJokeClass {
const joke = this.jokes[id];
if (!forced && !this.check(joke.settings.chance)) {
if (!forced && !AprilFoolsJokeClass.check(joke.settings.chance)) {
return;
}
+60
View File
@@ -0,0 +1,60 @@
import { Joke, JokeSettings, StopableJoke } from "../joke";
import $ from "jquery";
import { AprilFoolsJokeClass } from "../handler";
/**
* **Зеркало**
*
* Элементы форума отражаются (по крайней мере, пытаются)
*
* @author Kozhilya
*/
export class CarnivalJoke extends Joke {
settings: CarnivalJokeSettings;
start(): void {
$(this.settings.selector).each((_, elem) => {
const filters: string[] = [];
for (const entry of Object.entries(this.settings.variants)) {
if (!AprilFoolsJokeClass.check(this.settings.variant_chance)) {
continue;
}
filters.push(entry[0].replace('{0}', Math.round(Math.random() * entry[1]).toString()));
}
if (filters.length > 0) {
$(elem).css('filter', filters.join(' '));
}
});
}
}
export class CarnivalJokeSettings implements JokeSettings {
chance: number = 30;
/**
* Селектор всех элементов, которые будут трястись
*/
selector: string = 'img[src*="/avatars/"]';
/**
* Вероятность применения фильтра
*/
variant_chance: number = 20;
/**
* Список фильтров и диапозона случайных параметров
*/
variants: CarnivalJokeFilters = {
'sepia({0}%)': 100,
'saturate({0}%)': 100,
'hue-rotate({0}deg)': 360,
'invert({0}%)': 100,
}
}
export interface CarnivalJokeFilters {
[key: string]: number;
}
+35
View File
@@ -0,0 +1,35 @@
import { Joke, JokeSettings, StopableJoke } from "../joke";
import $ from "jquery";
/**
* **Ад гуманитария**
*
* Все "тся" заменяются на "ться", а все "ться" на "тся".
*
* @author Kozhilya
*/
export class CrazyLettersJoke extends Joke {
settings: CrazyLettersJokeSettings;
start(): void {
$(this.settings.selector).each((_, elem) => {
let text = $(this).text();
let result = '';
for (let i = 0; i < text.length; i++) {
result += text[i][(i % 2) ? 'toLowerCase' : 'toUpperCase']();
}
$(this).text(result);
});
}
}
export class CrazyLettersJokeSettings implements JokeSettings {
chance: number = 20;
/**
* Селектор всех элементов, которые будут затронуты
*/
selector: string = '.pa-author a';
}
+30
View File
@@ -0,0 +1,30 @@
import { Joke, JokeSettings, StopableJoke } from "../joke";
import $ from "jquery";
/**
* **Ад гуманитария**
*
* Все "тся" заменяются на "ться", а все "ться" на "тся".
*
* @author Kozhilya
*/
export class HumanitarianHellJoke extends Joke {
settings: HumanitarianHellJokeSettings;
start(): void {
$(this.settings.selector).each(function () {
$(this).html($(this).html().replace(/(ть?ся)/g, function (fnd) {
return (fnd.indexOf('ь') > 0) ? 'тся' : 'ться';
}));
});
}
}
export class HumanitarianHellJokeSettings implements JokeSettings {
chance: number = 20;
/**
* Селектор всех элементов, которые будут затронуты
*/
selector: string = '.post-content';
}
+25
View File
@@ -0,0 +1,25 @@
import { Joke, JokeSettings, StopableJoke } from "../joke";
import $ from "jquery";
/**
* **Зеркало**
*
* Элементы форума отражаются (по крайней мере, пытаются)
*
* @author Kozhilya
*/
export class MirrorJoke extends Joke {
settings: MirrorJokeSettings;
start(): void {
$('.post, .post h3, .post-links, .post-author, .post-content')
.css('transform', 'scaleX(-1)').css('-moz-transform', 'scaleX(-1)').css('-moz-transform', 'scaleX(-1)').css('filter', 'FlipH').css('-ms-filter', '"FlipH"');
$('#pun-title #title-logo').animate('')
$('.post-links, .post-links ul, .post h3 span').css('margin-left', '0');
$('.post h3 span').css('margin-right', '25em');
}
}
export class MirrorJokeSettings implements JokeSettings {
chance: number = 30;
}
+3 -3
View File
@@ -1,7 +1,8 @@
import { Joke, JokeSettings, StopableJoke } from "../joke";
import $ from "jquery";
/**
* Форумо-трясение
* **Форумо-трясение**
*
* Страница форума начинает трястись
*
@@ -17,7 +18,6 @@ export class ShakeJoke extends StopableJoke {
private data_name: string = 'april-fools-shake';
rand(a: number): number {
return a + this.settings.force * (Math.random() * 2 - 1);
}
@@ -85,6 +85,6 @@ export class ShakeJokeSettings implements JokeSettings {
force: number = 0.5;
}
interface ShakeJokeMargin {
export interface ShakeJokeMargin {
[key: string]: number;
}