Ghost Trappers - Ghost Counter

To be used with the Ghost Trappers Facebook game. This script will count the total number of ghosts a player has caught and places the information in their profile page.

当前为 2014-08-07 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Ghost Trappers - Ghost Counter
  3. // @author Rani Kheir
  4. // @namespace https://greasyfork.org/users/4271-rani-kheir
  5. // @version 1.0
  6. // @description To be used with the Ghost Trappers Facebook game. This script will count the total number of ghosts a player has caught and places the information in their profile page.
  7. // @include *ghost-trappers.com/fb/profiletab/index_intern.php?fbid=*
  8. // @icon http://i44.photobucket.com/albums/f36/Rani-Kheir/ghosticon_zpsc395e1ce.png
  9. // @copyright 2014+, Rani Kheir
  10. // ==/UserScript==
  11.  
  12. var countGhosts = document.getElementsByClassName('ghostCount').length;
  13. var countGhostsTotal = 0;
  14. var i;
  15.  
  16. for ( i = 0; i < countGhosts; i++ ) {
  17. var singleGhostCount = document.getElementsByClassName('ghostCount')[i].innerHTML.replace( /[^\d.]/g, '' );
  18. singleGhostCountInt = parseInt(singleGhostCount, 10);
  19. countGhostsTotal += singleGhostCountInt;
  20. }
  21.  
  22. function addCommas(nStr) {
  23. nStr += '';
  24. var x = nStr.split('.');
  25. var x1 = x[0];
  26. var x2 = x.length > 1 ? '.' + x[1] : '';
  27. var rgx = /(\d+)(\d{3})/;
  28. while (rgx.test(x1)) {
  29. x1 = x1.replace(rgx, '$1' + ',' + '$2');
  30. }
  31. return x1 + x2;
  32. }
  33.  
  34. var contentToEdit = document.getElementsByClassName('profileBoxData')[0].innerHTML.split("<b>Location:</b>");
  35. var contentEdited = contentToEdit.join("<b>Total ghosts caught: </b>" + addCommas(countGhostsTotal) + "<br><b>Location:</b>");
  36. document.getElementsByClassName('profileBoxData')[0].innerHTML = contentEdited;
  37.  
  38. //document.getElementsByClassName('profileBoxData')[0].innerHTML = document.getElementsByClassName('profileBoxData')[0].innerHTML + "<b>Total ghosts caught: </b>" + addCommas(countGhostsTotal);
  39. //alert(countGhostsTotal);