MyDealz Toggle Comments

Adds functionallity to toggles cascaded comments on mydealz.de

2016-08-12 기준 버전입니다. 최신 버전을 확인하세요.

// ==UserScript==
// @name         MyDealz Toggle Comments
// @namespace    http://www.mydealz.de/profile/richi2k
// @version      0.4
// @description  Adds functionallity to toggles cascaded comments on mydealz.de 
// @author       richi2k
// @require      https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js
// @match        http://www.mydealz.de/*
// @grant        none
// ==/UserScript==


(function() {
    'use strict';

    
    // BEGIN REQUIRED ONE TIME INIT 
    // hides all quoted content except those without a header
    $(".bbcode_quote_head:not(:empty)  ~ .bbcode_quote_body").hide();

    // sets 'pointer' as cursor to indicate, that the element is clickable
    $(".bbcode_quote_head").css("cursor", "pointer");
    // END REQUIRED ONE TIME INIT
    
    $(document).on( "click",".bbcode_quote_head", function(){
        // toggles the related content area
        $(this).siblings(".bbcode_quote_body").toggle(); 
    });
    // 
    $(document).on('DOMNodeInserted DOMNodeRemoved',".comments-item", function(event) {
        if (event.type == 'DOMNodeInserted') {
            // Here we need to set the same things up, that we setup in the one time init section, 
            // because we get a new set of dom elements 
            $(this).find(".bbcode_quote_head:not(:empty)  ~ .bbcode_quote_body").hide();
            $(this).find(".bbcode_quote_head").css("cursor", "pointer");
            
        }
    });
    
})();