Quora Truncate Answer

Truncate button to shorten ans after clicking on more

Fra 04.06.2016. Se den seneste versjonen.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Quora Truncate Answer
// @namespace    http://dhyeythakore.net/
// @version      1.0
// @description  Truncate button to shorten ans after clicking on more
// @author       Dhyey Thakore
// @match        https://www.quora.com/
// @grant        none
// @require      https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    
    $(document).ready(function(){
        var startAt = 1; //to avoid more than one truncate button
        
        $(".more_link").click(function(){
            
            //selects the 3rd child of action_bar_inner,
            //if quora changes the order of comment btn change this
            var btnContainer = $(".action_bar_inner").children("[id$=link]");
            var length = btnContainer.length;
            //console.log("Length : "+length);
            for(var i= startAt;i<=length;i++){
                //console.log(i);
                //append a btn after comment btn
                $(btnContainer[i]).after("<button class='truncateBtn' >Truncate</button>");
            }
            $(".truncateBtn").click(function(){
                //console.log("pressed");
                //when 
                $("[id$=_truncated]").removeClass("hidden");
                $("[id$=_expanded]").addClass("hidden");
            });
            
            //for loop will not execute if no new que-ans is loaded via ajax
            startAt = length;
        });
        
        

    });

})();