Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name crypto
- // @namespace http://tampermonkey.net/
- // @version 0.1
- // @description try to take over the world!
- // @author anonymousse
- // @match https://avenoel.org/*
- // @exclude https://avenoel.org/chat*
- // @exclude https://avenoel.org/admin*
- // @grant none
- // ==/UserScript==
- function createKey (str_key) {
- let raw_key = Uint8Array.from(btoa(str_key), c => c.charCodeAt(0)).buffer;
- return crypto.subtle.digest('sha-256', raw_key).then(hash_key => {
- return crypto.subtle.importKey('raw', hash_key, { name: 'AES-CBC' }, false, ['encrypt', 'decrypt']);
- });
- }
- function encrypt (msg, str_key) {
- let data = Uint8Array.from(btoa(msg), c => c.charCodeAt(0));
- let initVector = new Uint8Array(16);
- crypto.getRandomValues(initVector);
- return createKey(str_key).then(key => {
- return crypto.subtle.encrypt({ name: 'AES-CBC', iv: initVector}, key, data);
- }).then(encrypted => {
- encrypted = new Uint8Array(encrypted);
- return btoa(encrypted) + '.' + btoa(initVector);
- });
- }
- function decrypt (msg, str_key) {
- let [encrypted, initVector] = msg.split('.');
- encrypted = new Uint8Array(atob(encrypted).split(','));
- initVector = new Uint8Array(atob(initVector).split(','));
- return createKey(str_key).then(key => {
- return crypto.subtle.decrypt({name: 'AES-CBC', iv: initVector}, key, encrypted);
- }).then(decrypted => {
- decrypted = new Uint8Array(decrypted);
- let decoded = atob(String.fromCharCode.apply(null, decrypted));
- return decoded;
- });
- }
- function previsu (msg, balise) {
- let req = new XMLHttpRequest();
- let form = new FormData();
- form.append('content', '[DECRYPTED CONTENT]\n' + msg + '\n[END]');
- req.open('POST', 'https://avenoel.org/previsualisation', true);
- req.setRequestHeader('x-csrf-token', document.token);
- req.setRequestHeader('x-requested-with', 'XMLHttpRequest');
- req.onload = function (res) {
- balise.innerHTML = JSON.parse(res.srcElement.response).content;
- };
- req.send(form);
- }
- (function() {
- 'use strict';
- document.token = document.querySelector('meta[name=csrf-token]').getAttribute('content');
- let bbcodes = document.getElementsByClassName('bbcodes')[0];
- let field = document.getElementsByTagName('textarea')[0];
- //on créé le bouton bbcode
- let button = document.createElement('button');
- button.setAttribute('type', 'button');
- button.setAttribute('class', 'btn');
- button.setAttribute('tabindex', '-1');
- button.setAttribute('href', '#');
- let img = document.createElement('img');
- img.setAttribute('src', 'https://avenoel.org/images/smilies/724771109.gif');
- button.appendChild(img);
- button.addEventListener('click', event => {
- let key = document.getElementsByClassName('bloc-title')[0].innerText.split(' ').pop();
- if (field.selectionStart === field.selectionEnd) {
- return ;
- }
- let msg = field.value.substr(field.selectionStart, field.selectionEnd);
- previsu(msg);
- encrypt(msg, key).then(encrypted => {
- let a = `<spoiler>[WARNING ENCRYPTED CONTENT]
- ${encrypted}
- [END]</spoiler>`;
- field.value = field.value.slice(0, field.selectionStart) + a + field.value.slice(field.selectionEnd);
- });
- });
- bbcodes.appendChild(button);
- if (document.location.pathname.split('/')[1] === 'topic') {
- Array.from(document.getElementsByClassName('message-content')).map(msg => {
- let author = msg.parentNode.getElementsByTagName('header')[0].getElementsByTagName('a')[0].pathname.split('/').pop();
- Array.from(msg.getElementsByClassName('spoiler-content')).map(spoiler => {
- if (!spoiler) return ;
- let tab = spoiler.innerText.split('\n\n');
- console.log(tab);
- if (tab.length === 3 && tab[0] === '[WARNING ENCRYPTED CONTENT]' && tab[2] === '[END]') {
- console.log('message encrypté;;; key = ' + author);
- decrypt(tab[1], author).then(decrypted => {
- previsu(decrypted, spoiler);
- });
- }
- });
- });
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment