Bitcoin Forum
August 11, 2020, 07:11:34 AM *
News: Latest Bitcoin Core release: 0.20.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: User Script: Automatically remove nested quotes v1.1.1  (Read 409 times)
EcuaMobi
Legendary
*
Offline Offline

Activity: 1820
Merit: 1429


https://Ecua.Mobi


View Profile WWW
May 28, 2019, 05:37:38 PM
Last edit: May 31, 2019, 10:27:14 PM by EcuaMobi
Merited by bones261 (5), suchmoon (4), DarkStar_ (4), mprep (3), minifrij (3), franckuestein (3), LoyceV (2), Avirunes (2), Xal0lex (2), Halab (2), tbct_mt2 (2), mk4 (1), IeSua (1), DdmrDdmr (1), morvillz7z (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]

    100% First Deposit Bonus Instant Withdrawals Best Odds 10+ Sports Since 2014 No KYC Asked Play Now
    Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
    1597129894
    Hero Member
    *
    Offline Offline

    Posts: 1597129894

    View Profile Personal Message (Offline)

    Ignore
    1597129894
    Reply with quote  #2

    1597129894
    Report to moderator
    1597129894
    Hero Member
    *
    Offline Offline

    Posts: 1597129894

    View Profile Personal Message (Offline)

    Ignore
    1597129894
    Reply with quote  #2

    1597129894
    Report to moderator
    tbct_mt2
    Hero Member
    *****
    Offline Offline

    Activity: 952
    Merit: 560


    First 100% Liquid Stablecoin Backed by Gold


    View Profile
    May 29, 2019, 03:37:26 AM
     #2

    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). 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.

    DarkStar_
    Legendary
    *
    Offline Offline

    Activity: 1778
    Merit: 2403


    Join the world-leading crypto sportsbook NOW!


    View Profile WWW
    May 29, 2019, 04:00:18 AM
    Merited by EcuaMobi (2)
     #3

    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). 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) or Tampermonkey and it will *probably* work. The former has better compatibility.

    EcuaMobi
    Legendary
    *
    Offline Offline

    Activity: 1820
    Merit: 1429


    https://Ecua.Mobi


    View Profile WWW
    May 29, 2019, 04:06:07 AM
    Last edit: May 29, 2019, 05:04:23 AM by EcuaMobi
     #4

    If you have an Android device, you can use usi (User|Unified 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 along with User|Unified Script Injector worked great! And that one is definitely a very good browser. Here's a gif demo.
    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.

    tbct_mt2
    Hero Member
    *****
    Offline Offline

    Activity: 952
    Merit: 560


    First 100% Liquid Stablecoin Backed by Gold


    View Profile
    May 29, 2019, 04:08:10 AM
    Last edit: May 29, 2019, 07:37:42 AM by tbct_mt2
     #5

    If you have an Android device, you can use usi (User|Unified 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.

    EcuaMobi
    Legendary
    *
    Offline Offline

    Activity: 1820
    Merit: 1429


    https://Ecua.Mobi


    View Profile WWW
    May 31, 2019, 09:24:41 PM
     #6

    I've realized this script didn't work when quoting from 'Show the last posts of this person' or when quoting a 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)

    suchmoon
    Legendary
    *
    Offline Offline

    Activity: 2394
    Merit: 5422


    https://bpip.org


    View Profile WWW
    May 31, 2019, 09:44:35 PM
    Merited by DarkStar_ (1)
     #7

    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.

    EcuaMobi
    Legendary
    *
    Offline Offline

    Activity: 1820
    Merit: 1429


    https://Ecua.Mobi


    View Profile WWW
    May 31, 2019, 10:00:47 PM
     #8

    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

    minifrij
    Legendary
    *
    Offline Offline

    Activity: 2240
    Merit: 1217


    In Memory of Zepher


    View Profile WWW
    May 31, 2019, 10:14:28 PM
    Merited by suchmoon (4), EcuaMobi (1), DarkStar_ (1)
     #9

    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.

    Thanks for the script EcuaMobi, it's fantastic.
    EcuaMobi
    Legendary
    *
    Offline Offline

    Activity: 1820
    Merit: 1429


    https://Ecua.Mobi


    View Profile WWW
    May 31, 2019, 10:28:28 PM
     #10

    This wasn't a huge job, so I went though and changed it.
    Thanks! I've checked and tested your code and updated the OP and the script on openuserjs.org.

    Pages: [1]
      Print  
     
    Jump to:  

    Sponsored by , a Bitcoin-accepting VPN.
    Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!