<<  >> (p.2)
    Author Topic: User Script: Automatically remove nested quotes v1.1.1  (Read 683 times)
    EcuaMobi (OP)
    Legendary
    *
    Offline Offline

    Activity: 1904
    Merit: 1507



    View Profile
    May 28, 2019, 05:37:38 PM
    Last edit: May 31, 2019, 10:27:14 PM by EcuaMobi
    Merited by Welsh (8), Jet Cash (5), bones261 (5), suchmoon (4), DarkStar_ (4), mprep (3), minifrij (3), franckuestein (3), LoyceV (2), Avirunes (2), Xal0lex (2), Halab (2), tbct_mt2 (2), marlboroza (2), -CryptoViking- (2), TryNinja (1), mk4 (1), DdmrDdmr (1), morvillz7z (1), IeSua (1), sncc (1)
     #1

    I introduce the "Quote plus" user script.

    I always have to manually edit my post when quoting someone else and getting several nested quotes like this:

    This has also been recently discussed here.

    So I've written a small user script that removes all the extra quotes, leaving only the latest one:


    It also shows 3 links to use the whole text, only the latest quote (default), or just a "~snip~":


    Here's what the snip button does:


    Important: You should use these 3 buttons before making any editions. You may lose your work otherwise.



    To install this userscript you need to:
    Here you can see the source code: https://openuserjs.org/scripts/EcuaMobi/Quote_plus/source
    Code:
    // ==UserScript==
    // @name        Quote plus
    // @namespace   ecuamobi
    // @author      EcuaMobi
    // @include     https://bitcointalk.org/index.php?action=post;*quote=*
    // @include     https://bitcointalk.org/index.php?action=pm;sa=send;f=inbox;pmsg=*;quote;u=*
    // @version     1.1.1
    // @license   MIT
    // @grant none
    // ==/UserScript==

    (() => {
      var full_text = document.forms.postmodify.message.value;
      var regex =\[quote author/gi,
        result, indices = [];
      // Find second [quote]
      var i = 0;
      var start2 = 0;
      var end2 = 0;
      while ((result = regex.exec(full_text))) {
        i++;
        if (2 == i) {
          start2 = result.index;
          break;
        }
      }
      regex =\[\/quote\]/gi, result, indices = [];
      var last = 0;
      while ((result = regex.exec(full_text))) {
        if (last > 0) {
          end2 = last + 8;
        }
        last = result.index;
      }

      // Are there several quotes?
      if (start2 == 0 || end2 == 0) {
        // Abort
        return;
      }

      // Get text to use for every option
      var latest_quote = full_text.substr(0, start2).trim() + '\n' + full_text.substr(end2).trim() + '\n';
      var snip_quote = full_text.substr(0, start2).trim() + '~snip~[/quote]\n';
      full_text = full_text.trim() + '\n';

      // By default use the latest quote. REPLACE THIS BY snip_quote OR REMOVE IF DESIRED
      document.forms.postmodify.message.value = latest_quote;

      // Add buttons to manually use full text, latest quote or snip
      const $links = "<span style='margin-left:38%'><a id='full_text' href='#'>Full text</a> | <a id='latest_quote' href='#'>Latest quote</a> | <a id='snip_quote' href='#'>~snip~</a></span>"
      document.querySelector("textarea").insertAdjacentHTML('afterend', $links);

      document.querySelector('#full_text').addEventListener('click', function(e){
        e.preventDefault();
        document.forms.postmodify.message.value = full_text;
      });
      document.querySelector('#latest_quote').addEventListener('click', function(e){
        e.preventDefault();
        document.forms.postmodify.message.value = latest_quote;
      });
      document.querySelector('#snip_quote').addEventListener('click', function(e){
        e.preventDefault();
        document.forms.postmodify.message.value = snip_quote;
      });
    })();
      Demo:
      Capture taken on Android. It works the same on PC/Mac/Laptop.

      Notes and limitations:
      • It will not run if there are no quotes inside your quote (no nested quotes)
      • It only considers regular quotes ([ quote author=username link=...), not other simple quotes
      • It may behave strangely if the nested quote is not at the beginning or if there are several quotes mixed with inline responses. I'm still testing these scenarios
      • You should always check whether the script did a good job and click "Full text" otherwise

      Version history:
      • 1.1.1
        By minifrij. jQuery has been removed
      • 1.1
        It now works when quoting from 'Show the last posts of this person.' or a PM (more info)
      • 1.0:
        Initial release

      I'll keep testing and improving it. Let me know your comments or any bugs you find.[/list]
    Page 1
    Viewing Page: 2