Guest User

reaz

a guest
Apr 26th, 2018
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. // ==UserScript==
  2. // @name avecrypto
  3. // @namespace http://tampermonkey.net/
  4. // @version 1
  5. // @description try to take over the world!
  6. // @author anonymousse
  7. // @match https://avenoel.org/*
  8. // @exclude https://avenoel.org/chat*
  9. // @exclude https://avenoel.org/admin*
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. const CURRENT_VERSION = 1;
  14. const START_DELIMITER = '#secret#start#';
  15. const END_DELIMITER = '#secret#end#';
  16. const SUBSTITUTORS = [
  17. ['=', '##EQUAL##'],
  18. ['+', '##PLUS##'],
  19. ['/', '##SLASH##'],
  20. ];
  21.  
  22. const CRYPTO_REGEXP = new RegExp(`#v([0-9]+)${START_DELIMITER}([a-zA-Z0-9#]+)${END_DELIMITER}`);
  23.  
  24. function getSelection (field) {
  25. return field.value.substring(field.selectionStart, field.selectionEnd);
  26. }
  27.  
  28. function replaceSelection (field, new_value) {
  29. field.value = [field.value.slice(0, field.selectionStart), new_value, field.value.slice(field.selectionEnd)].join('');
  30. }
  31.  
  32. function encode (text) {
  33. return SUBSTITUTORS.reduce((acc, v) => acc.split(v[0]).join(v[1]), btoa(text));
  34. }
  35.  
  36. function decode (text) {
  37. return atob(SUBSTITUTORS.reduce((acc, v) => acc.split(v[1]).join(v[0]), text));
  38. }
  39.  
  40. function formatForHide (text) {
  41. return `<color=#v${CURRENT_VERSION}${START_DELIMITER}${encode(text)}${END_DELIMITER}> </color>`;
  42. }
  43.  
  44. function formatForDisp (text, version) {
  45. return `Message Avepremium: <spoiler>${decode(text)}</spoiler>`;
  46. }
  47.  
  48. function createButton () {
  49. const button = $('<button type="button" class="btn" tabindex="-1" href="#">');
  50. const img = $('<img src="https://avenoel.org/images/smilies/724771109.gif">');
  51.  
  52. img.appendTo(button);
  53.  
  54. button.click(function () {
  55. let field = $(this).closest('form').find('textarea')[0];
  56.  
  57. if (field.selectionStart === field.selectionEnd) {
  58. return console.log('vous devez selectionner le texte à cacher');
  59. }
  60. let text = getSelection(field);
  61. replaceSelection(field, formatForHide(text));
  62. });
  63.  
  64. return button;
  65. }
  66.  
  67. (function() {
  68. 'use strict';
  69.  
  70. createButton().appendTo($('.bbcodes'));
  71.  
  72. if (document.location.pathname.split('/')[1] === 'topic') {
  73. $('.text-color').filter(function () {
  74. return CRYPTO_REGEXP.test($(this).attr('style'));
  75. }).each(function () {
  76. let [,version, text] = $(this).attr('style').match(CRYPTO_REGEXP);
  77. $.post('https://avenoel.org/previsualisation', {content: formatForDisp(text, version)}).done(res => {
  78. $(this).html(res.content);
  79. });
  80. });
  81. }
  82. })();
Add Comment
Please, Sign In to add comment