Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8602327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:03:34+00:00 2026-06-12T02:03:34+00:00

I am missing something, I’m not sure why the function ‘addIcon()’ is being called

  • 0

I am missing something, I’m not sure why the function ‘addIcon()’ is being called multiple times.

Given:

<div class="ticketpostcontainer">Some text</div>
<div class="ticketpostcontainer">Some text</div>
<div class="ticketpostcontainer">Some text</div>

Using the utility function waitForKeyElements, the result is that each div element receives my “collapse icon” three times:

// ==UserScript==
// @name        Collapse Kayako Response
// @grant               Sandbox
// @namespace   http://my.chiromatrixbase.com/fisher.chiromatrix.com/collaps_div.js
// @include     http://imatrixsupport.com/*
// @require     http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js
// ==/UserScript==
/*jslint plusplus: true, undef: true, sloppy: true, vars: true, white: true, indent: 2, maxerr: 30 */

//Enable or disable GreaseMonkey function, GM_log
var GM_Debug = 1;

if (!GM_Debug) {
  var GM_log = function () {};
}
//If FireBig is active, send GM log events to FB.
if (unsafeWindow.console && GM_Debug) {
  var GM_log = unsafeWindow.console.log;
}

GM_log("Running collapse kayako response script");

//Don't run on frames or iframes.
if (window.top !== window.self) {
      return;
}

waitForKeyElements(".ticketpostcontainer", addIcon);

function addIcon() {
  var i, toCollapse = document.getElementsByClassName('ticketpostcontainer'), j = toCollapse.length;

  GM_log("Number of elements to collapse: " + toCollapse.length);

  for (i = 0; i < j; i++) {
    var curElement = toCollapse[i];

    var p = document.createElement('p');
    var a = document.createElement('a');
    var span = document.createElement('span');

    styleLink(a);
    styleParagraph(p);
    styleSpan(span);
    p.appendChild(a);
    p.appendChild(span);
    a.appendChild(document.createTextNode('-'));
    span.appendChild(document.createTextNode(' Some text'));

    a.addEventListener("click", toggle, false);

    curElement.parentNode.insertBefore(p, curElement);
  }

  function toggle(e) {
    if (this.firstChild.nodeValue === '-') {
      this.parentNode.nextSibling.style.display = 'none';
      this.firstChild.nodeValue = '+';
      this.nextSibling.style.display = 'inline';

    } else {
      this.parentNode.nextSibling.style.display = 'block';
      this.firstChild.nodeValue = '-';
      this.nextSibling.style.display = 'none';
    }
    e.preventDefault();
  }

  function styleLink(a) {
    a.href = '#';
    a.style.fontWeight = 'bold';
    a.style.background = '#F6F1E7';
    a.style.border = '1px solid #cccccc';
    a.style.color = '#B24C58';
    a.style.textDecoration = 'none';
    a.style.width = '15px';
    a.style.height = '15px';
    a.style.textAlign = 'center';
    a.style.fontSize = '100%';
    a.style.margin = '0 5px 5px 8px';
    a.style.cssFloat = 'left';
    a.style.display = 'block';
    a.style.lineHeight = '13px';
  }

  function styleParagraph(p) {
    p.style.margin = '0 0 0 0';
    p.style.lineHeight = '16px';
    p.style.clear = 'both';
    p.style.height = '15px';
  }

  function styleSpan(span) {
    span.style.display = 'none';
  }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T02:03:35+00:00Added an answer on June 12, 2026 at 2:03 am

    addIcon collapses all ticketpostcontainer elements, but waitForKeyElements will fire and run it for all three ticketpostcontainer elements. Try something like this to run it once for each:

    function addIcon($el) {
        var curElement = $el.get(0); // get DOM element
        // proceed as above but without the for loop
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Maybe im missing something but im not sure. All im simply trying to do
Hopefully I'm not missing something obvious... I'm creating a function that will ease in
I may be missing something, but I'm sure that I've checked everything, I forked
Either I am missing something or not understanding other posts/instructions. I am trying to
I'm missing something obvious I'm sure. Hoping I can explain the problem without posting
Probably missing something completely obvious here, but here goes. I'm starting out with Spring
Must be missing something really obvious here but how do you change the size
I may be missing something about the fundamentals of WPF design, but I was
I am missing something in my SQL query, could please someone advise how to
I am abviously missing something, but I keep getting this message when trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.