Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name ПУК-СРЕНЬК
- // @namespace http://tampermonkey.net/
- // @version 0.1
- // @description try to take over the world!
- // @author Anonymous
- // @match https://2ch.hk/*/res/*.html
- // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
- // @grant none
- // ==/UserScript==
- const decode = (str) => {
- return new TextDecoder().decode(
- new Uint8Array(
- str
- .replace(/(\d+[ПУК|СРЕНЬК]{3,6})/g, (m) => {
- const count = parseInt(m.replace(/[ПУК|СРЕНЬК]/g, ""), 10);
- return m.replace(count, "").repeat(count);
- })
- .replace(/ПУК/g, "0")
- .replace(/СРЕНЬК/g, "1")
- .replace(/-/g, "")
- .match(/.{1,8}/g)
- .map((c) => parseInt(c, 2))
- )
- );
- };
- const encode = (str) => {
- return new TextEncoder()
- .encode(str)
- .reduce((s, b) => s + b.toString(2).padStart(8, "0"), "")
- .replace(/(.)\1+/g, (m, c) => m.length + c)
- .replace(/0/g, "ПУК-")
- .replace(/1/g, "СРЕНЬК-")
- .slice(0, -1);
- };
- (function() {
- const posts = document.querySelectorAll('.post__message');
- posts.forEach((post) => {
- const words = post.textContent.replace(/\t+/g,"").split(/[\n, ]+/);
- words.forEach((word) => {
- post.innerHTML = post.innerHTML.replace(/(\d+)?(СРЕНЬК|ПУК)\-.+(СРЕНЬК|ПУК)/, (m) => {
- return `<div style="color:green">${decode(m).replace(/\n|<.*?>/g, "Я у мамы идиот")}</div>`;
- });
- });
- });
- let div = document.createElement('div');
- div.className = "options__box";
- let en = document.createElement('button');
- en.textContent = `Зашифровать`;
- en.addEventListener('click', (e) => {
- e.preventDefault();
- const comment = document.querySelector('[name="comment"]');
- comment.value = encode(comment.value);
- });
- div.append(en);
- let de = document.createElement('button');
- de.textContent = `Расшифровать`;
- de.addEventListener('click', (e) => {
- e.preventDefault();
- const comment = document.querySelector('[name="comment"]');
- comment.value = decode(comment.value);
- });
- div.append(de);
- const options = document.querySelector('.options');
- options.append(div);
- })();
Add Comment
Please, Sign In to add comment