diff options
author | Mario <mario@mariovavti.com> | 2024-03-22 08:37:29 +0000 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2024-03-22 08:37:29 +0000 |
commit | 1aeb05628b6a2a069c46980efbe628362c9e3e74 (patch) | |
tree | e9aed15d0cd74e0c23dcb05c7be8fe9541efdf36 /view/js | |
parent | 5b7387459cf4de8f7354d81cb0392c4225714d94 (diff) | |
parent | b464fae3bf22585888c5f3def8eded76fd48ed16 (diff) | |
download | volse-hubzilla-9.0.tar.gz volse-hubzilla-9.0.tar.bz2 volse-hubzilla-9.0.zip |
Merge branch '9.0RC'9.0
Diffstat (limited to 'view/js')
-rw-r--r-- | view/js/autocomplete.js | 6 | ||||
-rw-r--r-- | view/js/crypto.js | 98 | ||||
-rw-r--r-- | view/js/main.js | 28 | ||||
-rw-r--r-- | view/js/mod_poke.js | 5 |
4 files changed, 116 insertions, 21 deletions
diff --git a/view/js/autocomplete.js b/view/js/autocomplete.js index 8edd8dafa..7d6ddb1c4 100644 --- a/view/js/autocomplete.js +++ b/view/js/autocomplete.js @@ -45,7 +45,7 @@ function contact_format(item) { } function smiley_format(item) { - return "<div class='dropdown-item'>" + item.icon + ' ' + item.text + "</div>"; + return "<div class='dropdown-item'><img class='emoji' src='" + item.filepath + "'> " + item.shortname.replaceAll(':', '') + "</div>"; } function bbco_format(item) { @@ -193,8 +193,8 @@ function string2bb(element) { match: /(^|\s)(:[a-z0-9_:]{2,})$/, index: 2, cache: true, - search: function(term, callback) { $.getJSON('/smilies/json').done(function(data) { callback($.map(data, function(entry) { return entry.text.indexOf(term.substr(1)) !== -1 ? entry : null; })); }); }, - replace: function(item) { return "$1" + item.text + ' '; }, + search: function(term, callback) { $.getJSON('/smilies/json').done(function(data) { callback($.map(data, function(entry) { return entry.shortname.indexOf(term.substr(1)) !== -1 ? entry : null; })); }); }, + replace: function(item) { return "$1" + item.shortname + ' '; }, context: function(text) { return text.toLowerCase(); }, template: smiley_format }; diff --git a/view/js/crypto.js b/view/js/crypto.js index 14bc1e0a2..bc399caa3 100644 --- a/view/js/crypto.js +++ b/view/js/crypto.js @@ -15,6 +15,94 @@ function str_rot13 (str) { }); } +async function sodium_encrypt(element) { + if (!window.sodium) { + window.sodium = await SodiumPlus.auto(); + } + + if (typeof tinyMCE !== typeof undefined) { + tinyMCE.triggerSave(false,true); + } + + let message = $(element).val(); + + if (!message) { + return false; + } + + let password = prompt(aStr['passphrase']); + + if (!password) { + return false; + } + + let hint = bin2hex(prompt(aStr['passhint'])); + + let salt = await sodium.randombytes_buf(16); + let nonce = await sodium.randombytes_buf(24); + + let key = await sodium.crypto_pwhash( + 32, + password, + salt, + sodium.CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE, + sodium.CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE + ); + + // Message can be a string, buffer, array, etc. + let ciphertext = await sodium.crypto_secretbox(message, nonce, key); + delete message, password, key; + + let payload = { + hint: hint, + alg: 'XSalsa20', + salt: await sodium.sodium_bin2hex(salt), + nonce: await sodium.sodium_bin2hex(nonce), + ciphertext: await sodium.sodium_bin2hex(ciphertext) + }; + + let val = "[crypt]" + window.btoa(JSON.stringify(payload)) + '[/crypt]'; + + $(element).val(val); +} + +async function sodium_decrypt(payload, element) { + let arr = JSON.parse(window.atob(payload)); + + if (arr.alg !== 'XSalsa20') { + alert('Unsupported algorithm'); + return false; + } + + let password = prompt((arr.hint.length) ? hex2bin(arr.hint) : aStr['passphrase']); + + if (!password) { + return false; + } + + let salt = await sodium.sodium_hex2bin(arr.salt); + let nonce = await sodium.sodium_hex2bin(arr.nonce); + let ciphertext = await sodium.sodium_hex2bin(arr.ciphertext); + + let key = await sodium.crypto_pwhash( + 32, + password, + salt, + sodium.CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE, + sodium.CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE + ); + + let decrypted = await sodium.crypto_secretbox_open(ciphertext, nonce, key); + delete password, key; + + if ($(element).css('display') === 'none' && typeof tinyMCE !== typeof undefined) { + tinyMCE.activeEditor.setContent(decrypted.toString('utf-8')); + } + else { + $(element).html(decrypted.toString('utf-8')); + } +} + function hz_encrypt(alg, elem) { var enc_text = ''; var newdiv = ''; @@ -33,7 +121,7 @@ function hz_encrypt(alg, elem) { var enc_key = bin2hex(passphrase); // If you don't provide a key you get rot13, which doesn't need a key - // but consequently isn't secure. + // but consequently isn't secure. if(! enc_key) alg = 'rot13'; @@ -44,7 +132,7 @@ function hz_encrypt(alg, elem) { if(alg == 'AES-128-CCM') { // This is the prompt we're going to use when the receiver tries to open it. - // Maybe "Grandma's maiden name" or "our secret place" or something. + // Maybe "Grandma's maiden name" or "our secret place" or something. var enc_hint = bin2hex(prompt(aStr['passhint'])); @@ -62,7 +150,7 @@ function hz_encrypt(alg, elem) { // property of our source element - because a tinymce instance // will have display "none". If a normal textarea such as in a comment // box has display "none" you wouldn't be able to type in it. - + if($(elem).css('display') == 'none' && typeof tinyMCE !== "undefined") { tinyMCE.activeEditor.setContent(newdiv); } @@ -98,8 +186,8 @@ function hz_decrypt(alg, hint, text, elem) { enc_key = ''; // Not sure whether to drop this back in the conversation display. - // It probably needs a lightbox or popup window because any conversation - // updates could + // It probably needs a lightbox or popup window because any conversation + // updates could // wipe out the text and make you re-enter the key if it was in the // conversation. For now we do that so you can read it. diff --git a/view/js/main.js b/view/js/main.js index d022ee4a9..ba863b111 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -825,12 +825,12 @@ function scrollToItem() { if(justifiedGalleryActive) return; - var submid = ((bParam_mid.length) ? bParam_mid : 'abcdefg'); - var encoded = ((submid.substr(0,4) == 'b64.') ? true : false); - var submid_encoded = ((encoded) ? submid : window.btoa(submid)); + let submid = ((bParam_mid.length) ? bParam_mid : 'abcdefg'); + //var encoded = ((submid.substr(0,4) == 'b64.') ? true : false); + //var submid_encoded = ((encoded) ? submid : window.btoa(submid)); $('.thread-wrapper').filter(function() { - if($(this).data('b64mids').indexOf(submid_encoded) > -1 && !$(this).hasClass('toplevel_item')) { + if($(this).data('b64mids').indexOf(submid) > -1 && !$(this).hasClass('toplevel_item')) { if($('.collapsed-comments').length) { var scrolltoid = $('.collapsed-comments').attr('id').substring(19); $('#collapsed-comments-' + scrolltoid + ' .autotime').timeago(); @@ -847,9 +847,21 @@ function scrollToItem() { function collapseHeight() { $(".wall-item-content:not('.divmore_checked'), .directory-collapse:not('.divmore_checked')").each(function(i) { - var orgHeight = $(this).outerHeight(true); - var id = $(this).attr('id') - var open = ((expanded_items.indexOf($(this).attr('id')) === -1) ? false : true); + let orgHeight = $(this).outerHeight(true); + let id = (($(this).attr('id')) ? $(this).attr('id').split('wall-item-content-').pop() : 0); + let b64mid = ((typeof bParam_mid !== 'undefined') ? bParam_mid : ''); + + if (b64mid) { + // Display the selected mid in an open state + let b64mids = $('#thread-wrapper-' + id).data('b64mids'); + + if (b64mids.length && b64mids.indexOf(b64mid) !== -1) {; + expanded_items.push(id); + } + } + + let open = ((expanded_items.indexOf(id) === -1) ? false : true); + if(orgHeight > divmore_height) { if(! $(this).hasClass('divmore') && $(this).has('div.no-collapse').length == 0) { $(this).readmore({ @@ -1346,7 +1358,7 @@ function dostar(ident) { $('#starred-' + ident).removeClass('fa-star-o'); $('#star-' + ident).addClass('hidden'); $('#unstar-' + ident).removeClass('hidden'); - var btn_tpl = '<div class="btn-group" id="star-button-' + ident + '"><button type="button" class="btn btn-outline-secondary btn-sm wall-item-like" onclick="dostar(' + ident + ');"><i class="fa fa-star"></i></button></div>' + var btn_tpl = '<div class="btn-group" id="star-button-' + ident + '"><button type="button" class="btn btn-outline-secondary border-0 btn-sm wall-item-star" onclick="dostar(' + ident + ');"><i class="fa fa-star"></i></button></div>' $('#wall-item-tools-left-' + ident).prepend(btn_tpl); } else { diff --git a/view/js/mod_poke.js b/view/js/mod_poke.js deleted file mode 100644 index 88fa9f7c2..000000000 --- a/view/js/mod_poke.js +++ /dev/null @@ -1,5 +0,0 @@ -$(document).ready(function() { - $("#poke-recip").contact_autocomplete(baseurl + '/acl', 'a', false, function(data) { - $("#poke-recip-complete").val(data.id); - }); -}); |