「Forumeiros」 Aviso Dual-Post 23.10.17 19:42
Olá,
Vim aqui disponibilizar um script que identifica dual-post e o evita mesclando a nova mensagem com a última, não o criei, adicionei-lhe mínimos detalhes de forma a aperfeiçoar seu desempenho:
Vim aqui disponibilizar um script que identifica dual-post e o evita mesclando a nova mensagem com a última, não o criei, adicionei-lhe mínimos detalhes de forma a aperfeiçoar seu desempenho:
- Código:
$(function() {
if (!_userdata.session_logged_in) {
return false
}
var lastposting,link;
$.get(location.pathname+"?view=newest",function(d){
lastposting = $('.post:last',d).find('.author a, .name, .user a[href^="/u"]').text();
if(lastposting ==undefined ||lastposting == null) {return false; alert("Falha ao encontrar o último post");}
link = $('.post:last a[href*="mode=editpost"]',d).attr('href');
if(link==undefined||link==null){return false;}
var user = _userdata.username;
if (lastposting == user) {
$('head').append('<style type="text/css">' + '.warn_merge {' + ' padding: 10px;' + ' line-height: 1.6;' + ' font-size: 12px;' + ' color: #00529B;' + ' background-color: #BDE5F8;' + ' text-shadow: 0 1px 0 rgba(255,255,255,0.5);' + '}' + '</style>');
var text = '<div class="warn_merge" id="novasmsg">Nosso sistema identificou que você fez a última postagem deste tópico, seu novo post será mesclado com o seu último.</div>';
var quickreply = $('#quick_reply');
quickreply.prepend(text);
quickreply.find('input[name="post"]').click(function(d) {
d.preventDefault();
$("#novasmsg").text("Mesclando mensagem...");
var newValue = $('#text_editor_textarea').sceditor('instance').val();
$.get(link, function(e) {
if (!$.trim(newValue)) {
alert("Seu post está vazio")
} else {
var currentValue = $(e).find('#text_editor_textarea').val(),
title = $(e).find('input[name="subject"]').val();
console.log(title)
if ($.trim(title)) {
title = title
} else {
title = ''
}
$.post(link, {
'message': currentValue + '\n\n[hr]\n' + newValue,
'post': '1',
'subject': title,
'tid':$('input[name="tid"]').val()
}, function(e) {
$("#novasmsg").text("Mesclando com suceso. Redirecionando...");
var href = $(e).find('a[href^="/viewtopic"]').attr('href');
document.title = "Redirecionando...";
location.href = href;
})
}
})
})
}
});
});