var ST = window.ST || {}; ST.show_embed = function() { $embed_field = $('#embed_field'); var lang_showcode = $embed_field.data('lang-showcode'); $embed_field.hide(); $embed_field.after('' + lang_showcode + ''); $('#show_code').on('click', function(e) { e.preventDefault(); $(this).hide(); $embed_field.show().select(); }); $embed_field.on("blur", function() { $(this).hide(); $('#show_code').show(); }); }; ST.spamadmin = function() { if ($('.content h1').text() == 'Spamadmin') { $('.content .hidden').show(); $('.content .quick_remove').live('click', function(ev) { var ip = $(ev.target).data('ip'); if (confirm('Delete all pastes belonging to ' + ip + '?')) { $.post(base_url + 'spamadmin/' + ip, { 'confirm_remove': 'yes', 'block_ip': 1 }, function() { window.location.reload(); }); } return false; }); } // needed by .selectable $.fn.addBack = function(selector) { return this.add(selector == null ? this.prevObject : this.prevObject.filter(selector)); } $('.selectable>tbody').selectable({ filter: 'tr', cancel: 'a', stop: function() { var $deletestack = $(".paste_deletestack"); var $input = $("input[name=pastes_to_delete]"); $('.inv').show(); $deletestack.empty(); $input.empty(); var res = []; $(".ui-selected").each(function(i, el) { var id = $('a', el).attr('href').split('view/')[1]; res.push(id); }); $deletestack.text(res.join(' ')); $input.val(res.join(' ')); } }); }; ST.line_highlighter = function() { var org_href = window.location.href.replace(/(.*?)#(.*)/, '$1'); var first_line = false; var second_line = false; $('blockquote').on('mousedown', function(ev) { if (ev.which == 1) { // left mouse button has been clicked window.getSelection().removeAllRanges(); } }); $('blockquote').on('click', 'li', function(ev) { var $this = $(this); var li_num = ($this.index() + 1); if (ev.shiftKey == 1) { second_line = li_num; } else { first_line = li_num; second_line = false; } if (second_line) { // determine mark if (first_line < second_line) { sel_start = first_line; sel_end = second_line; } else { sel_start = second_line; sel_end = first_line; } window.location.href = org_href + '#L' + sel_start + '-L' + sel_end; } else { window.location.href = org_href + '#L' + first_line; } ST.highlight_lines(); }); ST.highlight_lines(); } ST.highlight_lines = function() { var wloc = window.location.href; if (wloc.indexOf('#') > -1) { $('.container .CodeMirror li').css('background', 'none'); var lines = wloc.split('#')[1]; if (lines.indexOf('-') > -1) { var start_line = parseInt(lines.split('-')[0].replace('L', ''), 10); var end_line = parseInt(lines.split('-')[1].replace('L', ''), 10); for (var i = start_line; i <= end_line; i++) { $('.container .CodeMirror li:nth-child(' + i + ')').css('background', '#F8EEC7'); } } else { var re = new RegExp('^L[0-9].*?$'); var r = lines.match(re); if (r) { var marked_line = lines.replace('L', ''); $('.container .CodeMirror li:nth-child(' + marked_line + ')').css('background', '#F8EEC7'); } } } } ST.crypto = function() { $('button[name=submit]').after(' '); $('#create_encrypted').on('click', function() { var $code = $('#code'); // save CM into textarea CM.editor.save(); // encrypt the paste var key = ST.crypto_generate_key(32); var plaintext = $code.val(); plaintext = LZString.compressToBase64(plaintext); var encrypted = CryptoJS.AES.encrypt(plaintext, key) + ''; // linebreak after 100 chars encrypted = encrypted.replace(/(.{100})/g, "$1\n"); // post request via JS $.post(base_url + 'post_encrypted', { 'name': $('#name').val(), 'title': $('#title').val(), 'code': encrypted, 'lang': $('#lang').val(), 'expire': $('#expire').val(), 'reply': $('input[name=reply]').val() }, function(redirect_url) { if (redirect_url.indexOf('invalid') > -1) { $('#create_encrypted').parent().html('
' + redirect_url + '#' + key + '
'); } else { window.location.href = base_url + redirect_url + '#' + key; } }); return false; }); // decryption routine w_href = window.location.href; if (w_href.indexOf('#') > -1) { key = w_href.split('#')[1]; var re = new RegExp('^L[0-9].*?$'); var r = key.match(re); if (key.indexOf('-') > -1 || r) { // line highlighter } else { try { var $code = $('#code'); var encrypted = $code.val().replace(/\n/g, ''); var decrypted = CryptoJS.AES.decrypt(encrypted, key).toString(CryptoJS.enc.Utf8) + ''; decrypted = LZString.decompressFromBase64(decrypted); $code.val(decrypted); // add a breaking_space after 90 chars (for later) decrypted = decrypted.replace(/(.{90}.*?) /g, "$1{{{breaking_space}}}"); // remove html entities decrypted = decrypted .replace(/&/g, '&') .replace(/"/g, '"') .replace(/'/g, ''') .replace(//g, '>') .replace(/ /g, ' ') .replace(/{{{breaking_space}}}/g, ' ') .replace(/\n/g, '