Merge branch '479' of https://github.com/Haocen/PrivateBin-Contribute into Haocen-479
This commit is contained in:
commit
84827e19c3
|
@ -1711,8 +1711,58 @@ jQuery.PrivateBin = (function($, RawDeflate) {
|
||||||
*/
|
*/
|
||||||
function sendToShortener()
|
function sendToShortener()
|
||||||
{
|
{
|
||||||
window.location.href = $shortenButton.data('shortener') +
|
if ($shortenButton.hasClass('buttondisabled')) {
|
||||||
encodeURIComponent($pasteUrl.attr('href'));
|
return;
|
||||||
|
}
|
||||||
|
$.ajax({
|
||||||
|
type: 'GET',
|
||||||
|
url: `${$shortenButton.data('shortener')}${encodeURIComponent($pasteUrl.attr('href'))}`,
|
||||||
|
headers: {'Accept': 'text/html, application/xhtml+xml, application/xml, application/json'},
|
||||||
|
processData: false,
|
||||||
|
timeout: 10000,
|
||||||
|
xhrFields: {
|
||||||
|
withCredentials: false
|
||||||
|
},
|
||||||
|
success: function(response) {
|
||||||
|
let responseString = response;
|
||||||
|
if (typeof responseString === 'object') {
|
||||||
|
responseString = JSON.stringify(responseString);
|
||||||
|
}
|
||||||
|
if (typeof responseString === 'string' && responseString.length > 0) {
|
||||||
|
const shortUrlMatcher = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/g;
|
||||||
|
const shortUrl = (responseString.match(shortUrlMatcher) || []).sort(function(a, b) {
|
||||||
|
return a.length - b.length;
|
||||||
|
})[0];
|
||||||
|
if (typeof shortUrl === 'string' && shortUrl.length > 0) {
|
||||||
|
$('#pastelink').html(
|
||||||
|
I18n._(
|
||||||
|
'Your paste is <a id="pasteurl" href="%s">%s</a> <span id="copyhint">(Hit [Ctrl]+[c] to copy)</span>',
|
||||||
|
shortUrl, shortUrl
|
||||||
|
)
|
||||||
|
);
|
||||||
|
// we disable the button to avoid calling shortener again
|
||||||
|
$shortenButton.addClass('buttondisabled');
|
||||||
|
// save newly created element
|
||||||
|
$pasteUrl = $('#pasteurl');
|
||||||
|
// we pre-select the link so that the user only has to [Ctrl]+[c] the link
|
||||||
|
Helper.selectText($pasteUrl[0]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Alert.showError(
|
||||||
|
I18n._('Cannot parse response from URL shortener.')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.fail(function(data, textStatus, errorThrown) {
|
||||||
|
console.error(textStatus, errorThrown);
|
||||||
|
// we don't know why it failed, could be CORS of the external server not setup properly, in which case we follow old behavior to open it in new tab
|
||||||
|
window.open(
|
||||||
|
`${$shortenButton.data('shortener')}${encodeURIComponent($pasteUrl.attr('href'))}`,
|
||||||
|
'_blank',
|
||||||
|
'noopener, noreferrer'
|
||||||
|
)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1754,9 +1804,12 @@ jQuery.PrivateBin = (function($, RawDeflate) {
|
||||||
// and add click event
|
// and add click event
|
||||||
$pasteUrl.click(pasteLinkClick);
|
$pasteUrl.click(pasteLinkClick);
|
||||||
|
|
||||||
// shorten button
|
// delete link
|
||||||
$('#deletelink').html('<a href="' + deleteUrl + '">' + I18n._('Delete data') + '</a>');
|
$('#deletelink').html('<a href="' + deleteUrl + '">' + I18n._('Delete data') + '</a>');
|
||||||
|
|
||||||
|
// enable shortener button
|
||||||
|
$shortenButton.removeClass('buttondisabled');
|
||||||
|
|
||||||
// show result
|
// show result
|
||||||
$pasteSuccess.removeClass('hidden');
|
$pasteSuccess.removeClass('hidden');
|
||||||
// we pre-select the link so that the user only has to [Ctrl]+[c] the link
|
// we pre-select the link so that the user only has to [Ctrl]+[c] the link
|
||||||
|
@ -4688,6 +4741,10 @@ jQuery.PrivateBin = (function($, RawDeflate) {
|
||||||
|
|
||||||
TopNav.showCreateButtons();
|
TopNav.showCreateButtons();
|
||||||
Alert.hideLoading();
|
Alert.hideLoading();
|
||||||
|
history.pushState({type: 'create'}, document.title, Helper.baseUri());
|
||||||
|
|
||||||
|
// clear discussion
|
||||||
|
DiscussionViewer.prepareNewDiscussion();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4800,6 +4857,9 @@ jQuery.PrivateBin = (function($, RawDeflate) {
|
||||||
Editor.show();
|
Editor.show();
|
||||||
|
|
||||||
TopNav.showCreateButtons();
|
TopNav.showCreateButtons();
|
||||||
|
|
||||||
|
// clear discussion
|
||||||
|
DiscussionViewer.prepareNewDiscussion();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -71,7 +71,7 @@ if ($MARKDOWN):
|
||||||
endif;
|
endif;
|
||||||
?>
|
?>
|
||||||
<script type="text/javascript" data-cfasync="false" src="js/purify-1.0.11.js" integrity="sha512-p7UyJuyBkhMcMgE4mDsgK0Lz70OvetLefua1oXs1OujWv9gOxh4xy8InFux7bZ4/DAZsTmO4rgVwZW9BHKaTaw==" crossorigin="anonymous"></script>
|
<script type="text/javascript" data-cfasync="false" src="js/purify-1.0.11.js" integrity="sha512-p7UyJuyBkhMcMgE4mDsgK0Lz70OvetLefua1oXs1OujWv9gOxh4xy8InFux7bZ4/DAZsTmO4rgVwZW9BHKaTaw==" crossorigin="anonymous"></script>
|
||||||
<script type="text/javascript" data-cfasync="false" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-8n4HbSmQC++v3AfA2nqlueUp3RkfeU7POcpga+yS4Rlz95G+paRjMmw5B+3HAC7TlswME16n0wIxHD1dkScC8A==" crossorigin="anonymous"></script>
|
<script type="text/javascript" data-cfasync="false" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-kQMNNeXI+TANiKlYOXFhSIpjoNl8++VpBHLsXMlCH4GTBLFc3cWSGo9ZbOSzctTZn3HFlnAfbOjvuK/qmRbWDA==" crossorigin="anonymous"></script>
|
||||||
<!--[if IE]>
|
<!--[if IE]>
|
||||||
<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;}</style>
|
<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;}</style>
|
||||||
<![endif]-->
|
<![endif]-->
|
||||||
|
|
|
@ -49,7 +49,7 @@ if ($MARKDOWN):
|
||||||
endif;
|
endif;
|
||||||
?>
|
?>
|
||||||
<script type="text/javascript" data-cfasync="false" src="js/purify-1.0.11.js" integrity="sha512-p7UyJuyBkhMcMgE4mDsgK0Lz70OvetLefua1oXs1OujWv9gOxh4xy8InFux7bZ4/DAZsTmO4rgVwZW9BHKaTaw==" crossorigin="anonymous"></script>
|
<script type="text/javascript" data-cfasync="false" src="js/purify-1.0.11.js" integrity="sha512-p7UyJuyBkhMcMgE4mDsgK0Lz70OvetLefua1oXs1OujWv9gOxh4xy8InFux7bZ4/DAZsTmO4rgVwZW9BHKaTaw==" crossorigin="anonymous"></script>
|
||||||
<script type="text/javascript" data-cfasync="false" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-8n4HbSmQC++v3AfA2nqlueUp3RkfeU7POcpga+yS4Rlz95G+paRjMmw5B+3HAC7TlswME16n0wIxHD1dkScC8A==" crossorigin="anonymous"></script>
|
<script type="text/javascript" data-cfasync="false" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-kQMNNeXI+TANiKlYOXFhSIpjoNl8++VpBHLsXMlCH4GTBLFc3cWSGo9ZbOSzctTZn3HFlnAfbOjvuK/qmRbWDA==" crossorigin="anonymous"></script>
|
||||||
<!--[if IE]>
|
<!--[if IE]>
|
||||||
<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;}</style>
|
<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;}</style>
|
||||||
<![endif]-->
|
<![endif]-->
|
||||||
|
|
Loading…
Reference in New Issue