More UI

The first part to The GT UI+

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

  1. // ==UserScript==
  2. // @name More UI
  3. // @namespace http://use.i.E.your.homepage/
  4. // @version 0.3.2
  5. // @description The first 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. getSpecialItems();
  13. getCompanionExpAndLike();
  14. function getSpecialItems(){
  15. GM_xmlhttpRequest({
  16. method: 'GET',
  17. url: 'http://www.ghost-trappers.com/fb/setup.php?type=special',
  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. var result = text.match(/<div class="itemHeadline">[A-Za-z0-9'`._%+-\s]+/ig);
  27.  
  28. for(var x = 0; x< result.length; x++){
  29. result[x] = result[x].substr(result[x].indexOf('>')+1, result[x].lastIndexOf(' '));
  30. result[x] = result[x].trim();
  31. }
  32.  
  33. getAyumiShopItems(result);
  34. }
  35. });
  36. };
  37.  
  38. function getAyumiShopItems(itemsInInventory){
  39. GM_xmlhttpRequest({
  40. method: 'GET',
  41. url: 'http://www.ghost-trappers.com/fb/scotch_ninth_floor.php?page=shop&filterItemType=souvenir_set',
  42. headers: {
  43. "Accept": "text/html",
  44. "Pragma": "no-cache",
  45. "Cache-Control": "no-cache"
  46. },
  47. onload: function(rD) {
  48. var text = rD.responseText;
  49. var itemRGX = text.match(/<div class="itemInfo">(\n(.*?))*.?(<div class="seperatorLine">)/ig);
  50. var itemsHolder = [];
  51. for(var x = 0; x < itemRGX.length; x++){
  52. var rgx = itemRGX[x];
  53. var itemNameRGX = rgx.match(/<div class="itemHeadline">\n*.*<\/div>|<div class="itemSpecialText">[A-Za-z0-9'`._%+-\s]+/ig);
  54. var itemCostRGX = rgx.match(/<div class="itemCurrency">(\n(.*?)<\/div>)*/ig);
  55. var itemName = itemNameRGX[0].match(/\s[A-Z0-9.-_\s]*?</ig);
  56. var itemName = itemName[0].substr(1, itemName[0].length-2);
  57.  
  58. var item;
  59. if(itemsInInventory.indexOf(itemName) == -1){
  60. item = new Item(itemName);
  61. for(var y = 0; y < itemCostRGX.length; y++){
  62. var currency_price = itemCostRGX[y].match(/"PRICE - in(.*?)"|<div class="itemPrice">(.*?)<\/div>/ig);
  63. var currency = currency_price[0].substr(currency_price[0].indexOf('In')+3);
  64. currency = currency.substr(0,currency.length-1);
  65. if(currency == 'Great British Pounds, that goes without saying'){
  66. currency = "GBP"
  67. }
  68. var price = currency_price[1].match(/>[0-9,]*?</ig);
  69. price = price[0].substr(1,price[0].length-2);
  70. try{
  71. price = parseInt(price.replace(/,/ig,''));
  72. }
  73. catch(err)
  74. {
  75. console.log('error parse price');
  76. }
  77. item.setCurrency(currency, price);
  78. }
  79. itemsHolder.push(item);
  80. }
  81. }
  82.  
  83. constract_Table(itemsHolder);
  84. }
  85. });
  86. }
  87.  
  88. function constract_Table(array){
  89.  
  90. $('<div class="UserSricpt_container"></div>').appendTo('#header');
  91. $('<div class="souvenirs_container"></div>').appendTo('.UserSricpt_container');
  92. var container = $('.souvenirs_container');
  93. $('.UserSricpt_container').css('position','absolute');
  94. $('.UserSricpt_container').css('top','133%');
  95. $('.UserSricpt_container').css('left','-45%');
  96. $('.UserSricpt_container').css('color','#fff');
  97. for(var x = 0; x < array.length; x++){
  98. $('<a href="http://www.ghost-trappers.com/fb/scotch_ninth_floor.php?page=shop&filterItemType=souvenir_set" class="custom-item" id="item-'+x+'"></a>')
  99. .append($('<div class="itemName"></div>').html(array[x].getName()))
  100. .append($('<div class="itemCost"></div>').css('display', 'table'))
  101. .appendTo(container);
  102. var key = null;
  103. for(key in array[x].getItemCost())
  104. {
  105. $('#item-'+x).find('.itemCost').append($('<div class="itemCurrencyType"></div>').html('- '+key + " " + array[x].getItemCost()[key]));
  106. }
  107. }
  108. $('.UserSricpt_container').find('.souvenirs_container').css({
  109. 'display':'block',
  110. 'color':'white',
  111. 'position':'relative',
  112. 'padding':'10px',
  113. 'margin-top':'10px',
  114. 'border-radius':'15px',
  115. 'font-size':'14px',
  116. 'width':'607px',
  117. 'z-index': '9999',
  118. 'display': 'none'
  119. });
  120.  
  121.  
  122. container.css({
  123. 'position': 'absolute',
  124. 'left' : '297px',
  125. 'top': '-89px',
  126. 'background-color': 'rgba(0, 0, 0, 0.6)',
  127. 'z-index': '999'
  128. });
  129. $('.UserSricpt_container').prepend($('<button>toggle souvenirs</button>'));
  130. var button = $('.UserSricpt_container').find('button');
  131. button.css({
  132. 'position':'absolute',
  133. 'left':'116px',
  134. 'color': 'white',
  135. 'font-weight':'bold',
  136. 'font-size': '16px',
  137. 'text-shadow': '1px 1px black',
  138. 'padding': '3px 8px',
  139. 'border': '1px solid rgb(206, 174, 7)',
  140. 'border-radius':'5px',
  141. 'background-color': 'gold',
  142. 'z-index': '99999999',
  143. 'min-width':'153px'
  144. });
  145. button[0].addEventListener("click", function(){
  146. if($('.UserSricpt_container').find('.souvenirs_container').css('display') == 'none'){
  147. $('.UserSricpt_container').find('.souvenirs_container').css({
  148. 'display': 'block'
  149. });
  150. }
  151. else{
  152. $('.UserSricpt_container').find('.souvenirs_container').css({
  153. 'display': 'none'
  154. });
  155. }
  156. });
  157. getCurrency(array);
  158. }
  159.  
  160. function insertCommas(string,text){
  161. if(text){
  162. var result = text.toString();
  163. if (result.length > 3){
  164. for(var x = result.length-3; x>0; x-=3){
  165. result = result.substring(0, x) + string + result.substring(x, result.length);
  166. }
  167. }
  168.  
  169. return result;
  170. }
  171. else{
  172. return 0;
  173. }
  174. }
  175.  
  176. function priceIn(dictionary, array){
  177. var elements = $(".UserSricpt_container").find('.souvenirs_container')[0].childNodes;
  178. for(var x= 0; x < elements.length; x++){
  179. var currencyHolder = elements[x];
  180. var children = currencyHolder.childNodes;
  181. children = children[1].childNodes;
  182. var match = 0;
  183. for(var y = 0; y < children.length; y++){
  184. var temp = children[y].innerHTML;
  185. var priceIn = temp.substr(temp.indexOf('-')+2, temp.lastIndexOf(' ')-2).trim();
  186. var price = temp.substr(temp.lastIndexOf(' ')+1);
  187.  
  188. try{
  189. dictionary[priceIn] = parseInt(dictionary[priceIn].replace(/,/ig,''));
  190. }
  191. catch(err)
  192. {
  193. // just skip this error!!!
  194. }
  195. children[y].innerHTML = ' - ' + priceIn +' '+ insertCommas(',',price) + '('+insertCommas(',',dictionary[priceIn])+')';
  196. if(dictionary[priceIn] >= array[x].getCurrency(priceIn)){
  197. if(match == children.length-1){
  198.  
  199. $(".UserSricpt_container").find('.souvenirs_container').find('#item-'+x).css({
  200. 'background-color':'rgba(0, 128, 0, 0.2)',
  201. 'border':'1px solid green',
  202. 'box-shadow':'inset 0 1px 1px rgba(0,0,0,.075),0 0 6px green',
  203. '-webkit-box-shadow':'inset 0 1px 1px rgba(0,0,0,.075),0 0 6px green',
  204. 'display':'block',
  205. 'color':'white',
  206. 'position':'relative',
  207. 'padding':'10px',
  208. 'margin-top':'10px',
  209. 'border-radius':'15px'
  210. });
  211. }
  212. match++;
  213. }
  214. else{
  215. $(".UserSricpt_container").find('.souvenirs_container').find('#item-'+x).css({
  216. 'background-color':'rgba(255, 0, 0, 0.2)',
  217. 'border':'1px solid red',
  218. 'box-shadow':'inset 0 1px 1px rgba(0,0,0,.075),0 0 6px red',
  219. '-webkit-box-shadow':'inset 0 1px 1px rgba(0,0,0,.075),0 0 6px red',
  220. 'display':'block',
  221. 'color':'white',
  222. 'position':'relative',
  223. 'padding':'10px',
  224. 'margin-top':'10px',
  225. 'border-radius':'15px'
  226. });
  227. }
  228. }
  229. }
  230. }
  231.  
  232. function getCurrency(array){
  233. GM_xmlhttpRequest({
  234. method: 'GET',
  235. url: 'http://www.ghost-trappers.com/fb/setup.php?type=currency',
  236. headers: {
  237. "Accept": "text/html",
  238. "Pragma": "no-cache",
  239. "Cache-Control": "no-cache"
  240. },
  241. onload: function(rD) {
  242. var text = rD.responseText;
  243.  
  244. var result = text.match(/<div class="itemInfo">\n*.*<\/div>|<div class="itemSpecialText">[A-Za-z0-9'`._%+-\s]+/ig);
  245. var gbpHolder = document.getElementById('profile_gbp').innerHTML;
  246.  
  247. var dictionary = [];
  248. for(var x = 0; x < result.length-1; x+=2){
  249. var temp = result[x].match(/[A-Z0-9.-_\s]+>/ig);
  250. var key = temp[0].substring(1, temp[0].indexOf('</')).trim();
  251. var value = result[x+1].substring(result[x+1].indexOf('itemSpecialText'), result[x+1].indexOf('.'));
  252. value = value.match(/[0-9]+/ig);
  253. dictionary[key] = parseInt(value);
  254. }
  255. dictionary['GBP'] = gbpHolder;
  256. priceIn(dictionary, array);
  257. }
  258. });
  259. };
  260.  
  261.  
  262. var Item = function(name) {
  263. this.name = name;
  264. this.dictionary = [];
  265. };
  266.  
  267. Item.prototype.getName = function(){
  268. return this.name;
  269. }
  270.  
  271. Item.prototype.setCurrency = function(currency, value){
  272. this.dictionary[currency] = value;
  273. };
  274.  
  275. Item.prototype.getCurrency = function(currency){
  276. return this.dictionary[currency];
  277. };
  278.  
  279. Item.prototype.getItemCost = function(){
  280. return this.dictionary;
  281. }
  282.  
  283. //<<<<>>>
  284. function getCompanionExpAndLike(){
  285. GM_xmlhttpRequest({
  286. method: 'GET',
  287. url: 'http://www.ghost-trappers.com/fb/setup.php?type=companion',
  288. headers: {
  289. "Accept": "text/html",
  290. "Pragma": "no-cache",
  291. "Cache-Control": "no-cache"
  292. },
  293. onload: function(rD) {
  294. var text = rD.responseText;
  295. var rgx = text.match(/<div class="companionFullBar"*.*<\/div>|<div class=companionLikeFullBar*.*<\/div>/ig);
  296. var percent = [];
  297. for(var x= 0; x< rgx.length; x++){
  298. var width = rgx[x].match(/width:[0-9]+/ig);
  299. width = width[0].substr(width[0].indexOf(':')+1);
  300. percent.push((width/200)*100);
  301. }
  302. var companionLVLRGX = text.match(/companion\/level*.*(jpg)/ig);
  303. var companionLVL = companionLVLRGX[0].substr(companionLVLRGX[0].indexOf('_')+1, 1);
  304. var container = $('#petRightContainer');
  305. var likeValue = 0;
  306. if(percent[1]){
  307. likeValue = percent[1];
  308. }
  309. else{
  310. if(companionLVL < 5){
  311. likeValue = 0;
  312. }
  313. else if(companionLVL == 5){
  314. likeValue = 100;
  315. }
  316. }
  317.  
  318. $('<a href="http://www.ghost-trappers.com/fb/setup.php?type=companion" class="exp_like_display"></a>')
  319. .append($('<div class="expDisplay"></div>')
  320. .html(percent[0].toFixed(1) + '%')
  321. .css({
  322. 'float': 'left',
  323. 'padding': '3px',
  324. 'font-weight': 'bold',
  325. 'background-color':'rgba(135, 206, 235, 0.6)',
  326. 'border-radius': '10px',
  327. 'border':'1px solid skyblue',
  328. 'box-shadow':'inset 0 1px 1px rgba(0,0,0,.075),0 0 6px skyblue',
  329. '-webkit-box-shadow':'inset 0 1px 1px rgba(0,0,0,.075),0 0 6px skyblue'
  330. }))
  331. .append($('<div class="likeDisplay"></div>')
  332. .html(likeValue.toFixed(1)+ '%')
  333. .css({
  334. 'float': 'right',
  335. 'padding': '3px',
  336. 'font-weight': 'bold',
  337. 'background-color':'rgba(255, 192, 203, 0.6)',
  338. 'border-radius': '10px',
  339. 'border':'1px solid pink',
  340. 'box-shadow':'inset 0 1px 1px rgba(0,0,0,.075),0 0 6px pink',
  341. '-webkit-box-shadow':'inset 0 1px 1px rgba(0,0,0,.075),0 0 6px pink'
  342. }))
  343. .appendTo(container);
  344. $('.exp_like_display').css({
  345. 'color': 'black',
  346. 'position':'absolute',
  347. 'top': '60px',
  348. 'left': '0px',
  349. 'width': '100%',
  350. 'z-index': '9999'
  351. })
  352. }
  353. });
  354. }
  355.  
  356. //<<<<>>>
  357. exhibition();
  358. function exhibition(){
  359. GM_xmlhttpRequest({
  360. method: 'GET',
  361. url: 'http://www.ghost-trappers.com/fb/scotch_ninth_floor.php?page=exhibition&currentPage=-2',
  362. headers: {
  363. "Accept": "text/html",
  364. "Pragma": "no-cache",
  365. "Cache-Control": "no-cache"
  366. },
  367. onload: function(rD) {
  368. var text = rD.responseText;
  369.  
  370. $('<div class="UserSricpt_exhibition_container"></div>').appendTo('#header');
  371. $('<div class="exhibition_container"></div>').appendTo('.UserSricpt_exhibition_container');
  372. var container = $('.exhibition_container');
  373. $('.UserSricpt_exhibition_container').css('position','absolute');
  374. $('.UserSricpt_exhibition_container').css('top','150%');
  375. $('.UserSricpt_exhibition_container').css('left','-27%');
  376. $('.UserSricpt_exhibition_container').css('color','#fff');
  377. var rgx = text.match(/<div class="souvenirPartsLine " >[\s\nA-Za-z0-9<=>"'\/_.?!]*<\/div>/gi);
  378. var array = [];
  379. var temp = stringRep(text);
  380. for(var x = 0; x< rgx.length; x++){
  381. var rgxImg = rgx[x].match(/src(.*)\w/gi);
  382. array[x] = [];
  383.  
  384. var items = extractItems(rgxImg);
  385. ($('<a href="http://www.ghost-trappers.com/fb/scotch_ninth_floor.php?page=exhibition&currentPage=-2" class="exhibition-collection" id="exhibition-collection-'+x+'"></a>')
  386. .css('position', 'relative'))
  387. .appendTo(container);
  388. var item_container = $('#exhibition-collection-'+x);
  389. if(x < rgx.length-1){
  390. for(var y=0; y < rgxImg.length-1; y++){
  391. var ghost = getGhostByLoot(items[y]);
  392. ($('<img '+ rgxImg[y] + '" data-target="'+x+'_'+y+'"/>')
  393. .css('width', '10%'))
  394. .appendTo(item_container);
  395. if(ghost){
  396. ($('<div id="'+x+'_'+y+'"></div>').css({
  397. 'position': 'absolute',
  398. 'top': '-14px',
  399. 'right': '40px',
  400. 'z-index': '9999999',
  401. 'font-size': '14px',
  402. 'display': 'none',
  403. 'background-color': '#223341',
  404. 'border': '1px solid #222',
  405. 'border-radius': '7px',
  406. 'padding': '10px',
  407. 'min-width': '150px'
  408. }).html(ghost.name + ' ' + ghost.location))
  409. .appendTo(item_container);
  410. }
  411. }
  412. }
  413. else{
  414. for(var y=0; y < rgxImg.length; y++){
  415. ($('<img '+ rgxImg[y] + '"/>').css('width', '10%'))
  416. .appendTo(item_container);
  417. }
  418. }
  419. }
  420. $('.UserSricpt_exhibition_container').find('.exhibition-collection').css({
  421. 'display':'block',
  422. 'color':'white',
  423. 'position':'relative',
  424. 'padding':'10px',
  425. 'margin-top':'10px',
  426. 'border-radius':'15px',
  427. 'font-size':'14px',
  428. 'width':'607px',
  429. 'z-index': '9999',
  430. 'display': 'none'
  431. });
  432. container.css({
  433. 'position': 'absolute',
  434. 'left' : '183px',
  435. 'top': '-89px',
  436. 'background-color': 'rgba(0, 0, 0, 0.6)',
  437. 'z-index': '999'
  438. });
  439. $('.UserSricpt_exhibition_container').prepend($('<button>toggle exhibition</button>'));
  440. var button = $('.UserSricpt_exhibition_container').find('button');
  441.  
  442. button.css({
  443. 'position':'absolute',
  444. 'left':'0px',
  445. 'color': 'white',
  446. 'font-weight':'bold',
  447. 'font-size': '16px',
  448. 'text-shadow': '1px 1px black',
  449. 'padding': '3px 8px',
  450. 'border': '1px solid rgb(206, 174, 7)',
  451. 'border-radius':'5px',
  452. 'background-color': 'gold',
  453. 'z-index': '99999999',
  454. 'width': '153px'
  455. });
  456.  
  457. button[0].addEventListener("click", function(){
  458.  
  459. if($('.UserSricpt_exhibition_container').find('.exhibition-collection').css('display') == 'none'){
  460. $('.UserSricpt_exhibition_container').find('.exhibition-collection').css({
  461. 'display': 'block'
  462. });
  463. }
  464. else{
  465. $('.UserSricpt_exhibition_container').find('.exhibition-collection').css({
  466. 'display': 'none'
  467. });
  468. }
  469. });
  470. }
  471. });
  472. }
  473.  
  474.  
  475. function extractItems(array){
  476. var result = [];
  477. for(var x = 0 ; x < array.length-1; x++){
  478. var start = array[x].lastIndexOf('/')+1;
  479. var end = array[x].indexOf('.png');
  480. var souvenir = array[x].substr(start,end-start);
  481. souvenir = souvenir.replace(/_/ig,' ');
  482. if(souvenir.lastIndexOf(' grey') > -1){
  483. souvenir = souvenir.replace(/ grey/ig,' ');
  484. }
  485. if(souvenir.indexOf('04 ') > -1){
  486. souvenir = souvenir.replace(/04 /ig,' ');
  487. }
  488. souvenir = souvenir.substr(0,1).toUpperCase() + souvenir.substr(1);
  489. result.push(souvenir);
  490. }
  491. return result;
  492. }
  493.  
  494.  
  495. function stringRep(text){
  496. var rgx = text.match(/<div class="souvenirSetContainer" >(\n(.*?))*.?(<div class="seperatorLine">)/gi);
  497. var array = [];
  498. for(var x = 0; x < rgx.length; x++){
  499. var name = rgx[x].match(/<div class="souvenirTopLeft">(\n(.*?))*.?(<\/img>)/gi);
  500. name = name[0].substr(name[0].indexOf('souvenirs')+'souvenirs'.length+1, (name[0].lastIndexOf('"')-(name[0].indexOf('souvenirs')+'souvenirs'.length+5)));
  501. if(name.indexOf('04_headline') > -1){
  502. name = name.substr(name.indexOf('04_headline')+'04_headline'.length+1);
  503. }
  504. else if(name.indexOf('headline') > -1){
  505. name = name.substr(name.indexOf('headline')+'headline'.length+1);
  506. }
  507. name = name.replace(/_/ig,' ');
  508. array.push(name);
  509. }
  510. return array;
  511. }
  512.  
  513.  
  514.  
  515. function getGhostByLoot(loot){
  516. var obj = jQuery.parseJSON($('.fakeDB').html());
  517. var result = '';
  518. for(var x = 0; x < obj.length; x++){
  519. for(var y= 0; y < obj[x].loot.length; y++){
  520. if(loot && obj[x].loot[y] == loot){
  521. result = {
  522. name: obj[x].name,
  523. location: obj[x].location,
  524. type: obj[x].type
  525. }
  526. }
  527. }
  528. }
  529.  
  530. return result;
  531. }