Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Discord Text Formatting
- // @namespace http://discordapp.com/
- // @version 2
- // @author Huntereb
- // @match *://discordapp.com/*
- // @require http://code.jquery.com/jquery-latest.js
- // ==/UserScript==
- //Initial variables! Can be applied in-app with the insert key!
- var beforeText = "";
- var afterText = "";
- var reparseQuotes = 0;
- var paused = 0;
- //Don't edit anything below here
- function literalAddReturn (string) {
- var string2 = string.split('%r');
- var string3 = "";
- for(i = 0; i < string2.length; i++) {
- if (i !== string2.length - 1) string3 += string2[i] + "\r\n";
- else return string3 += string2[i];
- }
- }
- function applyBinds() {
- jQuery(textboxes).keypress(function (e) {
- if (paused == 1) return;
- if (e.shiftKey) return;
- if (e.which == '13') {
- for(i = 0; i < textboxes.length; i++) {
- var ourText = textboxes[i].value;
- var ourQuotes = '';
- var ptrn = /@.+?#[0-9]+/g;
- var match;
- while ( ( match = ptrn.exec(ourText) ) !== null ) {
- ourQuotes += match + ' ';
- }
- if(!/\d/g.test(ourQuotes) || reparseQuotes === 0) {
- ourQuotes = '';
- }
- textboxes[i].value = ourQuotes + beforeText + ourText + afterText;
- }
- }
- });
- jQuery(textboxes).keyup(function (e) {
- if (e.keyCode == 19) {
- if (paused == 1) paused = 0;
- else paused = 1;
- }
- if (e.keyCode == 45) {
- beforeText = literalAddReturn(prompt("Enter formatting before your text (%r for new line)", beforeText));
- afterText = literalAddReturn(prompt("Enter formatting after your text (%r for new line)", afterText));
- if(confirm("Parse quotes? (You don't need to unless you're using code tags)\r\nCancel = No")) reparseQuotes = 1;
- else reparseQuotes = 0;
- }
- if (e.keyCode == 36) {
- alert("Auto-Formatting Help:\r\nPAUSE (Pause key): Pause text formatting. Press it again to continue!\r\nINS (Insert key): Set formatting (resets to default on page refresh)\r\nYour current formatting: " + beforeText + "[Your text]" + afterText + "\r\nMade by Huntereb");
- }
- });
- }
- function start() {
- jQuery(textboxes).unbind();
- textboxes = document.getElementsByTagName('textarea');
- if (paused === 0) for(i = 0; i < textboxes.length; i++) textboxes[i].placeholder = 'Formatting in progress! Press "Home" for help!';
- else for(i = 0; i < textboxes.length; i++) textboxes[i].placeholder = 'Formatting paused! Press \"Pause\" key to continue!';
- applyBinds();
- setTimeout(start, 1000);
- }
- var textboxes;
- start();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement