More UI part2

The second part to The GT UI+

目前為 2015-08-27 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name More UI part2
  3. // @namespace http://use.i.E.your.homepage/
  4. // @version 1.0.2
  5. // @description The second part to The GT UI+
  6. // @match http://www.ghost-trappers.com/fb/camp.php*
  7. // @match http://www.ghost-trappers.com/fb/hunt.php*
  8. // @copyright 2015+, GTNoAPI
  9. // @grant GM_xmlhttpRequest
  10. // ==/UserScript==
  11.  
  12. initUIv2();
  13.  
  14. function initUIv2(){
  15. GM_xmlhttpRequest({
  16. method: 'GET',
  17. url: 'https://gtnoapi.herokuapp.com/api/ghosts',
  18. headers: {
  19. "Accept": "application/json",
  20. "Pragma": "no-cache",
  21. "Cache-Control": "no-cache"
  22. },
  23. onload: function(rD) {
  24. $('.logText').each(function(){
  25. var ghostEncounter = $(this).find('a').html();
  26. var ghostInfo = getGhostByName(ghostEncounter, rD.response);
  27. if(ghostEncounter && ghostEncounter == ghostInfo.name){
  28. var perantEle;
  29. var childEle;
  30. if(ghostInfo.loot){
  31.  
  32. var arrow= $('<div></div>').css({
  33. 'width': '0' ,
  34. 'height': '0',
  35. 'border-top': '10px solid transparent',
  36. 'border-bottom': '10px solid transparent',
  37. 'border-left': '10px solid #223341',
  38. 'position': 'absolute',
  39. 'top': '10px',
  40. 'right': '-10px',
  41. })
  42.  
  43. childEle = $('<span></span>').css({
  44. 'position': 'absolute',
  45. 'top': '-14px',
  46. 'right': '40px',
  47. 'z-index': '9999999',
  48. 'font-size': '14px',
  49. 'display': 'none',
  50. 'background-color': '#223341',
  51. 'border': '1px solid #222',
  52. 'border-radius': '7px',
  53. 'padding': '10px',
  54. 'min-width': '150px'
  55.  
  56. }).html(ghostInfo.loot);
  57.  
  58.  
  59. perantEle = $('<div>?</div>').css({
  60. 'cursor':'pointer',
  61. 'padding': '1px 4.5px',
  62. 'border-radius': '50%',
  63. 'background-color': 'black',
  64. 'color': 'white',
  65. 'float': 'right',
  66. 'font-weight': 'bold',
  67. 'position': 'relative'
  68. });
  69.  
  70.  
  71. perantEle.hover(function(){
  72. if(childEle.css('display')=='none'){
  73. childEle.show();
  74. }
  75. else{
  76. childEle.hide();
  77. }
  78. });
  79.  
  80. arrow.appendTo(childEle);
  81. childEle.appendTo(perantEle)
  82. }
  83.  
  84.  
  85.  
  86.  
  87. $(this).append(perantEle);
  88. }
  89. });
  90. }
  91. });
  92. };
  93.  
  94.  
  95. function getGhostByName(name, jsonTxt){
  96. var obj = jQuery.parseJSON(jsonTxt);
  97. var result = '';
  98. for(var x = 0; x < obj.length; x++){
  99. if(obj[x].name == name){
  100. var title = '';
  101. for(var y = 0; y < obj[x].loot.length; y++){
  102. title += obj[x].loot[y] + '<br />';
  103. }
  104. result = {
  105. 'name':obj[x].name,
  106. 'loot':title,
  107. 'type':obj[x].type
  108. }
  109. }
  110. }
  111. return result;
  112. }