Greasy Fork 还支持 简体中文。

More UI part1

The first part to The GT UI+

  1. // ==UserScript==
  2. // @name More UI part1
  3. // @namespace http://use.i.E.your.homepage/
  4. // @version 1.0
  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. function stringRep(text){
  357. var rgx = text.match(/<div class="souvenirSetContainer" >(\n(.*?))*.?(<div class="seperatorLine">)/gi);
  358. var array = [];
  359. for(var x = 0; x < rgx.length; x++){
  360. var name = rgx[x].match(/<div class="souvenirTopLeft">(\n(.*?))*.?(<\/img>)/gi);
  361. name = name[0].substr(name[0].indexOf('souvenirs')+'souvenirs'.length+1, (name[0].lastIndexOf('"')-(name[0].indexOf('souvenirs')+'souvenirs'.length+5)));
  362. if(name.indexOf('04_headline') > -1){
  363. name = name.substr(name.indexOf('04_headline')+'04_headline'.length+1);
  364. }
  365. else if(name.indexOf('headline') > -1){
  366. name = name.substr(name.indexOf('headline')+'headline'.length+1);
  367. }
  368. name = name.replace(/_/ig,' ');
  369. array.push(name);
  370. }
  371. return array;
  372. }