Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

Anonymous
Friday, May 13th, 2011 at 11:23:35am UTC 

  1. // count function
  2.  
  3. function countElement(item, array) {
  4.     var count = 0;
  5.     $.each(array, function(i, v) {
  6.         if (v === item) {
  7.             count++;
  8.         }
  9.     });
  10.     return count;
  11. }
  12.  
  13. // create array from ips in the list
  14. ipList = [];
  15. uaList = [];
  16. $('li.list').each(function(i) {
  17.     var spans = $(this).children();
  18.     spans[0] = $(spans[0]);
  19.     spans[1] = $(spans[1]);
  20.     ipList[i] = spans[0].text();
  21.     uaList[i] = spans[1].text();
  22. });
  23. // check how many for each ip
  24. $('li.list').each(function(i) {
  25.     var spans = $(this).children();
  26.     spans[0] = $(spans[0]);
  27.     spans[1] = $(spans[1]);
  28.     var ipText = $(spans[0]).text();
  29.     var uaText = $(spans[1]).text();
  30.     var count = countElement(ipText, ipList);
  31.     //if more than one update class of span
  32.     if (count > 1) {
  33.         spans[0].addClass('i' + count);
  34.     }
  35.     var countua = countElement(uaText, uaList);
  36.     //if more than one update class of span
  37.     if (countua > 1) {
  38.         spans[1].addClass('u' + count);
  39.     }
  40. });
  41.  
  42.  
  43.  
  44. <ul>
  45.     <li class="list">
  46.         <span id="ip0">127.0.0.3</span>
  47.         <span id="ua0">SonyEricssonK800i</span>
  48.     </li>
  49.     <li class="list">
  50.         <span id="ip1">127.0.0.3</span>
  51.         <span id="ua1">Nokia3120classic</span>
  52.     </li>
  53.     <li class="list">
  54.         <span id="ip2">127.0.0.1</span>
  55.         <span id="ua2">SonyEricssonW580i</span>
  56.     </li>
  57.     <li id="s3" class="list">
  58.         <span id="ip3">127.0.0.1</span>
  59.         <span id="ua3">SonyEricssonK800iv/R1KG Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1</span>
  60.     </li>
  61.     <li class="list">
  62.         <span id="ip4">127.0.0.1</span>
  63.         <span id="ua4">Nokia3120classic</span>
  64.     </li>
  65.     <li class="list">
  66.         <span id="ip5">127.0.0.2</span>
  67.         <span id="ua5">SonyEricssonW580i</span>
  68.     </li> <li class="list">
  69.     <span id="ip5">127.0.0.2</span>
  70.     <span id="ua5">SonyEricssonW580i</span>
  71.     </li>
  72.     <li class="list">
  73.         <span id="ip5">127.0.0.2</span>
  74.         <span id="ua5">SonyEricssonW580i</span>
  75.     </li>
  76.     <li class="list">
  77.         <span id="ip5">127.0.0.2</span>
  78.         <span id="ua5">SonyEricssonW580i</span>
  79.     </li>
  80.     <li class="list">
  81.         <span id="ip5">127.0.0.2</span>
  82.         <span id="ua5">SonyEricssonW580i</span>
  83.     </li>
  84.     <li class="list">
  85.         <span id="ip5">127.0.0.2</span>
  86.         <span id="ua5">SonyEricssonW580i</span>
  87.     </li>
  88. </ul>
  89.  
  90.  
  91.  
  92. .u2 {background:orange;}
  93. .u3{background:purple;}
  94. .u4{background:brown;}
  95. .u5{background:pink;}
  96. .u6{background:gray;}
  97. .i2 {background:yellow;}
  98. .i3{background:cyan;}
  99. .i4{background:green;}
  100. .i5{background:red;}
  101. .i6{background:black; color: white}

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

comments powered by Disqus
worth-right
worth-right
worth-right