Guest User

Mango's Noodz

a guest
Dec 21st, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.25 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Christmas Town 2018
  3. // @namespace mafia.christmas
  4. // @author Mafia[610357]
  5. // @description Notification for items near you in christmas town map
  6. // @match https://www.torn.com/christmas_town.php
  7. // @version 2018.9
  8. // @require http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js
  9. // @require https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js
  10. // @require https://greasyfork.org/scripts/39572/code/mafia-helper.js
  11. // @require https://greasyfork.org/scripts/375735/code/achex.js
  12. // @grant none
  13. // @run-at document-start
  14. // ==/UserScript==
  15.  
  16. 'use strict';
  17.  
  18. var ct = JSON.parse(localStorage.ct || '{}');
  19.  
  20. if(typeof ct.user == 'undefined') {
  21. $(document).ready(function() {
  22. uid = $("script[src*='js/chat/chat']").attr("uid");
  23. name = $("script[src*='js/chat/chat']").attr("name");
  24. ct.user = name + "[" + uid + "]";
  25. localStorage.ct = JSON.stringify(ct);
  26.  
  27. alert('Initializing CT 2018 script. Press OK to reload page.');
  28. location.reload();
  29. });
  30. }
  31. else {
  32. $.achex({
  33. facebook: false,
  34. username: ct.user,
  35. password: 'none',
  36. url: 'wss://ws.achex.ca',
  37. port: 443,
  38. reconnect: 3000,
  39. callback: function(o, d, e)
  40. {
  41. var o = o;
  42. if(o.type == "NPC") {
  43. if($("#ctnpc p").length) $("#ctnpc p").remove();
  44. if($("#npc"+o.npcName).length){
  45. $("#npc"+o.npcName+" span:eq(0)").html(o.npcName + ' at <strong>' + o.x + ',' + o.y + '</strong>');
  46. $("#npc"+o.npcName+" .cttime").attr("by", moment().unix());
  47. }
  48. else {
  49. $("#ctnpc ul").append('<li id="npc'+o.npcName+'"><img src="/images/v2/christmas_town/users/new/'+o.npcName.toLowerCase()+'.png"/> <div><span>' + o.npcName + ' at <strong>' + o.x + ',' + o.y + '</strong></span><br/><span class="cttime" by="'+moment().unix()+'">a few seconds ago</span></div><div class="clear"></div></li>');
  50. setInterval(() => {
  51. $("#npc" + o.npcName + " .cttime").text(moment.unix(parseInt($("#npc" + o.npcName + " .cttime").attr("by"))).fromNow());
  52. }, 5000);
  53. }
  54. }
  55. if(o.type == "CTitems") {
  56.  
  57. if($("#ctchest p").length) $("#ctchest p").remove();
  58. if(!$(".chest" + o.x + '_' + o.y).length) {
  59. $("#ctchest ul").prepend("<li class='chest"+o.x+"_"+o.y+"'><img src='/images/items/christmas_town/chests/"+o.ctID.replace(/\./g,'-')+".png'/> <div><span>" + o.itemName + " chest</spantext-transform:> at <strong>" + o.x + ',' + o.y + "</strong><br/><span class='cttime' by='"+moment().unix()+"'>a few seconds ago</span></div><div class='clear'></div></li>");
  60. setInterval(() => {
  61. $(".chest"+o.x+"_"+o.y+" .cttime").text(moment.unix(parseInt($(".chest"+o.x+"_"+o.y+" .cttime").attr("by"))).fromNow());
  62. if(moment().unix() - parseInt($(".chest"+o.x+"_"+o.y+" .cttime").attr("by")) > 100) {
  63. $(".chest"+o.x+"_"+o.y).fadeOut(50000,function(){
  64. $(".chest"+o.x+"_"+o.y).remove();
  65. if(!$("#ctchest ul li").length)
  66. $("#ctchest ul").before('<p>No chest found at a moment.</p>');
  67. });
  68. }
  69. }, 5000);
  70. }
  71. else {
  72. $(".chest"+o.x+"_"+o.y+" .cttime").attr("by", moment().unix());
  73. }
  74.  
  75. }
  76. }
  77. });
  78. $.achex.join('CT2018');
  79.  
  80. var $achex = $.achex;
  81. var xmastown = function(response) {
  82. if(response.hasOwnProperty('mapData')) {
  83. if(response.mapData.users !== null) {
  84. npc = response.mapData.users.filter(u=>typeof u.user_id=='string');
  85. users = response.mapData.users.filter(u=>typeof u.user_id=='number');
  86. if(users.length) {
  87. var utime = moment().unix();
  88. $.each(users, function() {
  89. var uid = this.user_id;
  90. if(!$("#ctusers ul li."+uid).length) {
  91. $("#ctusers ul").append($('<li class="'+uid+'" batch="'+utime+'" style="display: none;">'+this.playername+'</li>').hover(function(){
  92. $("#ctUser"+uid+" path:eq(1)").css("fill","gold");
  93. },function(){
  94. $("#ctUser"+uid+" path:eq(1)").css("fill","");
  95. }).fadeIn());
  96. }
  97. else {
  98. $("#ctusers ul li."+uid).attr("batch", utime);
  99. }
  100. });
  101. $("#ctusers ul li:not([batch='"+utime+"'])").fadeOut(function(){$(this).remove()});
  102. }
  103.  
  104. if(npc.length) {
  105. var ctnpc = '';
  106. $.each(npc,function() {
  107. if($("#ctnpc p").length) $("#ctnpc p").remove();
  108. $achex.send({
  109. toH:'CT2018',
  110. type: 'NPC',
  111. npcName: this.playername,
  112. x: this.position.x,
  113. y: this.position.y,
  114. v: GM_info.script.version
  115. });
  116.  
  117. if($("#npc"+this.playername).length){
  118. $("#npc"+this.playername+" span:eq(0)").html(this.playername + ' at <strong>' + this.position.x + ',' + this.position.y + '</strong>');
  119. $("#npc"+this.playername+" .cttime").attr("by", moment().unix());
  120. }
  121. else {
  122. $("#ctnpc ul").append('<li id="npc'+this.playername+'"><img src="/images/v2/christmas_town/users/new/'+this.playername.toLowerCase()+'.png"/> <div><span>' + this.playername + ' at <strong>' + this.position.x + ',' + this.position.y + '</strong></span><br/><span class="cttime" by="'+moment().unix()+'">a few seconds ago</span></div><div class="clear"></div></li>');
  123. setInterval(() => {
  124. $("#npc" + this.playername + " .cttime").text(moment.unix(parseInt($("#npc" + this.playername + " .cttime").attr("by"))).fromNow());
  125. }, 5000);
  126. }
  127. });
  128. }
  129. }
  130.  
  131. // Item Spawned
  132. if(response.mapData.items !== null) {
  133. items = response.mapData.items;
  134. var ctspawn = '';
  135.  
  136. $.each(items,function() {
  137. if(this.category != 'tornItems' && this.category != 'keys' && this.category != 'combinationChest') {
  138. $achex.send({
  139. toH:'CT2018',
  140. type: 'CTitems',
  141. ctID: this.item_id,
  142. itemID: this.type,
  143. itemName: this.name,
  144. x: this.position.x,
  145. y: this.position.y
  146. });
  147. }
  148.  
  149. switch (this.category) {
  150. case 'keys':
  151. custompadding = '18px';
  152. break;
  153.  
  154. case 'combinationChest':
  155. custompadding = '6px';
  156. break;
  157. default:
  158. custompadding = '0px';
  159. break;
  160. }
  161. ctspawn += '<li><img src="/images/items/'+(this.category == 'tornItems' ? this.type + '/small': 'christmas_town/'+this.category+'/'+this.item_id.replace(/\./g,'-'))+'.png" style="padding-right:'+custompadding+';"> <div>[' + this.position.x + ',' + this.position.y + ']<br/>' + this.name + (this.category == 'chests' ? ' chest' : '') + '</div></li>';
  162. });
  163. $("#ctspawn ul").html(ctspawn ? ctspawn : 'No item around you.');
  164. }
  165.  
  166. //POI (Shop / Games)
  167. if(typeof response.mapData.cellEvent !== 'undefined') {
  168. place = response.mapData.cellEvent;
  169. if(place.type !== 'gameCombinationChest' && place.type != 'NPC') {
  170. place = place.miniGameType.split(/(?=[A-Z])/).join(" ");
  171. x = response.mapData.position.x;
  172. y = response.mapData.position.y;
  173. if(!ct.hasOwnProperty('places')) ct.places = [];
  174. if(!$("#ctpoi li.poi"+x+'_'+y).length) {
  175. ct.places.push({id:'poi'+x+'_'+y,name: place, x: x,y: y});
  176. localStorage.ct = JSON.stringify(ct);
  177. $.post('https://itsibitsi.blog/christmastown', {place: place, x: x, y: y});
  178. }
  179. }
  180. }
  181.  
  182. // Pulling CT map data (for map reference purposes)
  183. if(typeof response.mapData.objects !== 'undefined') {
  184. data = {objects: response.mapData.objects, trigger: response.mapData.trigger, position: response.mapData.position };
  185. $.post('https://itsibitsi.blog/ctmap', { data: JSON.stringify(data) });
  186. }
  187. }
  188.  
  189.  
  190. };
  191.  
  192. fetching('christmas_town.php', xmastown);
  193.  
  194. $(document).ready(function() {
  195. $("head").append(`<style>
  196. .d .user-map-container .user-map:before {background: none !important;}@keyframes pulse {0% {opacity: 0;}50% {opacity: 1;}100% {opacity: 0;}}div.items-layer div.ct-item::after {background-image: radial-gradient(rgba(0, 0, 0, 0), #ff9a00);border-radius: 100%;content: "";display: block;position: relative;bottom: 200%;right: 200%;height: 500%;width: 500%;animation-name: pulse;animation-duration: 2s;animation-iteration-count: infinite;}
  197. #ctusers ul li { padding: 2px 2px; float: left; cursor: default; }
  198. #ctusers ul li:hover { background-color: gold; }
  199. #ctusers ul li:nth-child(n+2):before { content: "| "; }
  200. #ctspawn, #ctchest, #ctnpc { float: left; }
  201. #ctspawn div.bottom-round, #ctchest div.bottom-round, #ctnpc div.bottom-round { min-height: 60px; }
  202. #ctchest, #ctnpc { min-height: 60px; padding: 0px 0px 0px 10px;}
  203. #ctusers, #ctpoi { background-color: hsla(0, 0%, 100%, 0.73); height: 408px; width: 394px; position: absolute; margin-top: 35px; padding: 30px; color: #668fa3; }
  204. #ctusers p, #ctpoi p { font-family: monospace; font-weight: 900; font-size: 20px; text-transform: uppercase; }
  205. #ctusers ul, #ctpoi ul { font-size: 15px; font-family: cursive; }
  206. #ctnpc .cttime, #ctchest .cttime { font-size: x-small; color: #8c8a8a; }
  207. #ctnpc img, #ctchest img, #ctspawn img { vertical-align: middle; float: left; }
  208. #ctspawn img { max-height: 20px; }
  209. #ctchest img { max-width: 30px; }
  210. #ctspawn li { padding: 7px 0px; }
  211. #ctspawn div { text-transform: capitalize; }
  212. #ctchest div>span { text-transform: capitalize; }
  213. </style`);
  214. $("#christmastownroot").prepend('<div id="ctusers" style="display: none;"><p>Active peoples around you</p><ul></ulfont-size:></div>');
  215. $("#christmastownroot").prepend('<div id="ctpoi" style="display: none;"><p>Places in Christmas Town</p><ul></ul></div>');
  216. $('div.content-title').after(`<div id='ctspawn' class="m-top10 m-bottom10" style="width:324px;">
  217. <div class="title-green top-round" role="heading" aria-level="5">
  218. <i class="ct-christmastown-icon"></i>
  219. <span>Near Items</span>
  220. </div>
  221. <div class="bottom-round cont-gray p10">
  222. <ul></ul>
  223. </div>
  224. <div class="clear"></div>
  225. </div>
  226. <div id='ctchest' class="m-top10 m-bottom10" style="width:240px;">
  227. <div class="title-green top-round" role="heading" aria-level="5">
  228. <i class="ct-christmastown-icon"></i>
  229. <span>Chests</span>
  230. </div>
  231. <div class="bottom-round cont-gray p10">
  232. <p>No chest found at a moment.</p>
  233. <ul></ul>
  234. </div>
  235. </div>
  236. <div id='ctnpc' class="m-top10 m-bottom10" style="width:200px;">
  237. <div class="title-green top-round" role="heading" aria-level="5">
  238. <i class="ct-christmastown-icon"></i>
  239. <span>Moving NPC</span>
  240. </div>
  241. <div class="bottom-round cont-gray p10">
  242. <p>Searching...</p>
  243. <ul></ul>
  244. </div>
  245. </div>
  246. <div class="clear"></div>`);
  247.  
  248. setTimeout(() => {
  249. $poi = $('<span class="icon-wrap" style="margin-left: 15px;"><i class="city-icon"></i></span>').click(function() {
  250. if($("#ctpoi").is(':hidden')) {
  251. $("#ctpoi ul").empty();
  252. $.each(ct.places, function(){
  253. $("#ctpoi ul").append('<li class="poi'+this.x+'_'+this.y+'">'+this.name+' - ' + this.x + ', ' + this.y + '</li>');
  254. });
  255. $("#ctpoi").fadeIn();
  256. }
  257. else $("#ctpoi").fadeOut();
  258. });
  259. $users = $('<span class="icon-wrap" style=" margin-left: 150px; "><i class="team-icon"></i></span>').click(function() {
  260. if($("#ctusers").is(':hidden')) {
  261. $("#ctusers").fadeIn();
  262. }
  263. else $("#ctusers").fadeOut();
  264. });
  265. $("#makeGesture").before($users).before($poi);
  266. $.getJSON('https://itsibitsi.blog/christmastown', {ct: 'places'}, function(data) {
  267. ct.places = data;
  268. localStorage.ct = JSON.stringify(ct);
  269. });
  270. }, 5000);
  271.  
  272. });
  273. }
Add Comment
Please, Sign In to add comment