MyDealz Toggle Comments

Adds functionallity to toggles cascaded comments on mydealz.de

当前为 2016-08-16 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name MyDealz Toggle Comments
  3. // @namespace http://www.mydealz.de/profile/richi2k
  4. // @version 0.5
  5. // @description Adds functionallity to toggles cascaded comments on mydealz.de
  6. // @author richi2k
  7. // @require https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js
  8. // @match http://www.mydealz.de/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // BEGIN REQUIRED ONE TIME INIT
  16. // hides all quoted content except those without a header
  17. $(".bbcode_quote_head:not(:empty) ~ .bbcode_quote_body").hide();
  18.  
  19. // sets 'pointer' as cursor to indicate, that the element is clickable
  20. $(".bbcode_quote_head").css("cursor", "pointer").each(function(){
  21. var onlyText = $(this).siblings(".bbcode_quote_body").clone() //clone the element
  22. .children() //select all the children
  23. .remove() //remove all the children
  24. .end() //again go back to selected element
  25. .text(); //get the text of element
  26. $(this).text($(this).text() + " - " + onlyText.substring(0,80) + " [...]" );
  27. });
  28. // END REQUIRED ONE TIME INIT
  29. $(document).on( "click",".bbcode_quote_head", function(){
  30. // toggles the related content area
  31. $(this).siblings(".bbcode_quote_body").toggle();
  32. });
  33. //
  34. $(document).on('DOMNodeInserted DOMNodeRemoved',".comments-item", function(event) {
  35. if (event.type == 'DOMNodeInserted') {
  36. // Here we need to set the same things up, that we setup in the one time init section,
  37. // because we get a new set of dom elements
  38. if($(this).hasClass("comments-item")){
  39. $(this).find(".bbcode_quote_head:not(:empty) ~ .bbcode_quote_body").hide();
  40. $(this).find(".bbcode_quote_head").css("cursor", "pointer");
  41. }
  42. }
  43. });
  44. })();