diff --git a/.gitignore b/.gitignore index 6319017..0fef4b9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ node_modules -build*.sh \ No newline at end of file +*.sh diff --git a/JOKES.md b/JOKES.md index 01ebdbb..1f7c7e4 100644 --- a/JOKES.md +++ b/JOKES.md @@ -37,4 +37,12 @@ Настройки: * `chance` - Вероятность срабатывания в процентах (по умолчанию: `20%`) -* `selector` - Селектор всех элементов, которые будут затронуты: `.pa-author a`) \ No newline at end of file +* `selector` - Селектор всех элементов, которые будут затронуты: `.pa-author a`) + +## `letter_chaos` - Буквенный хаос +Все буквы в словах, кроме первой и последней, перемешены. + +Настройки: +* `chance` - Вероятность срабатывания в процентах (по умолчанию: `20%`) +* `selector` - Селектор всех элементов, которые будут затронуты: `.post-content`) +* `shuffle_chance` - Вероятность того, что буквы будут перемешаны (по умолчанию: `50%`) \ No newline at end of file diff --git a/dist/april-fools.js b/dist/april-fools.js index 1e79e37..42f9ea5 100644 --- a/dist/april-fools.js +++ b/dist/april-fools.js @@ -36,7 +36,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac \*******************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"CarnivalJoke\": () => (/* binding */ CarnivalJoke),\n/* harmony export */ \"CarnivalJokeSettings\": () => (/* binding */ CarnivalJokeSettings)\n/* harmony export */ });\n/* harmony import */ var _joke__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../joke */ \"./src/joke.ts\");\n/* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! jquery */ \"jquery\");\n/* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(jquery__WEBPACK_IMPORTED_MODULE_1__);\n/* harmony import */ var _handler__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../handler */ \"./src/handler.ts\");\nvar __extends = (undefined && undefined.__extends) || (function () {\n var extendStatics = function (d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\n return extendStatics(d, b);\n };\n return function (d, b) {\n if (typeof b !== \"function\" && b !== null)\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\n\n\n\n/**\n * **Карнавал**\n *\n * Аватарки приобретают интересные цвета\n *\n * @author Kozhilya\n */\nvar CarnivalJoke = /** @class */ (function (_super) {\n __extends(CarnivalJoke, _super);\n function CarnivalJoke() {\n var _this = _super !== null && _super.apply(this, arguments) || this;\n _this.id = 'carnival';\n _this.settings = new CarnivalJokeSettings;\n return _this;\n }\n CarnivalJoke.prototype.start = function () {\n var _this = this;\n jquery__WEBPACK_IMPORTED_MODULE_1___default()(this.settings.selector).each(function (_, elem) {\n var filters = [];\n for (var _i = 0, _a = Object.entries(_this.settings.variants); _i < _a.length; _i++) {\n var entry = _a[_i];\n if (!_handler__WEBPACK_IMPORTED_MODULE_2__.AprilFoolsJokeClass.check(_this.settings.variant_chance)) {\n continue;\n }\n filters.push(entry[0].replace('{0}', Math.round(Math.random() * entry[1]).toString()));\n }\n if (filters.length > 0) {\n jquery__WEBPACK_IMPORTED_MODULE_1___default()(elem).css({ 'filter': filters.join(' ') });\n }\n });\n };\n return CarnivalJoke;\n}(_joke__WEBPACK_IMPORTED_MODULE_0__.Joke));\n\nvar CarnivalJokeSettings = /** @class */ (function () {\n function CarnivalJokeSettings() {\n this.chance = 30;\n /**\n * Селектор всех элементов, которые будут трястись\n */\n this.selector = 'img[src*=\"/avatars/\"]';\n /**\n * Вероятность применения фильтра\n */\n this.variant_chance = 20;\n /**\n * Список фильтров и диапозона случайных параметров\n */\n this.variants = {\n 'sepia({0}%)': 100,\n 'saturate({0}%)': 100,\n 'hue-rotate({0}deg)': 360,\n 'invert({0}%)': 100,\n };\n }\n return CarnivalJokeSettings;\n}());\n\n\n\n//# sourceURL=webpack://mybb-april-fools/./src/jokes/carnival.ts?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"CarnivalJoke\": () => (/* binding */ CarnivalJoke),\n/* harmony export */ \"CarnivalJokeSettings\": () => (/* binding */ CarnivalJokeSettings)\n/* harmony export */ });\n/* harmony import */ var _joke__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../joke */ \"./src/joke.ts\");\n/* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! jquery */ \"jquery\");\n/* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(jquery__WEBPACK_IMPORTED_MODULE_1__);\n/* harmony import */ var _handler__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../handler */ \"./src/handler.ts\");\nvar __extends = (undefined && undefined.__extends) || (function () {\n var extendStatics = function (d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\n return extendStatics(d, b);\n };\n return function (d, b) {\n if (typeof b !== \"function\" && b !== null)\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\n\n\n\n/**\n * **Карнавал**\n *\n * Аватарки приобретают интересные цвета\n *\n * @author Kozhilya\n */\nvar CarnivalJoke = /** @class */ (function (_super) {\n __extends(CarnivalJoke, _super);\n function CarnivalJoke() {\n var _this = _super !== null && _super.apply(this, arguments) || this;\n _this.id = 'carnival';\n _this.settings = new CarnivalJokeSettings;\n return _this;\n }\n CarnivalJoke.prototype.start = function () {\n var _this = this;\n jquery__WEBPACK_IMPORTED_MODULE_1___default()(this.settings.selector).each(function (_, elem) {\n var filters = [];\n for (var _i = 0, _a = Object.entries(_this.settings.variants); _i < _a.length; _i++) {\n var entry = _a[_i];\n if (!_handler__WEBPACK_IMPORTED_MODULE_2__.AprilFoolsJokeClass.check(_this.settings.variant_chance)) {\n continue;\n }\n filters.push(entry[0].replace('{0}', Math.round(Math.random() * entry[1]).toString()));\n }\n if (filters.length > 0) {\n jquery__WEBPACK_IMPORTED_MODULE_1___default()(elem).css({ 'filter': filters.join(' ') });\n }\n });\n };\n return CarnivalJoke;\n}(_joke__WEBPACK_IMPORTED_MODULE_0__.Joke));\n\nvar CarnivalJokeSettings = /** @class */ (function () {\n function CarnivalJokeSettings() {\n this.chance = 30;\n /**\n * Селектор всех элементов, которые будут перекрашены\n */\n this.selector = 'img[src*=\"/avatars/\"]';\n /**\n * Вероятность применения некоторого фильтра\n */\n this.variant_chance = 20;\n /**\n * Список фильтров и диапозона случайных параметров\n */\n this.variants = {\n 'sepia({0}%)': 100,\n 'saturate({0}%)': 100,\n 'hue-rotate({0}deg)': 360,\n 'invert({0}%)': 100,\n };\n }\n return CarnivalJokeSettings;\n}());\n\n\n\n//# sourceURL=webpack://mybb-april-fools/./src/jokes/carnival.ts?"); /***/ }), @@ -46,7 +46,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac \************************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"CrazyLettersJoke\": () => (/* binding */ CrazyLettersJoke),\n/* harmony export */ \"CrazyLettersJokeSettings\": () => (/* binding */ CrazyLettersJokeSettings)\n/* harmony export */ });\n/* harmony import */ var _joke__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../joke */ \"./src/joke.ts\");\n/* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! jquery */ \"jquery\");\n/* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(jquery__WEBPACK_IMPORTED_MODULE_1__);\nvar __extends = (undefined && undefined.__extends) || (function () {\n var extendStatics = function (d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\n return extendStatics(d, b);\n };\n return function (d, b) {\n if (typeof b !== \"function\" && b !== null)\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\n\n\n/**\n * **Ад гуманитария**\n *\n * Все \"тся\" заменяются на \"ться\", а все \"ться\" на \"тся\".\n *\n * @author Kozhilya\n */\nvar CrazyLettersJoke = /** @class */ (function (_super) {\n __extends(CrazyLettersJoke, _super);\n function CrazyLettersJoke() {\n var _this = _super !== null && _super.apply(this, arguments) || this;\n _this.id = 'crazy_letters';\n _this.settings = new CrazyLettersJokeSettings;\n return _this;\n }\n CrazyLettersJoke.prototype.start = function () {\n var _this = this;\n jquery__WEBPACK_IMPORTED_MODULE_1___default()(this.settings.selector).each(function (_, elem) {\n var text = jquery__WEBPACK_IMPORTED_MODULE_1___default()(_this).text();\n var result = '';\n for (var i = 0; i < text.length; i++) {\n result += text[i][(i % 2) ? 'toLowerCase' : 'toUpperCase']();\n }\n jquery__WEBPACK_IMPORTED_MODULE_1___default()(_this).text(result);\n });\n };\n return CrazyLettersJoke;\n}(_joke__WEBPACK_IMPORTED_MODULE_0__.Joke));\n\nvar CrazyLettersJokeSettings = /** @class */ (function () {\n function CrazyLettersJokeSettings() {\n this.chance = 20;\n /**\n * Селектор всех элементов, которые будут затронуты\n */\n this.selector = '.pa-author a';\n }\n return CrazyLettersJokeSettings;\n}());\n\n\n\n//# sourceURL=webpack://mybb-april-fools/./src/jokes/crazy_letters.ts?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"CrazyLettersJoke\": () => (/* binding */ CrazyLettersJoke),\n/* harmony export */ \"CrazyLettersJokeSettings\": () => (/* binding */ CrazyLettersJokeSettings)\n/* harmony export */ });\n/* harmony import */ var _joke__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../joke */ \"./src/joke.ts\");\n/* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! jquery */ \"jquery\");\n/* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(jquery__WEBPACK_IMPORTED_MODULE_1__);\nvar __extends = (undefined && undefined.__extends) || (function () {\n var extendStatics = function (d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\n return extendStatics(d, b);\n };\n return function (d, b) {\n if (typeof b !== \"function\" && b !== null)\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\n\n\n/**\n * **Мама, Я сОшЛа С уМа!**\n *\n * иМеНа ЗаБоРчИкОм\n *\n * @author Kozhilya\n */\nvar CrazyLettersJoke = /** @class */ (function (_super) {\n __extends(CrazyLettersJoke, _super);\n function CrazyLettersJoke() {\n var _this = _super !== null && _super.apply(this, arguments) || this;\n _this.id = 'crazy_letters';\n _this.settings = new CrazyLettersJokeSettings;\n return _this;\n }\n CrazyLettersJoke.prototype.start = function () {\n var _this = this;\n jquery__WEBPACK_IMPORTED_MODULE_1___default()(this.settings.selector).each(function (_, elem) {\n var text = jquery__WEBPACK_IMPORTED_MODULE_1___default()(_this).text();\n var result = '';\n for (var i = 0; i < text.length; i++) {\n result += text[i][(i % 2) ? 'toLowerCase' : 'toUpperCase']();\n }\n jquery__WEBPACK_IMPORTED_MODULE_1___default()(_this).text(result);\n });\n };\n return CrazyLettersJoke;\n}(_joke__WEBPACK_IMPORTED_MODULE_0__.Joke));\n\nvar CrazyLettersJokeSettings = /** @class */ (function () {\n function CrazyLettersJokeSettings() {\n this.chance = 20;\n /**\n * Селектор всех элементов, которые будут затронуты\n */\n this.selector = '.pa-author a';\n }\n return CrazyLettersJokeSettings;\n}());\n\n\n\n//# sourceURL=webpack://mybb-april-fools/./src/jokes/crazy_letters.ts?"); /***/ }), @@ -56,7 +56,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac \****************************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"CrazyPunctuationJoke\": () => (/* binding */ CrazyPunctuationJoke),\n/* harmony export */ \"CrazyPunctuationJokeSettings\": () => (/* binding */ CrazyPunctuationJokeSettings)\n/* harmony export */ });\n/* harmony import */ var _joke__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../joke */ \"./src/joke.ts\");\n/* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! jquery */ \"jquery\");\n/* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(jquery__WEBPACK_IMPORTED_MODULE_1__);\nvar __extends = (undefined && undefined.__extends) || (function () {\n var extendStatics = function (d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\n return extendStatics(d, b);\n };\n return function (d, b) {\n if (typeof b !== \"function\" && b !== null)\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\n\n\n/**\n * **Бешеные запятые**\n *\n * Запятые после слов\n *\n * @author Kozhilya\n */\nvar CrazyPunctuationJoke = /** @class */ (function (_super) {\n __extends(CrazyPunctuationJoke, _super);\n function CrazyPunctuationJoke() {\n var _this = _super !== null && _super.apply(this, arguments) || this;\n _this.id = 'crazy_punctuation';\n _this.settings = new CrazyPunctuationJokeSettings;\n return _this;\n }\n CrazyPunctuationJoke.prototype.transform = function (text) {\n var newText = \"\";\n for (var i = 0; i < text.length; i++) {\n var currentChar = text[i];\n var nextChar = text[i + 1];\n if (this.settings.symbols.includes(currentChar)) {\n newText += currentChar;\n }\n else if (nextChar === \" \" || this.settings.symbols.includes(nextChar)) {\n newText += currentChar;\n }\n }\n return newText;\n };\n CrazyPunctuationJoke.prototype.process = function (node) {\n };\n CrazyPunctuationJoke.prototype.start = function () {\n var items = jquery__WEBPACK_IMPORTED_MODULE_1___default()(this.settings.selector).find('*').contents().filter(function (_, node) { return node.nodeType === Node.TEXT_NODE; });\n items.each(function (_, node) {\n console.log(node);\n });\n };\n return CrazyPunctuationJoke;\n}(_joke__WEBPACK_IMPORTED_MODULE_0__.Joke));\n\nvar CrazyPunctuationJokeSettings = /** @class */ (function () {\n function CrazyPunctuationJokeSettings() {\n this.chance = 20;\n /**\n * Селектор всех элементов, которые будут затронуты\n */\n this.selector = '.post-content';\n /**\n * Мигрирующие знаки\n */\n this.symbols = ',.;:?!-()[]{}\\'\"';\n }\n return CrazyPunctuationJokeSettings;\n}());\n\n\n\n//# sourceURL=webpack://mybb-april-fools/./src/jokes/crazy_punctuation.ts?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"CrazyPunctuationJoke\": () => (/* binding */ CrazyPunctuationJoke),\n/* harmony export */ \"CrazyPunctuationJokeSettings\": () => (/* binding */ CrazyPunctuationJokeSettings)\n/* harmony export */ });\n/* harmony import */ var _joke__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../joke */ \"./src/joke.ts\");\n/* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! jquery */ \"jquery\");\n/* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(jquery__WEBPACK_IMPORTED_MODULE_1__);\nvar __extends = (undefined && undefined.__extends) || (function () {\n var extendStatics = function (d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\n return extendStatics(d, b);\n };\n return function (d, b) {\n if (typeof b !== \"function\" && b !== null)\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\n\n\n/**\n * **Бешеные запятые**\n *\n * Запятые после слов\n *\n * @author Kozhilya\n */\nvar CrazyPunctuationJoke = /** @class */ (function (_super) {\n __extends(CrazyPunctuationJoke, _super);\n function CrazyPunctuationJoke() {\n var _this = _super !== null && _super.apply(this, arguments) || this;\n _this.id = 'crazy_punctuation';\n _this.settings = new CrazyPunctuationJokeSettings;\n _this.punctuationSymbols = null;\n return _this;\n }\n CrazyPunctuationJoke.prototype.shufflePunctuation = function (text) {\n var _this = this;\n if (this.punctuationSymbols === null) {\n this.punctuationSymbols = this.settings.symbols.split('');\n }\n var words = text.split(\" \");\n var shuffledWords = words.map(function (word) {\n var characters = word.split(\"\");\n // Filter out any non-punctuation characters\n var punctuation = characters.filter(function (char) { return _this.punctuationSymbols.includes(char); });\n // Shuffle the punctuation array\n var shuffledPunctuation = punctuation.sort(function () { return Math.random() - 0.5; });\n // Loop through each character in the word and replace punctuation with shuffled punctuation\n var index = 0;\n return characters.map(function (char) {\n if (_this.punctuationSymbols.includes(char)) {\n return shuffledPunctuation[index++];\n }\n return char;\n }).join(\"\");\n });\n // Join the shuffled words array into a single string with spaces\n return shuffledWords.join(\" \");\n };\n CrazyPunctuationJoke.prototype.start = function () {\n var _this = this;\n var items = jquery__WEBPACK_IMPORTED_MODULE_1___default()(this.settings.selector).find('*').contents().filter(function (_, node) { return node.nodeType === Node.TEXT_NODE; });\n items.each(function (_, node) {\n node.textContent = _this.shufflePunctuation(node.textContent);\n });\n };\n return CrazyPunctuationJoke;\n}(_joke__WEBPACK_IMPORTED_MODULE_0__.Joke));\n\nvar CrazyPunctuationJokeSettings = /** @class */ (function () {\n function CrazyPunctuationJokeSettings() {\n this.chance = 20;\n /**\n * Селектор всех элементов, которые будут затронуты\n */\n this.selector = '.post-content p';\n /**\n * Мигрирующие знаки\n */\n this.symbols = ',.;:?!-()[]{}\\'\"';\n }\n return CrazyPunctuationJokeSettings;\n}());\n\n\n\n//# sourceURL=webpack://mybb-april-fools/./src/jokes/crazy_punctuation.ts?"); /***/ }), @@ -66,7 +66,17 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac \****************************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"HumanitarianHellJoke\": () => (/* binding */ HumanitarianHellJoke),\n/* harmony export */ \"HumanitarianHellJokeSettings\": () => (/* binding */ HumanitarianHellJokeSettings)\n/* harmony export */ });\n/* harmony import */ var _joke__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../joke */ \"./src/joke.ts\");\n/* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! jquery */ \"jquery\");\n/* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(jquery__WEBPACK_IMPORTED_MODULE_1__);\nvar __extends = (undefined && undefined.__extends) || (function () {\n var extendStatics = function (d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\n return extendStatics(d, b);\n };\n return function (d, b) {\n if (typeof b !== \"function\" && b !== null)\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\n\n\n/**\n * **Ад гуманитария**\n *\n * Все \"тся\" заменяются на \"ться\", а все \"ться\" на \"тся\".\n *\n * @author Kozhilya\n */\nvar HumanitarianHellJoke = /** @class */ (function (_super) {\n __extends(HumanitarianHellJoke, _super);\n function HumanitarianHellJoke() {\n var _this = _super !== null && _super.apply(this, arguments) || this;\n _this.id = 'humanitarian_hell';\n _this.settings = new HumanitarianHellJokeSettings;\n return _this;\n }\n HumanitarianHellJoke.prototype.start = function () {\n jquery__WEBPACK_IMPORTED_MODULE_1___default()(this.settings.selector).each(function () {\n jquery__WEBPACK_IMPORTED_MODULE_1___default()(this).html(jquery__WEBPACK_IMPORTED_MODULE_1___default()(this).html().replace(/(ть?ся)/g, function (fnd) {\n return (fnd.indexOf('ь') > 0) ? 'тся' : 'ться';\n }));\n });\n };\n return HumanitarianHellJoke;\n}(_joke__WEBPACK_IMPORTED_MODULE_0__.Joke));\n\nvar HumanitarianHellJokeSettings = /** @class */ (function () {\n function HumanitarianHellJokeSettings() {\n this.chance = 20;\n /**\n * Селектор всех элементов, которые будут затронуты\n */\n this.selector = '.post-content';\n }\n return HumanitarianHellJokeSettings;\n}());\n\n\n\n//# sourceURL=webpack://mybb-april-fools/./src/jokes/humanitarian_hell.ts?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"HumanitarianHellJoke\": () => (/* binding */ HumanitarianHellJoke),\n/* harmony export */ \"HumanitarianHellJokeSettings\": () => (/* binding */ HumanitarianHellJokeSettings)\n/* harmony export */ });\n/* harmony import */ var _joke__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../joke */ \"./src/joke.ts\");\n/* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! jquery */ \"jquery\");\n/* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(jquery__WEBPACK_IMPORTED_MODULE_1__);\nvar __extends = (undefined && undefined.__extends) || (function () {\n var extendStatics = function (d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\n return extendStatics(d, b);\n };\n return function (d, b) {\n if (typeof b !== \"function\" && b !== null)\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\n\n\n/**\n * **Ад гуманитария**\n *\n * Все \"тся\" заменяются на \"ться\", а все \"ться\" на \"тся\"\n *\n * @author Kozhilya\n */\nvar HumanitarianHellJoke = /** @class */ (function (_super) {\n __extends(HumanitarianHellJoke, _super);\n function HumanitarianHellJoke() {\n var _this = _super !== null && _super.apply(this, arguments) || this;\n _this.id = 'humanitarian_hell';\n _this.settings = new HumanitarianHellJokeSettings;\n return _this;\n }\n HumanitarianHellJoke.prototype.start = function () {\n jquery__WEBPACK_IMPORTED_MODULE_1___default()(this.settings.selector).each(function () {\n jquery__WEBPACK_IMPORTED_MODULE_1___default()(this).html(jquery__WEBPACK_IMPORTED_MODULE_1___default()(this).html().replace(/(ть?ся)/g, function (fnd) {\n return (fnd.indexOf('ь') > 0) ? 'тся' : 'ться';\n }));\n });\n };\n return HumanitarianHellJoke;\n}(_joke__WEBPACK_IMPORTED_MODULE_0__.Joke));\n\nvar HumanitarianHellJokeSettings = /** @class */ (function () {\n function HumanitarianHellJokeSettings() {\n this.chance = 20;\n /**\n * Селектор всех элементов, которые будут затронуты\n */\n this.selector = '.post-content';\n }\n return HumanitarianHellJokeSettings;\n}());\n\n\n\n//# sourceURL=webpack://mybb-april-fools/./src/jokes/humanitarian_hell.ts?"); + +/***/ }), + +/***/ "./src/jokes/letter_chaos.ts": +/*!***********************************!*\ + !*** ./src/jokes/letter_chaos.ts ***! + \***********************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"LetterChaosJoke\": () => (/* binding */ LetterChaosJoke),\n/* harmony export */ \"LetterChaosJokeSettings\": () => (/* binding */ LetterChaosJokeSettings)\n/* harmony export */ });\n/* harmony import */ var _joke__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../joke */ \"./src/joke.ts\");\n/* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! jquery */ \"jquery\");\n/* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(jquery__WEBPACK_IMPORTED_MODULE_1__);\n/* harmony import */ var _handler__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../handler */ \"./src/handler.ts\");\nvar __extends = (undefined && undefined.__extends) || (function () {\n var extendStatics = function (d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\n return extendStatics(d, b);\n };\n return function (d, b) {\n if (typeof b !== \"function\" && b !== null)\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\nvar __spreadArray = (undefined && undefined.__spreadArray) || function (to, from, pack) {\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\n if (ar || !(i in from)) {\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\n ar[i] = from[i];\n }\n }\n return to.concat(ar || Array.prototype.slice.call(from));\n};\n\n\n\n/**\n * **Буквенный хаос**\n *\n * Все буквы в словах, кроме первой и последней, перемешены.\n *\n * @author Kozhilya\n */\nvar LetterChaosJoke = /** @class */ (function (_super) {\n __extends(LetterChaosJoke, _super);\n function LetterChaosJoke() {\n var _this = _super !== null && _super.apply(this, arguments) || this;\n _this.id = 'letter_chaos';\n _this.settings = new LetterChaosJokeSettings;\n _this.punctuationSymbols = null;\n return _this;\n }\n LetterChaosJoke.prototype.shuffleLetters = function (word) {\n var _a;\n // Check if the word has two or more letters\n if ((word.length < 3) || !_handler__WEBPACK_IMPORTED_MODULE_2__.AprilFoolsJokeClass.check(this.settings.shuffle_chance)) {\n return word;\n }\n // Split the word into an array of characters\n var characters = word.split(\"\");\n // Shuffle the characters between the first and last letters\n var middleCharacters = characters.slice(1, -1);\n for (var i = middleCharacters.length - 1; i > 0; i--) {\n var j = Math.floor(Math.random() * (i + 1));\n _a = [middleCharacters[j], middleCharacters[i]], middleCharacters[i] = _a[0], middleCharacters[j] = _a[1];\n }\n // Join the shuffled characters back into a word\n return __spreadArray(__spreadArray([characters[0]], middleCharacters, true), [characters[characters.length - 1]], false).join(\"\");\n };\n LetterChaosJoke.prototype.processNode = function (node) {\n var _a;\n node.textContent = (_a = node.textContent) === null || _a === void 0 ? void 0 : _a.replace(/([А-Яа-яA-Za-z]+)/gm, this.shuffleLetters);\n };\n LetterChaosJoke.prototype.start = function () {\n var _this = this;\n var items = jquery__WEBPACK_IMPORTED_MODULE_1___default()(this.settings.selector).find('*').contents().filter(function (_, node) { return node.nodeType === Node.TEXT_NODE; });\n items.each(function (_, node) { return _this.processNode(node); });\n };\n return LetterChaosJoke;\n}(_joke__WEBPACK_IMPORTED_MODULE_0__.Joke));\n\nvar LetterChaosJokeSettings = /** @class */ (function () {\n function LetterChaosJokeSettings() {\n this.chance = 20;\n /**\n * Селектор всех элементов, которые будут затронуты\n */\n this.selector = '.post-content';\n /**\n * Вероятность того, что буквы будут перемешаны\n */\n this.shuffle_chance = 50;\n }\n return LetterChaosJokeSettings;\n}());\n\n\n\n//# sourceURL=webpack://mybb-april-fools/./src/jokes/letter_chaos.ts?"); /***/ }), @@ -96,7 +106,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac \*********************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _handler__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./handler */ \"./src/handler.ts\");\n/* harmony import */ var _jokes_shake__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./jokes/shake */ \"./src/jokes/shake.ts\");\n/* harmony import */ var _jokes_humanitarian_hell__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./jokes/humanitarian_hell */ \"./src/jokes/humanitarian_hell.ts\");\n/* harmony import */ var _jokes_mirror__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./jokes/mirror */ \"./src/jokes/mirror.ts\");\n/* harmony import */ var _jokes_carnival__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./jokes/carnival */ \"./src/jokes/carnival.ts\");\n/* harmony import */ var _jokes_crazy_letters__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./jokes/crazy_letters */ \"./src/jokes/crazy_letters.ts\");\n/* harmony import */ var _jokes_crazy_punctuation__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./jokes/crazy_punctuation */ \"./src/jokes/crazy_punctuation.ts\");\n\n\n\n\n\n\n\nwindow.AprilJokes = (function (jokes) {\n var cl = new _handler__WEBPACK_IMPORTED_MODULE_0__.AprilFoolsJokeClass();\n jokes.forEach(function (joke) {\n cl.add(new joke());\n });\n cl.regularStart();\n return cl;\n})([\n _jokes_shake__WEBPACK_IMPORTED_MODULE_1__.ShakeJoke,\n _jokes_humanitarian_hell__WEBPACK_IMPORTED_MODULE_2__.HumanitarianHellJoke,\n _jokes_mirror__WEBPACK_IMPORTED_MODULE_3__.MirrorJoke,\n _jokes_carnival__WEBPACK_IMPORTED_MODULE_4__.CarnivalJoke,\n _jokes_crazy_letters__WEBPACK_IMPORTED_MODULE_5__.CrazyLettersJoke,\n _jokes_crazy_punctuation__WEBPACK_IMPORTED_MODULE_6__.CrazyPunctuationJoke,\n]);\n\n\n//# sourceURL=webpack://mybb-april-fools/./src/main.ts?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _handler__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./handler */ \"./src/handler.ts\");\n/* harmony import */ var _jokes_shake__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./jokes/shake */ \"./src/jokes/shake.ts\");\n/* harmony import */ var _jokes_humanitarian_hell__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./jokes/humanitarian_hell */ \"./src/jokes/humanitarian_hell.ts\");\n/* harmony import */ var _jokes_mirror__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./jokes/mirror */ \"./src/jokes/mirror.ts\");\n/* harmony import */ var _jokes_carnival__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./jokes/carnival */ \"./src/jokes/carnival.ts\");\n/* harmony import */ var _jokes_crazy_letters__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./jokes/crazy_letters */ \"./src/jokes/crazy_letters.ts\");\n/* harmony import */ var _jokes_crazy_punctuation__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./jokes/crazy_punctuation */ \"./src/jokes/crazy_punctuation.ts\");\n/* harmony import */ var _jokes_letter_chaos__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./jokes/letter_chaos */ \"./src/jokes/letter_chaos.ts\");\n\n\n\n\n\n\n\n\nwindow.AprilJokes = (function (jokes) {\n var cl = new _handler__WEBPACK_IMPORTED_MODULE_0__.AprilFoolsJokeClass();\n jokes.forEach(function (joke) {\n cl.add(new joke());\n });\n cl.regularStart();\n return cl;\n})([\n _jokes_shake__WEBPACK_IMPORTED_MODULE_1__.ShakeJoke,\n _jokes_humanitarian_hell__WEBPACK_IMPORTED_MODULE_2__.HumanitarianHellJoke,\n _jokes_mirror__WEBPACK_IMPORTED_MODULE_3__.MirrorJoke,\n _jokes_carnival__WEBPACK_IMPORTED_MODULE_4__.CarnivalJoke,\n _jokes_crazy_letters__WEBPACK_IMPORTED_MODULE_5__.CrazyLettersJoke,\n _jokes_crazy_punctuation__WEBPACK_IMPORTED_MODULE_6__.CrazyPunctuationJoke,\n _jokes_letter_chaos__WEBPACK_IMPORTED_MODULE_7__.LetterChaosJoke,\n]);\n\n\n//# sourceURL=webpack://mybb-april-fools/./src/main.ts?"); /***/ }), diff --git a/src/jokes/crazy_punctuation.ts b/src/jokes/crazy_punctuation.ts index c6fad6e..5bf058e 100644 --- a/src/jokes/crazy_punctuation.ts +++ b/src/jokes/crazy_punctuation.ts @@ -10,35 +10,45 @@ import $ from "jquery"; */ export class CrazyPunctuationJoke extends Joke { id = 'crazy_punctuation'; - + settings = new CrazyPunctuationJokeSettings; - private transform(text: string): string { - let newText = ""; + punctuationSymbols: string[]|null = null; - for (let i = 0; i < text.length; i++) { - const currentChar = text[i]; - const nextChar = text[i + 1]; - - if (this.settings.symbols.includes(currentChar)) { - newText += currentChar; - } else if (nextChar === " " || this.settings.symbols.includes(nextChar)) { - newText += currentChar; - } + private shufflePunctuation(text: string): string { + if (this.punctuationSymbols === null) { + this.punctuationSymbols = this.settings.symbols.split(''); } + const words = text.split(" "); - return newText; - } + const shuffledWords = words.map(word => { + const characters = word.split(""); - private process(node: any): void { + // Filter out any non-punctuation characters + const punctuation = characters.filter(char => this.punctuationSymbols.includes(char)); + // Shuffle the punctuation array + const shuffledPunctuation = punctuation.sort(() => Math.random() - 0.5); + + // Loop through each character in the word and replace punctuation with shuffled punctuation + let index = 0; + return characters.map(char => { + if (this.punctuationSymbols.includes(char)) { + return shuffledPunctuation[index++]; + } + return char; + }).join(""); + }); + + // Join the shuffled words array into a single string with spaces + return shuffledWords.join(" "); } start(): void { const items = $(this.settings.selector).find('*').contents().filter((_, node) => node.nodeType === Node.TEXT_NODE); items.each((_, node) => { - console.log(node); + node.textContent = this.shufflePunctuation(node.textContent); }) } } @@ -49,7 +59,7 @@ export class CrazyPunctuationJokeSettings implements JokeSettings { /** * Селектор всех элементов, которые будут затронуты */ - selector: string = '.post-content'; + selector: string = '.post-content p'; /** * Мигрирующие знаки diff --git a/src/jokes/letter_chaos.ts b/src/jokes/letter_chaos.ts new file mode 100644 index 0000000..25ddf9a --- /dev/null +++ b/src/jokes/letter_chaos.ts @@ -0,0 +1,62 @@ +import { Joke, JokeSettings, StopableJoke } from "../joke"; +import $ from "jquery"; +import { AprilFoolsJokeClass } from "../handler"; + +/** + * **Буквенный хаос** + * + * Все буквы в словах, кроме первой и последней, перемешены. + * + * @author Kozhilya + */ +export class LetterChaosJoke extends Joke { + id = 'letter_chaos'; + + settings = new LetterChaosJokeSettings; + + punctuationSymbols: string[] | null = null; + + private shuffleLetters(word: string): string { + // Check if the word has two or more letters + if ((word.length < 3) || !AprilFoolsJokeClass.check(this.settings.shuffle_chance)) { + return word; + } + + // Split the word into an array of characters + const characters = word.split(""); + + // Shuffle the characters between the first and last letters + const middleCharacters = characters.slice(1, -1); + for (let i = middleCharacters.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)); + [middleCharacters[i], middleCharacters[j]] = [middleCharacters[j], middleCharacters[i]]; + } + + // Join the shuffled characters back into a word + return [characters[0], ...middleCharacters, characters[characters.length - 1]].join(""); + } + + private processNode(node: any) { + node.textContent = node.textContent?.replace(/([А-Яа-яA-Za-z]+)/gm, this.shuffleLetters); + } + + start(): void { + const items = $(this.settings.selector).find('*').contents().filter((_, node) => node.nodeType === Node.TEXT_NODE); + + items.each((_, node) => this.processNode(node)) + } +} + +export class LetterChaosJokeSettings implements JokeSettings { + chance: number = 20; + + /** + * Селектор всех элементов, которые будут затронуты + */ + selector: string = '.post-content'; + + /** + * Вероятность того, что буквы будут перемешаны + */ + shuffle_chance: number = 50; +} diff --git a/src/main.ts b/src/main.ts index 8054f29..e91bf4c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -6,6 +6,7 @@ import { MirrorJoke } from "./jokes/mirror"; import { CarnivalJoke } from "./jokes/carnival"; import { CrazyLettersJoke } from "./jokes/crazy_letters"; import { CrazyPunctuationJoke } from "./jokes/crazy_punctuation"; +import { LetterChaosJoke } from "./jokes/letter_chaos"; (window as any).AprilJokes = ((jokes: JokeClassList): AprilFoolsJokeClass => { const cl = new AprilFoolsJokeClass(); @@ -24,6 +25,7 @@ import { CrazyPunctuationJoke } from "./jokes/crazy_punctuation"; CarnivalJoke, CrazyLettersJoke, CrazyPunctuationJoke, + LetterChaosJoke, ]); interface JokeClassList extends Array Joke> {} \ No newline at end of file diff --git a/webpack.config.js b/webpack.config.js index 453645a..4b2ce9b 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -3,6 +3,7 @@ const path = require("path"); const webpack = require("webpack"); const BomPlugin = require('webpack-utf8-bom'); +const { exec } = require('node:child_process'); const isProduction = process.env.NODE_ENV == "production"; @@ -13,7 +14,18 @@ const config = { filename: () => ('april-fools' + (isProduction ? '.min' : '') + '.js'), }, plugins: [ - new BomPlugin(true) + new BomPlugin(true), + { + apply: (compiler) => { + compiler.hooks.afterEmit.tap('AfterEmitPlugin', (compilation) => { + exec('./upload.sh', (err, stdout, stderr) => { + if (stdout) process.stdout.write(stdout); + if (stderr) process.stderr.write(stderr); + console.log("Uploaded."); + }); + }); + } + } // Add your plugins here // Learn more about plugins from https://webpack.js.org/configuration/plugins/ ],