Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name ПУК-СРЕНЬК
- // @version 2.1
- // @description Encode and decode 2ch.hk fart code
- // @author Anonymous
- // @include *://2ch.*
- // @grant none
- // @run-at document-end
- // ==/UserScript==
- const syms = [
- "ПУК",
- "СРЕНЬК",
- "ХРЮК",
- "УИИИ",
- "ЛАХТА",
- "ЛИБЕРАХА",
- "ХОХЛЫ",
- "СВИНОСОБАКА",
- "ШВАЙНОКАРАСЬ",
- "ЛОЛ",
- "КЕК",
- "АБУ",
- "ДВАЧ",
- "ПАРАША",
- "ПОРИДЖ",
- "ХРЮЧЕВО",
- "СВИН",
- "ПЕРДИКС",
- "ПЫНЯ",
- "ЧАЮ",
- "ШУЕ",
- "ЛЕВАК",
- "ПРАВАК",
- "КОМИГЛИСТ",
- "ШВЯТЫЕ",
- "ВАТА",
- "ВОЛОДИН",
- "ДОЛБИЛЬНЯ",
- "ПЕРЕФОРС",
- "КУНЧИК",
- "АВАТАРКА",
- "АНАЛЬЧИК",
- ];
- const keysLen = Math.log2(syms.length);
- const symsEncode = () => {
- let result = {};
- syms.forEach((item, index) => {
- result[
- ("0".repeat(keysLen) + index.toString(2)).slice(-keysLen)
- ] = item;
- });
- return result;
- };
- const symsDecode = () => {
- let result = {};
- Object.entries(symsEncode()).forEach(([key, value]) => {
- result[value] = key;
- });
- return result;
- };
- const rle = (string) => {
- let arr = string.split("-"),
- encoding = [],
- previous = arr[0],
- count = 1;
- for (let i = 1; i < arr.length; i++) {
- if (arr[i] !== previous) {
- encoding.push(count, previous);
- count = 1;
- previous = arr[i];
- } else {
- count++;
- }
- }
- encoding.push(count, previous);
- return encoding.join("-").replace(/1-/g, "").replace(/(\d)-/g, "$1");
- };
- const decode = (string) => {
- const data = symsDecode();
- let ba = string
- .split("-")
- .map((item) => {
- const count = /(\d*)(\w+)-?/.exec(item);
- if (count) {
- const key = item.replace(count[0], "");
- return data[key].repeat(parseInt(count[0]));
- }
- return data[item];
- })
- .join("");
- const padLen = ba.length % 8;
- ba = ba.substring(0, ba.length - padLen);
- return new TextDecoder().decode(
- new Uint8Array(ba.match(/.{1,8}/g).map((c) => parseInt(c, 2)))
- );
- };
- const encode = (string) => {
- let ba = new TextEncoder()
- .encode(string)
- .reduce((s, b) => s + b.toString(2).padStart(8, "0"), "");
- const padLen = keysLen - (ba.length % keysLen);
- ba = ba + "0".repeat(padLen);
- const data = symsEncode();
- return rle(
- ba
- .match(new RegExp(`.{1,${keysLen}}`, "g"))
- .map((item) => {
- return data[item];
- })
- .join("-")
- );
- };
- (() => {
- const parse = (node) => {
- const post = node.querySelector(".post__message");
- if (post && post.textContent) {
- const words = post.textContent
- .replace(/\t+/g, "")
- .split(/[\n,\s]+/);
- const re = new RegExp(
- `(\\d+)?(${syms.join("|")})\-(\\S+)\-(\\d+)?(${syms.join("|")})`
- );
- words.forEach((word) => {
- post.innerHTML = post.innerHTML.replace(re, (m) => {
- try {
- const thread = node.parentElement.parentElement.id.replace(
- /thread-/,
- ""
- );
- const board = window.location.pathname.split("/")[1];
- return `<span style="color:green;font-size:1.21em">${decode(
- m
- )
- .replace(/<.*?>/g, "[Я у мамы идиот]")
- .replace(
- /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim,
- '<a href="$1" target="_blank" target="_blank" rel="nofollow noopener noreferrer">$1</a>'
- )
- .replace(
- /(^|[^\/])(www\.[\S]+(\b|$))/gim,
- '$1<a href="http://$2" target="_blank" rel="nofollow noopener noreferrer">$2</a>'
- )
- .replace(
- /(([a-zA-Z0-9\-\_\.])+@[a-zA-Z\_]+?(\.[a-zA-Z]{2,6})+)/gim,
- '<a href="mailto:$1" target="_blank" rel="nofollow noopener noreferrer">$1</a>'
- )
- .replace(
- /\>>(\d{9})/gim,
- '<a href="/' +
- board +
- "/res/" +
- thread +
- '.html#$1" class="post-reply-link" data-thread="' +
- thread +
- '" data-num="$1">>>$1</a>'
- )
- .replace(/\n/g, "<br>")}</span>`;
- } catch (err) {
- return m;
- }
- });
- });
- }
- };
- document.querySelectorAll(".post").forEach((post) => parse(post));
- const observer = new MutationObserver((o) => {
- o.forEach((i) => {
- if (i.addedNodes) {
- i.addedNodes.forEach((n) => parse(n));
- }
- });
- });
- const config = { childList: true };
- observer.observe(document.querySelector(".thread"), config);
- observer.observe(document.querySelector("#posts-form"), config);
- let container = document.createElement("div");
- container.className = "options__box";
- let enBtn = document.createElement("button");
- enBtn.className = "desktop button";
- enBtn.style = "color:green;font-weight:bold";
- enBtn.textContent = `Зашифровать`;
- enBtn.addEventListener("click", (e) => {
- e.preventDefault();
- const comment = document.querySelector('[name="comment"]');
- const selection = comment.value.substring(
- comment.selectionStart,
- comment.selectionEnd
- );
- if (selection) {
- const encoded = encode(selection);
- const start = comment.selectionStart;
- comment.value =
- comment.value.slice(0, start) +
- encoded +
- comment.value.slice(comment.selectionEnd);
- comment.focus();
- comment.setSelectionRange(start, start + encoded.length);
- } else {
- comment.value = encode(comment.value);
- }
- });
- container.append(enBtn);
- let deBtn = document.createElement("button");
- deBtn.className = "desktop button";
- deBtn.style = "color:red;font-weight:bold";
- deBtn.textContent = `Расшифровать`;
- deBtn.addEventListener("click", (e) => {
- e.preventDefault();
- try {
- const comment = document.querySelector('[name="comment"]');
- const selection = comment.value.substring(
- comment.selectionStart,
- comment.selectionEnd
- );
- if (selection) {
- const decoded = decode(selection);
- const start = comment.selectionStart;
- comment.value =
- comment.value.slice(0, start) +
- decoded +
- comment.value.slice(comment.selectionEnd);
- comment.focus();
- comment.setSelectionRange(start, start + decoded.length);
- } else {
- comment.value = decode(comment.value);
- }
- } catch (err) {}
- });
- container.append(deBtn);
- document.querySelector(".options").append(container);
- })();
Add Comment
Please, Sign In to add comment