Bitcoin Forum

Other => Meta => Topic started by: EcuaMobi on May 28, 2019, 05:37:38 PM



Title: User Script: Automatically remove nested quotes v1.1.1
Post by: EcuaMobi on May 28, 2019, 05:37:38 PM
I introduce the "Quote plus" user script (https://openuserjs.org/install/EcuaMobi/Quote_plus.user.js).

I always have to manually edit my post when quoting someone else and getting several nested quotes like this:
https://i.imgur.com/ao9kNFw.jpg
This has also been recently discussed here (https://bitcointalk.org/index.php?topic=5148084.0).

So I've written a small user script that removes all the extra quotes, leaving only the latest one:
https://i.imgur.com/3rRwsYD.jpg

It also shows 3 links to use the whole text, only the latest quote (default), or just a "~snip~":
https://i.imgur.com/S0Po89H.jpg

Here's what the snip button does:
https://i.imgur.com/byxzZIY.jpg

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



To install this userscript you need to:
  • Install Tampermonkey on Chrome, Greasemonkey on Firefox, or Violentmonkey on Opera (Read more here: https://openuserjs.org/about/Userscript-Beginners-HOWTO)
    On mobile, install Firefox for Android (https://play.google.com/store/apps/details?id=org.mozilla.firefox) and User|Unified Script Injector (https://addons.mozilla.org/en-US/android/addon/userunified-script-injector/)
  • Install this user script: https://openuserjs.org/scripts/EcuaMobi/Quote_plus
  • Make sure it's enabled and quote any post that already has a nested quote.
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 (http://qr.ai/i/cil0pfhieiqab6wd.gif). 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 (https://bitcointalk.org/index.php?topic=5148327.msg51300904#msg51300904). jQuery has been removed
    • 1.1
      It now works when quoting from 'Show the last posts of this person.' or a PM (more info (https://bitcointalk.org/index.php?topic=5148327.msg51300520#msg51300520))
    • 1.0:
      Initial release

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


    Title: Re: User Script: Automatically remove nested quotes
    Post by: tbct_mt2 on May 29, 2019, 03:37:26 AM
    Excellent script. I added the topic in my guide for interests of users who don't want to do pyramid quotes. [TIPS] to avoid pyramid quotes (for Newbies) (https://bitcointalk.org/index.php?topic=3749076.0). One question, can I use the script on mobile devices? If yes, how to use it? Most of time, when I am on mobile devices, I don't want to spend my time to delete unused parts inside quote blocks, but I usually come back later (when I am on computers or laptops) to edit such pyramid quotes. However, I doubt that other users often spend their time to do it.


    Title: Re: User Script: Automatically remove nested quotes
    Post by: DarkStar_ on May 29, 2019, 04:00:18 AM
    Excellent script. I added the topic in my guide for interests of users who don't want to do pyramid quotes. [TIPS] to avoid pyramid quotes (for Newbies) (https://bitcointalk.org/index.php?topic=3749076.0). One question, can I use the script on mobile devices? If yes, how to use it? Most of time, when I am on mobile devices, I don't want to spend my time to delete unused parts inside quote blocks, but I usually come back later (when I am on computers or laptops) to edit such pyramid quotes. However, I doubt that other users often spend their time to do it.

    If you have an Android device, you can use usi (User|Unified Script Injector) (https://addons.mozilla.org/en-US/android/addon/userunified-script-injector/) or Tampermonkey and it will *probably* work. The former has better compatibility.


    Title: Re: User Script: Automatically remove nested quotes
    Post by: EcuaMobi on May 29, 2019, 04:06:07 AM
    If you have an Android device, you can use usi (User|Unified Script Injector) (https://addons.mozilla.org/en-US/android/addon/userunified-script-injector/) or Tampermonkey and it will *probably* work. The former has better compatibility.
    I tested this script with Tampermonkey for Android (https://play.google.com/store/apps/details?id=net.biniok.tampermonkey) and it definitely works. However it's not really a very good browser, at least on Android 9.
    I'm checking the other one.

    Update:
    Firefox for Android (https://play.google.com/store/apps/details?id=org.mozilla.firefox) along with User|Unified Script Injector (https://addons.mozilla.org/en-US/android/addon/userunified-script-injector/) worked great! And that one is definitely a very good browser. Here's a gif demo (http://qr.ai/i/cil0pfhieiqab6wd.gif).
    I'm updating OP to suggest this for Android.



    By the way, due to the topic title, I would like to raise a minor discussion on the term: pyramid quote or nested quote, which one should officially used?
    I know that they have nearly same implications, but global moderator officially mentioned the type of posting style as pyramid quote, I think we should use only one term here to mention about it: Pyramid quotes.
    Any ideas?
    I thought nested quotes was the generic name, while pyramid quotes was used only when several (5+ or so) quotes are nested so the whole thing looks like a pyramid seen from above. (https://bitcointalk.org/index.php?topic=5148084.msg51252226#msg51252226)


    Title: Re: User Script: Automatically remove nested quotes
    Post by: tbct_mt2 on May 29, 2019, 04:08:10 AM
    If you have an Android device, you can use usi (User|Unified Script Injector) (https://addons.mozilla.org/en-US/android/addon/userunified-script-injector/) or Tampermonkey and it will *probably* work. The former has better compatibility.
    Thanks for your guided steps, I might try them later just for curious, because I would prefer to do most of things on computers or laptops, not on mobile devices. I asked this for lazy guys whom usually pyramid-quoting, and blame on their mobile devices.
    By the way, due to the topic title, I would like to raise a minor discussion on the term: pyramid quote or nested quote, which one should officially used?
    I know that they have nearly same implications, but global moderator officially mentioned the type of posting style as pyramid quote, I think we should use only one term here to mention about it: Pyramid quotes.
    Any ideas?
    1. No zero or low value, pointless or uninteresting posts or threads. [1][e]

    ~snip~

    1. Such posts as "SELL SELL SELL", "I agree", "+1", "Support", "Watching", "Interesting", "LOL", "SCAM", "LEGIT", "FAKE", other one word posts, posts consisting mostly of swearing, quote pyramids, useless introduction threads, threads about a topic already recently discussed in several other threads.


    Title: Re: User Script: Automatically remove nested quotes
    Post by: EcuaMobi on May 31, 2019, 09:24:41 PM
    I've realized this script didn't work when quoting from 'Show the last posts of this person (https://bitcointalk.org/index.php?action=profile;sa=showPosts)' or when quoting a PM (https://bitcointalk.org/index.php?action=pm).
    The script has been updated to version 1.1 to fix this.

    If you prefer not to use it on personal messages, just remove this line:
    Code:
    // @include     https://bitcointalk.org/index.php?action=pm;sa=send;f=inbox;pmsg=*;quote;u=*
    (However it's completely safe as of course everything happens on your own browser. I'd appreciate if someone can audit the code)


    Title: Re: User Script: Automatically remove nested quotes
    Post by: suchmoon on May 31, 2019, 09:44:35 PM
    I'd appreciate if someone can audit the code

    FWIW I have reviewed the code and it appears to be safe - doesn't attempt to send your PMs anywhere, or steal your netflix account, or flirt with your spouse.

    I would recommend getting rid of jQuery though. You're already using querySelector in one spot so you can replace the jQuery stuff with plain DOM calls I think.


    Title: Re: User Script: Automatically remove nested quotes
    Post by: EcuaMobi on May 31, 2019, 10:00:47 PM
    I would recommend getting rid of jQuery though. You're already using querySelector in one spot so you can replace the jQuery stuff with plain DOM calls I think.
    Thanks. I'll check that when I have some time


    Title: Re: User Script: Automatically remove nested quotes
    Post by: minifrij on May 31, 2019, 10:14:28 PM
    I would recommend getting rid of jQuery though. You're already using querySelector in one spot so you can replace the jQuery stuff with plain DOM calls I think.
    This wasn't a huge job, so I went though and changed it (https://paste.ee/p/diHzk).

    Thanks for the script EcuaMobi, it's fantastic.


    Title: Re: User Script: Automatically remove nested quotes
    Post by: EcuaMobi on May 31, 2019, 10:28:28 PM
    This wasn't a huge job, so I went though and changed it (https://paste.ee/p/diHzk).
    Thanks! I've checked and tested your code and updated the OP and the script on openuserjs.org (https://openuserjs.org/scripts/EcuaMobi/Quote_plus).


    Title: Re: User Script: Automatically remove nested quotes v1.1.1
    Post by: -CryptoViking- on August 20, 2020, 11:07:40 PM
    I was searching for the famous ~snip~ as I saw other people use it and managed to find your thread and script. So I made a mini guide on Croatian section on how to install and use it, based on your topic, to help people like me who are frustrated on mobile devices and don't have an idea that ~snip~ exists in automated form.

    What surprised me was the amount of people that are long term members and had same frustrations like I did with deleting obsolete quotes of quotes manually and didn't even know about the existence of this script.

    So firstly thanks to all who helped making this script and secondly I have a suggestion based on my recent experience and findings.

    Why not put this topic in Beginners section to help new members from the get go and maybe stick it. If I didn't dig through forum I would still be a frustrated young forum member :D