More UI part3

The third part to The GT UI+

当前为 2015-08-26 提交的版本,查看 最新版本

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