Skip to content

Instantly share code, notes, and snippets.

@dhyey35
Last active June 4, 2016 10:07
Show Gist options
  • Save dhyey35/a9536828d64b42d91eeecc3b6abb2d7e to your computer and use it in GitHub Desktop.
Save dhyey35/a9536828d64b42d91eeecc3b6abb2d7e to your computer and use it in GitHub Desktop.
Truncate answers after reading them on quora
// ==UserScript==
// @name Quora Truncate Answer
// @namespace http://dhyeythakore.net/
// @version 0.1
// @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 = 0; //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;
});
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment