Guest User

Untitled

a guest
Dec 22nd, 2021
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         ПУК-СРЕНЬК
  3. // @namespace    http://tampermonkey.net/
  4. // @version      0.1
  5. // @description  try to take over the world!
  6. // @author       Anonymous
  7. // @match        https://2ch.hk/*/res/*.html
  8. // @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  9. // @grant        none
  10. // ==/UserScript==
  11.  
  12. const decode = (str) => {
  13.     return new TextDecoder().decode(
  14.         new Uint8Array(
  15.             str
  16.             .replace(/(\d+[ПУК|СРЕНЬК]{3,6})/g, (m) => {
  17.                 const count = parseInt(m.replace(/[ПУК|СРЕНЬК]/g, ""), 10);
  18.                 return m.replace(count, "").repeat(count);
  19.             })
  20.             .replace(/ПУК/g, "0")
  21.             .replace(/СРЕНЬК/g, "1")
  22.             .replace(/-/g, "")
  23.             .match(/.{1,8}/g)
  24.             .map((c) => parseInt(c, 2))
  25.         )
  26.     );
  27. };
  28.  
  29. const encode = (str) => {
  30.     return new TextEncoder()
  31.         .encode(str)
  32.         .reduce((s, b) => s + b.toString(2).padStart(8, "0"), "")
  33.         .replace(/(.)\1+/g, (m, c) => m.length + c)
  34.         .replace(/0/g, "ПУК-")
  35.         .replace(/1/g, "СРЕНЬК-")
  36.         .slice(0, -1);
  37. };
  38.  
  39. (function() {
  40.     const posts = document.querySelectorAll('.post__message');
  41.  
  42.     posts.forEach((post) => {
  43.         const words = post.textContent.replace(/\t+/g,"").split(/[\n, ]+/);
  44.  
  45.         words.forEach((word) => {
  46.             post.innerHTML = post.innerHTML.replace(/(\d+)?(СРЕНЬК|ПУК)\-.+(СРЕНЬК|ПУК)/, (m) => {
  47.                 return `<div style="color:green">${decode(m).replace(/\n|<.*?>/g, "Я у мамы идиот")}</div>`;
  48.             });
  49.         });
  50.     });
  51.  
  52.     let div = document.createElement('div');
  53.     div.className = "options__box";
  54.  
  55.     let en = document.createElement('button');
  56.     en.textContent = `Зашифровать`;
  57.     en.addEventListener('click', (e) => {
  58.         e.preventDefault();
  59.         const comment = document.querySelector('[name="comment"]');
  60.         comment.value = encode(comment.value);
  61.     });
  62.     div.append(en);
  63.  
  64.     let de = document.createElement('button');
  65.     de.textContent = `Расшифровать`;
  66.     de.addEventListener('click', (e) => {
  67.         e.preventDefault();
  68.         const comment = document.querySelector('[name="comment"]');
  69.         comment.value = decode(comment.value);
  70.     });
  71.     div.append(de);
  72.  
  73.     const options = document.querySelector('.options');
  74.     options.append(div);
  75. })();
Add Comment
Please, Sign In to add comment