More UI part3

The third part to The GT UI+

当前为 2015-09-18 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name More UI part3
  3. // @namespace http://use.i.E.your.homepage/
  4. // @version 1.0.2.1
  5. // @description The third 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. initUIv3();
  13.  
  14. function initUIv3(){
  15. GM_xmlhttpRequest({
  16. method: 'GET',
  17. url: 'http://www.ghost-trappers.com/fb/scotch_ninth_floor.php?page=exhibition&currentPage=-2',
  18. headers: {
  19. "Accept": "text/html",
  20. "Pragma": "no-cache",
  21. "Cache-Control": "no-cache"
  22. },
  23. onload: function(rD) {
  24. var text = rD.responseText;
  25.  
  26. $('<div class="UserSricpt_exhibition_container"></div>').appendTo('#header');
  27. $('<div class="exhibition_container"></div>').appendTo('.UserSricpt_exhibition_container');
  28. var container = $('.exhibition_container');
  29. $('.UserSricpt_exhibition_container').css('position','absolute');
  30. $('.UserSricpt_exhibition_container').css('top','150%');
  31. $('.UserSricpt_exhibition_container').css('left','-27%');
  32. $('.UserSricpt_exhibition_container').css('color','#fff');
  33. var rgx = text.match(/<div class="souvenirPartsLine " >[\s\nA-Za-z0-9<=>"'\/_.?!]*<\/div>/gi);
  34. var array = [];
  35. var temp = stringRep(text);
  36. for(var x = 0; x< rgx.length; x++){
  37. var rgxImg = rgx[x].match(/src(.*)\w/gi);
  38. array[x] = [];
  39.  
  40. ($('<a href="http://www.ghost-trappers.com/fb/scotch_ninth_floor.php?page=exhibition&currentPage=-2" class="exhibition-collection" id="exhibition-collection-'+x+'"></a>')
  41. .css('position', 'relative'))
  42. .appendTo(container);
  43. var item_container = $('#exhibition-collection-'+x);
  44. if(x < rgx.length-1){
  45. for(var y=0; y < rgxImg.length-1; y++){
  46. ($('<img '+ rgxImg[y] + '" data-target="'+x+'_'+y+'"/>')
  47. .css('width', '10%'))
  48. .appendTo(item_container);
  49. ($('<div id="'+x+'_'+y+'"></div>').css({
  50. 'position': 'absolute',
  51. 'z-index': '9999999',
  52. 'font-size': '14px',
  53. 'display': 'none',
  54. 'background-color': '#223341',
  55. 'border': '1px solid #222',
  56. 'border-radius': '7px',
  57. 'padding': '10px',
  58. 'min-width': '150px'
  59. }))
  60. .appendTo(item_container);
  61. }
  62. }
  63. else{
  64. for(var y=0; y < rgxImg.length; y++){
  65. ($('<img '+ rgxImg[y] + '"/>').css('width', '10%'))
  66. .appendTo(item_container);
  67. }
  68. }
  69. }
  70. $('.UserSricpt_exhibition_container').find('.exhibition-collection').css({
  71. 'display':'block',
  72. 'color':'white',
  73. 'position':'relative',
  74. 'padding':'10px',
  75. 'margin-top':'10px',
  76. 'border-radius':'15px',
  77. 'font-size':'14px',
  78. 'width':'607px',
  79. 'z-index': '9999',
  80. 'display': 'none'
  81. });
  82. container.css({
  83. 'position': 'absolute',
  84. 'left' : '183px',
  85. 'top': '-89px',
  86. 'background-color': 'rgba(0, 0, 0, 0.6)',
  87. 'z-index': '999'
  88. });
  89. $('.UserSricpt_exhibition_container').prepend($('<button>toggle exhibition</button>'));
  90. var button = $('.UserSricpt_exhibition_container').find('button');
  91.  
  92. button.css({
  93. 'position':'absolute',
  94. 'left':'0px',
  95. 'color': 'white',
  96. 'font-weight':'bold',
  97. 'font-size': '16px',
  98. 'text-shadow': '1px 1px black',
  99. 'padding': '3px 8px',
  100. 'border': '1px solid rgb(206, 174, 7)',
  101. 'border-radius':'5px',
  102. 'background-color': 'gold',
  103. 'z-index': '99999999',
  104. 'width': '153px'
  105. });
  106.  
  107. button[0].addEventListener("click", function(){
  108.  
  109. if($('.UserSricpt_exhibition_container').find('.exhibition-collection').css('display') == 'none'){
  110. $('.UserSricpt_exhibition_container').find('.exhibition-collection').css({
  111. 'display': 'block'
  112. });
  113. }
  114. else{
  115. $('.UserSricpt_exhibition_container').find('.exhibition-collection').css({
  116. 'display': 'none'
  117. });
  118. }
  119. });
  120. }
  121. });
  122. GM_xmlhttpRequest({
  123. method: 'GET',
  124. url: 'https://gtnoapi.herokuapp.com/api/ghosts',
  125. headers: {
  126. "Accept": "application/json",
  127. "Pragma": "no-cache",
  128. "Cache-Control": "no-cache"
  129. },
  130. onload: function(rD) {
  131. $('.exhibition-collection').each(function(){
  132. var ghostEncounter = $(this).find('img');
  133. ghostEncounter.each(function(){
  134. var link = $(this).attr('src');
  135. var label = $(this).next('div');
  136. var item = link.substr(link.lastIndexOf('/')+1, link.length - link.lastIndexOf('/')-5);
  137. item = item.replace(/_/ig,' ');
  138. if(item.indexOf('04') != -1){
  139. item = item.substr(3);
  140. }
  141. if(item.lastIndexOf('grey') != -1){
  142. item = item.substr(0, item.lastIndexOf('grey')-1);
  143. }
  144.  
  145. var obj = jQuery.parseJSON(rD.response);
  146. var result = [];
  147. for(var x = 0; x < obj.length; x++){
  148. result.push(new Ghost(obj[x].name, obj[x].type, obj[x].location, obj[x].loot));
  149. }
  150. for(var x = 0; x < result.length; x++){
  151. for(var y = 0; y<result[x].getLoot().length; y++){
  152. if(result[x].getLoot()[y].toLowerCase() == item){
  153. label.html(result[x].getName() + '<br />' +
  154. 'type: ' + result[x].getType()[0] +(result[x].getType()[1] ? ', '+ result[x].getType()[1]: '') + (result[x].getType()[2] ? ', '+ result[x].getType()[2]: '')+ '<br />'+
  155. 'location: ' + result[x].getLocation()[0] +(result[x].getLocation()[1] ? ', '+ result[x].getLocation()[1]: '') + (result[x].getLocation()[2] ? ', '+ result[x].getLocation()[2]: '')
  156. );
  157. }
  158. }
  159. }
  160. $(this).hover(function(e){
  161. var parentOffset = $(this).offset();
  162. var relX = e.pageX - 570;
  163. var relY = -20;
  164. if(label.html() && label.css('display') == 'none'){
  165. $(this).next('div')
  166. .show()
  167. .css({
  168. 'top':relY,
  169. 'left': relX
  170. });
  171. }
  172. else{
  173. $(this).next('div').hide();
  174. }
  175. })
  176. });
  177. });
  178. }
  179. });
  180. }
  181.  
  182.  
  183. function stringRep(text){
  184. var rgx = text.match(/<div class="souvenirSetContainer" >(\n(.*?))*.?(<div class="seperatorLine">)/gi);
  185. var array = [];
  186. for(var x = 0; x < rgx.length; x++){
  187. var name = rgx[x].match(/<div class="souvenirTopLeft">(\n(.*?))*.?(<\/img>)/gi);
  188. name = name[0].substr(name[0].indexOf('souvenirs')+'souvenirs'.length+1, (name[0].lastIndexOf('"')-(name[0].indexOf('souvenirs')+'souvenirs'.length+5)));
  189. if(name.indexOf('04_headline') > -1){
  190. name = name.substr(name.indexOf('04_headline')+'04_headline'.length+1);
  191. }
  192. else if(name.indexOf('headline') > -1){
  193. name = name.substr(name.indexOf('headline')+'headline'.length+1);
  194. }
  195. name = name.replace(/_/ig,' ');
  196. array.push(name);
  197. }
  198. return array;
  199. }
  200.  
  201. var Ghost = function(name, type, location, loot) {
  202. this.name = name;
  203. this.type = type;
  204. this.location = location;
  205. this.loot = loot;
  206. };
  207.  
  208. Ghost.prototype.getName = function(){
  209. return this.name;
  210. }
  211.  
  212. Ghost.prototype.getType = function(){
  213. return this.type;
  214. };
  215.  
  216. Ghost.prototype.getLoot = function(){
  217. return this.loot;
  218. };
  219.  
  220. Ghost.prototype.getLocation = function(){
  221. return this.location;
  222. }
  223.  
  224. function getGhostFromDB(jsonTxt){
  225. var obj = jQuery.parseJSON(jsonTxt);
  226. var result = [];
  227. for(var x = 0; x < obj.length; x++){
  228. result.push({
  229. 'name':obj[x].name,
  230. 'location':obj[x].location,
  231. 'type':obj[x].type,
  232. 'loot':obj[x].loot,
  233. })
  234. }
  235. return result;
  236. }