Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name avecrypto
- // @namespace http://tampermonkey.net/
- // @version 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==
- const CURRENT_VERSION = 1;
- const START_DELIMITER = '#secret#start#';
- const END_DELIMITER = '#secret#end#';
- const SUBSTITUTORS = [
- ['=', '##EQUAL##'],
- ['+', '##PLUS##'],
- ['/', '##SLASH##'],
- ];
- const CRYPTO_REGEXP = new RegExp(`#v([0-9]+)${START_DELIMITER}([a-zA-Z0-9#]+)${END_DELIMITER}`);
- function getSelection (field) {
- return field.value.substring(field.selectionStart, field.selectionEnd);
- }
- function replaceSelection (field, new_value) {
- field.value = [field.value.slice(0, field.selectionStart), new_value, field.value.slice(field.selectionEnd)].join('');
- }
- function encode (text) {
- return SUBSTITUTORS.reduce((acc, v) => acc.split(v[0]).join(v[1]), btoa(text));
- }
- function decode (text) {
- return atob(SUBSTITUTORS.reduce((acc, v) => acc.split(v[1]).join(v[0]), text));
- }
- function formatForHide (text) {
- return `<color=#v${CURRENT_VERSION}${START_DELIMITER}${encode(text)}${END_DELIMITER}> </color>`;
- }
- function formatForDisp (text, version) {
- return `Message Avepremium: <spoiler>${decode(text)}</spoiler>`;
- }
- function createButton () {
- const button = $('<button type="button" class="btn" tabindex="-1" href="#">');
- const img = $('<img src="https://avenoel.org/images/smilies/724771109.gif">');
- img.appendTo(button);
- button.click(function () {
- let field = $(this).closest('form').find('textarea')[0];
- if (field.selectionStart === field.selectionEnd) {
- return console.log('vous devez selectionner le texte à cacher');
- }
- let text = getSelection(field);
- replaceSelection(field, formatForHide(text));
- });
- return button;
- }
- (function() {
- 'use strict';
- createButton().appendTo($('.bbcodes'));
- if (document.location.pathname.split('/')[1] === 'topic') {
- $('.text-color').filter(function () {
- return CRYPTO_REGEXP.test($(this).attr('style'));
- }).each(function () {
- let [,version, text] = $(this).attr('style').match(CRYPTO_REGEXP);
- $.post('https://avenoel.org/previsualisation', {content: formatForDisp(text, version)}).done(res => {
- $(this).html(res.content);
- });
- });
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement