More UI

The first version to The GT UI+

当前为 2015-06-19 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name More UI
  3. // @namespace http://use.i.E.your.homepage/
  4. // @version 0.2
  5. // @description The first version to The GT UI+
  6. // @match http://www.ghost-trappers.com/fb/*
  7. // @copyright 2015+, GTNoAPI
  8. // @grant GM_xmlhttpRequest
  9. // ==/UserScript==
  10.  
  11. getSpecialItems();
  12. getCompanionExpAndLike();
  13. function getSpecialItems(){
  14. GM_xmlhttpRequest({
  15. method: 'GET',
  16. url: 'http://www.ghost-trappers.com/fb/setup.php?type=special',
  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. var result = text.match(/<div class="itemHeadline">[A-Za-z0-9'`._%+-\s]+/ig);
  26.  
  27. for(var x = 0; x< result.length; x++){
  28. result[x] = result[x].substr(result[x].indexOf('>')+1, result[x].lastIndexOf(' '));
  29. result[x] = result[x].trim();
  30. }
  31.  
  32. getAyumiShopItems(result);
  33. }
  34. });
  35. };
  36.  
  37. function getAyumiShopItems(itemsInInventory){
  38. GM_xmlhttpRequest({
  39. method: 'GET',
  40. url: 'http://www.ghost-trappers.com/fb/scotch_ninth_floor.php?page=shop&filterItemType=souvenir_set',
  41. headers: {
  42. "Accept": "text/html",
  43. "Pragma": "no-cache",
  44. "Cache-Control": "no-cache"
  45. },
  46. onload: function(rD) {
  47. var text = rD.responseText;
  48. var itemRGX = text.match(/<div class="itemInfo">(\n(.*?))*.?(<div class="seperatorLine">)/ig);
  49. var itemsHolder = [];
  50. for(var x = 0; x < itemRGX.length; x++){
  51. var rgx = itemRGX[x];
  52. var itemNameRGX = rgx.match(/<div class="itemHeadline">\n*.*<\/div>|<div class="itemSpecialText">[A-Za-z0-9'`._%+-\s]+/ig);
  53. var itemCostRGX = rgx.match(/<div class="itemCurrency">(\n(.*?)<\/div>)*/ig);
  54. var itemName = itemNameRGX[0].match(/\s[A-Z0-9.-_\s]*?</ig);
  55. var itemName = itemName[0].substr(1, itemName[0].length-2);
  56.  
  57. var item;
  58. if(itemsInInventory.indexOf(itemName) == -1){
  59. item = new Item(itemName);
  60. for(var y = 0; y < itemCostRGX.length; y++){
  61. var currency_price = itemCostRGX[y].match(/"PRICE - in(.*?)"|<div class="itemPrice">(.*?)<\/div>/ig);
  62. var currency = currency_price[0].substr(currency_price[0].indexOf('In')+3);
  63. currency = currency.substr(0,currency.length-1);
  64. if(currency == 'Great British Pounds, that goes without saying'){
  65. currency = "GBP"
  66. }
  67. var price = currency_price[1].match(/>[0-9,]*?</ig);
  68. price = price[0].substr(1,price[0].length-2);
  69. try{
  70. price = parseInt(price.replace(/,/ig,''));
  71. }
  72. catch(err)
  73. {
  74. console.log('error parse price');
  75. }
  76. item.setCurrency(currency, price);
  77. }
  78. itemsHolder.push(item);
  79. }
  80. }
  81.  
  82. constract_Table(itemsHolder);
  83. }
  84. });
  85. }
  86.  
  87. function insertCommas(string,text){
  88. var result = text.toString();
  89. if (result.length > 3){
  90. for(var x = result.length-3; x>0; x-=3){
  91. result = result.substring(0, x) + string + result.substring(x, result.length);
  92. }
  93. }
  94.  
  95. return result;
  96. }
  97.  
  98. function constract_Table(array){
  99.  
  100. $('<div class="UserSricpt_container"></div>').appendTo('#header');
  101. var container = $('.UserSricpt_container');
  102. container.css('position','absolute');
  103. container.css('top','133%');
  104. container.css('left','-45%');
  105. container.css('color','#fff');
  106. for(var x = 0; x < array.length; x++){
  107. $('<a href="http://www.ghost-trappers.com/fb/scotch_ninth_floor.php?page=shop&filterItemType=souvenir_set" class="custom-item" id="item-'+x+'"></a>')
  108. .append($('<div class="itemName"></div>').html(array[x].getName()))
  109. .append($('<div class="itemCost"></div>').css('display', 'table'))
  110. .appendTo(container);
  111. var key = null;
  112. for(key in array[x].getItemCost())
  113. {
  114. $('#item-'+x).find('.itemCost').append($('<div class="itemCurrencyType"></div>').html('- '+key + " " + array[x].getItemCost()[key]));
  115. }
  116. }
  117. $('.UserSricpt_container').find('.custom-item').css({
  118. 'display':'block',
  119. 'color':'white',
  120. 'position':'relative',
  121. 'padding':'10px',
  122. 'margin-top':'10px',
  123. 'border-radius':'15px',
  124. 'font-size':'14px',
  125. 'width':'250px',
  126. 'display': 'none'
  127. });
  128. getCurrency(array);
  129. }
  130.  
  131. function insertCommas(string,text){
  132. var result = text.toString();
  133. if (result.length > 3){
  134. for(var x = result.length-3; x>0; x-=3){
  135. result = result.substring(0, x) + string + result.substring(x, result.length);
  136. }
  137. }
  138.  
  139. return result;
  140. }
  141.  
  142. function priceIn(dictionary, array){
  143. var elements = $(".UserSricpt_container")[0].childNodes;
  144. for(var x= 0; x < elements.length; x++){
  145. var currencyHolder = elements[x];
  146. var children = currencyHolder.childNodes;
  147. children = children[1].childNodes;
  148. var match = 0;
  149. for(var y = 0; y < children.length; y++){
  150. var temp = children[y].innerHTML;
  151. var priceIn = temp.substr(temp.indexOf('-')+2, temp.lastIndexOf(' ')-2).trim();
  152. var price = temp.substr(temp.lastIndexOf(' ')+1);
  153.  
  154. try{
  155. dictionary[priceIn] = parseInt(dictionary[priceIn].replace(/,/ig,''));
  156. }
  157. catch(err)
  158. {
  159. // just skip this error!!!
  160. }
  161. children[y].innerHTML = ' - ' + priceIn +' '+ insertCommas(',',price) + '('+insertCommas(',',dictionary[priceIn])+')';
  162. if(dictionary[priceIn] >= array[x].getCurrency(priceIn)){
  163. if(match == children.length-1){
  164.  
  165. $('.UserSricpt_container').find('#item-'+x).css({
  166. 'background-color':'rgba(0, 128, 0, 0.2)',
  167. 'border':'1px solid green',
  168. 'box-shadow':'inset 0 1px 1px rgba(0,0,0,.075),0 0 6px green',
  169. '-webkit-box-shadow':'inset 0 1px 1px rgba(0,0,0,.075),0 0 6px green'
  170. });
  171. }
  172. match++;
  173. }
  174. else{
  175. $('.UserSricpt_container').find('#item-'+x).css({
  176. 'background-color':'rgba(255, 0, 0, 0.2)',
  177. 'border':'1px solid red',
  178. 'box-shadow':'inset 0 1px 1px rgba(0,0,0,.075),0 0 6px red',
  179. '-webkit-box-shadow':'inset 0 1px 1px rgba(0,0,0,.075),0 0 6px red'
  180. });
  181. }
  182. }
  183. }
  184. var container = $('.UserSricpt_container');
  185. container.prepend($('<button>toggle table</button>'));
  186. var asd = $('.UserSricpt_container').find('button');
  187. asd.css({
  188. 'position':'absolute',
  189. 'left':'160px',
  190. 'color': 'white',
  191. 'font-weight':'bold',
  192. 'font-size': '16px',
  193. 'text-shadow': '1px 1px black',
  194. 'padding': '3px 8px',
  195. 'border': '1px solid rgb(206, 174, 7)',
  196. 'border-radius':'5px',
  197. 'background-color': 'gold',
  198. 'z-index': '99999999',
  199. 'min-width':'109px'
  200. });
  201. asd[0].addEventListener("click", function(){
  202. if($('.UserSricpt_container').find('.custom-item').css('display') == 'none'){
  203. $('.UserSricpt_container').find('.custom-item').css({
  204. 'display': 'block'
  205. });
  206. }
  207. else{
  208. $('.UserSricpt_container').find('.custom-item').css({
  209. 'display': 'none'
  210. });
  211. }
  212. });
  213. }
  214.  
  215. function getCurrency(array){
  216. GM_xmlhttpRequest({
  217. method: 'GET',
  218. url: 'http://www.ghost-trappers.com/fb/setup.php?type=currency',
  219. headers: {
  220. "Accept": "text/html",
  221. "Pragma": "no-cache",
  222. "Cache-Control": "no-cache"
  223. },
  224. onload: function(rD) {
  225. var text = rD.responseText;
  226.  
  227. var result = text.match(/<div class="itemInfo">\n*.*<\/div>|<div class="itemSpecialText">[A-Za-z0-9'`._%+-\s]+/ig);
  228. var gbpHolder = document.getElementById('profile_gbp').innerHTML;
  229.  
  230. var dictionary = [];
  231. for(var x = 0; x < result.length-1; x+=2){
  232. var temp = result[x].match(/[A-Z0-9.-_\s]+>/ig);
  233. var key = temp[0].substring(1, temp[0].indexOf('</')).trim();
  234. var value = result[x+1].substring(result[x+1].indexOf('itemSpecialText'), result[x+1].indexOf('.'));
  235. value = value.match(/[0-9]+/ig);
  236. dictionary[key] = parseInt(value);
  237. }
  238. dictionary['GBP'] = gbpHolder;
  239. priceIn(dictionary, array);
  240. }
  241. });
  242. };
  243.  
  244.  
  245. var Item = function(name) {
  246. this.name = name;
  247. this.dictionary = [];
  248. };
  249.  
  250. Item.prototype.getName = function(){
  251. return this.name;
  252. }
  253.  
  254. Item.prototype.setCurrency = function(currency, value){
  255. this.dictionary[currency] = value;
  256. };
  257.  
  258. Item.prototype.getCurrency = function(currency){
  259. return this.dictionary[currency];
  260. };
  261.  
  262. Item.prototype.getItemCost = function(){
  263. return this.dictionary;
  264. }
  265.  
  266. //<<<<>>>
  267. function getCompanionExpAndLike(){
  268. GM_xmlhttpRequest({
  269. method: 'GET',
  270. url: 'http://www.ghost-trappers.com/fb/setup.php?type=companion',
  271. headers: {
  272. "Accept": "text/html",
  273. "Pragma": "no-cache",
  274. "Cache-Control": "no-cache"
  275. },
  276. onload: function(rD) {
  277. var text = rD.responseText;
  278. var rgx = text.match(/<div class="companionFullBar"*.*<\/div>|<div class=companionLikeFullBar*.*<\/div>/ig);
  279. var percent = [];
  280. for(var x= 0; x< rgx.length; x++){
  281. var width = rgx[x].match(/width:[0-9]+/ig);
  282. width = width[0].substr(width[0].indexOf(':')+1);
  283. percent.push((width/200)*100);
  284. }
  285. var companionLVLRGX = text.match(/companion\/level*.*(jpg)/ig);
  286. var companionLVL = companionLVLRGX[0].substr(companionLVLRGX[0].indexOf('_')+1, 1);
  287. var container = $('#petRightContainer');
  288. var likeValue = 0;
  289. if(percent[1]){
  290. likeValue = percent[1];
  291. }
  292. else{
  293. if(companionLVL < 5){
  294. likeValue = 0;
  295. }
  296. else if(companionLVL == 5){
  297. likeValue = 100;
  298. }
  299. }
  300.  
  301. $('<a href="http://www.ghost-trappers.com/fb/setup.php?type=companion" class="exp_like_display"></a>')
  302. .append($('<div class="expDisplay"></div>')
  303. .html(percent[0].toFixed(1) + '%')
  304. .css({
  305. 'float': 'left',
  306. 'padding': '3px',
  307. 'font-weight': 'bold',
  308. 'background-color':'rgba(135, 206, 235, 0.6)',
  309. 'border-radius': '10px',
  310. 'border':'1px solid skyblue',
  311. 'box-shadow':'inset 0 1px 1px rgba(0,0,0,.075),0 0 6px skyblue',
  312. '-webkit-box-shadow':'inset 0 1px 1px rgba(0,0,0,.075),0 0 6px skyblue'
  313. }))
  314. .append($('<div class="likeDisplay"></div>')
  315. .html(likeValue.toFixed(1)+ '%')
  316. .css({
  317. 'float': 'right',
  318. 'padding': '3px',
  319. 'font-weight': 'bold',
  320. 'background-color':'rgba(255, 192, 203, 0.6)',
  321. 'border-radius': '10px',
  322. 'border':'1px solid pink',
  323. 'box-shadow':'inset 0 1px 1px rgba(0,0,0,.075),0 0 6px pink',
  324. '-webkit-box-shadow':'inset 0 1px 1px rgba(0,0,0,.075),0 0 6px pink'
  325. }))
  326. .appendTo(container);
  327. $('.exp_like_display').css({
  328. 'color': 'black',
  329. 'position':'absolute',
  330. 'top': '60px',
  331. 'left': '0px',
  332. 'width': '100%',
  333. 'z-index': '9999'
  334. })
  335. }
  336. });
  337. }