Quora Truncate Answer

Truncate button to shorten ans after clicking on more

当前为 2016-06-04 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Quora Truncate Answer
  3. // @namespace http://dhyeythakore.net/
  4. // @version 1.0
  5. // @description Truncate button to shorten ans after clicking on more
  6. // @author Dhyey Thakore
  7. // @match https://www.quora.com/
  8. // @grant none
  9. // @require https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Your code here...
  16. $(document).ready(function(){
  17. var startAt = 0; //to avoid more than one truncate button
  18. $(".more_link").click(function(){
  19. //selects the 3rd child of action_bar_inner,
  20. //if quora changes the order of comment btn change this
  21. var btnContainer = $(".action_bar_inner").children("[id$=link]");
  22. var length = btnContainer.length;
  23. //console.log("Length : "+length);
  24. for(var i= startAt;i<=length;i++){
  25. //console.log(i);
  26. //append a btn after comment btn
  27. $(btnContainer[i]).after("<button class='truncateBtn' >Truncate</button>");
  28. }
  29. $(".truncateBtn").click(function(){
  30. //console.log("pressed");
  31. //when truncate is clicked hidden class is added to expanded
  32. //answer and removed from truncated answer
  33. $("[id$=_truncated]").removeClass("hidden");
  34. $("[id$=_expanded]").addClass("hidden");
  35. });
  36. //for loop will not execute if no new que-ans is loaded via ajax
  37. startAt = length;
  38. });
  39.  
  40. });
  41.  
  42. })();