Citar/Copiar rápido em mensagens

Ver o tópico anterior Ver o tópico seguinte Ir para baixo

Principal Contribuidor

Citar/Copiar rápido em mensagens Empty Citar/Copiar rápido em mensagens

Mensagem por Shek 02.06.24 21:55

Olá pessoal. Feliz aniversário

Baseado numa ideia arquivada no suporte em inglês, eu atualizei e encontrei uma solução que acredito ser do interesse de todos vocês. Muito feliz Esta versão funciona para todas as versões se aplicada sem modificar nada (exceto fóruns com modelos alterados). Se o seu modelo de fórum não for o padrão, crie uma pergunta de suporte referenciando este tópico: Questões sobre códigos Thumbleft

Você pode aplicar com Investimento para os Tópicos:
Código:
$(document).ready(function() {
  var selectedText = '';
  var floatingMenu = $('<div id="floating-menu" class="button2" style="position: absolute; background: white; border: 1px solid #ccc; padding: 10px;">' + '<button id="cite-text" class="button2">Cite this part</button>' + '<button id="copy-text" class="button2">Copy this part</button>' + '</div>');
  $(document).on('mouseup', function(e) {
      var selection = window.getSelection();
      selectedText = selection.toString().trim();
      /** FA_VERSION >>
        Reference topic: https://help.forumotion.com/t163423-topic
        "The code works as standard for all versions. A div appears in the selected part of the text in the body of any message. In addition, there is a button to copy the message, if you wish."
        phpBB2:              table.forumline div.postbody
        phpBB3 & ModernBB:      div.postbody div.content
        punBB:              div.postbody div.entry-content
        Invision:            div.post-container div.postbody
        AwesomeBB:            div.post-body div.post-content
      **/
      if($(e.target).closest('table.forumline div.postbody,div.postbody div.content,div.postbody div.entry-content,div.post-container div.postbody,div.post-body div.post-content').length) {
        if($('#floating-menu').css('display') == 'none') {
            $('#floating-menu').remove();
        }
        if(selectedText && !selection.isCollapsed && $('#floating-menu').length == false) {
            localStorage.setItem('selectedText', selectedText);
            floatingMenu.css({
              top: e.pageY + 'px',
              left: e.pageX + 'px'
            }).appendTo('body').show();
        } else if(!selection.isCollapsed && window.getSelection().focusNode.parentNode !== '#floating-menu' && $('#floating-menu').css('display') == 'block') {
            return true;
        } else {
            $('#floating-menu').hide();
        }
      }
  });
    $(document).on('click', '#copy-text', function() {
      if($('#floating-menu').css('display') == 'none') {
        $('#floating-menu').remove();
      }
        navigator.clipboard.writeText(selectedText).then(function() {
            window.getSelection().removeAllRanges();
        $('#floating-menu').remove();
        }).catch(function(err) {
            alert('Falha ao copiar o texto: ' + err);
        });
    });
    $(document).on('click', '#cite-text', function() {
        var storedText = localStorage.getItem('selectedText');
      var checkText = $('#text_editor_textarea').sceditor('instance').val().toString().trim();
        if (storedText && checkText == '') {
        $('#text_editor_textarea').sceditor('instance').insertText('[quote]' + storedText + '[/quote]','');
        window.getSelection().removeAllRanges();
      } else {
        $('#text_editor_textarea').sceditor('instance').insertText('\n[quote]' + storedText + '[/quote]','');
        window.getSelection().removeAllRanges();
      }
      localStorage.removeItem('selectedText');
    });
});
O resultado:
Citar/Copiar rápido em mensagens Screen70

Fique livre para sugerir atualizações. Piscada
Shek

Shek
Principal Contribuidor
Principal Contribuidor

Membro desde : 11/04/2009
Mensagens : 18956
Pontos : 22885

https://shiftactive.blogspot.com/ https://www.facebook.com/ShiftActif https://twitter.com/ShiftActif

Ir para o topo Ir para baixo

Ver o tópico anterior Ver o tópico seguinte Ir para o topo

- Tópicos semelhantes

Permissões neste sub-fórum
Não podes responder a tópicos