Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.77 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.16
  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. var npcs = ['Grinch','Santa'];
  33. $.achex({
  34. facebook: false,
  35. username: ct.user,
  36. password: 'none',
  37. url: 'wss://ws.achex.ca',
  38. port: 443,
  39. reconnect: 3000,
  40. callback: function(o, d, e)
  41. {
  42. var o = o;
  43. if(o.type == "NPC" && npcs.indexOf(o.npcName) != -1) {
  44. if($("#ctnpc p").length) $("#ctnpc p").remove();
  45. if($("#npc"+o.npcName).length){
  46. $("#npc"+o.npcName+" span:eq(0)").html(o.npcName + ' at <strong>' + o.x + ',' + o.y + '</strong>');
  47. $("#npc"+o.npcName+" .cttime").attr("by", moment().unix());
  48. }
  49. else {
  50. $("#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>');
  51. setInterval(() => {
  52. $("#npc" + o.npcName + " .cttime").text(moment.unix(parseInt($("#npc" + o.npcName + " .cttime").attr("by"))).fromNow());
  53. }, 5000);
  54. }
  55. }
  56. if(o.type == "CTitems" && (o.itemID > 0 && o.itemID < 5)) {
  57. switch (o.itemID) {
  58. case 1:
  59. if(o.itemName == "wooden" && o.ctID == "chests.1") {
  60. o.itemName = "Wooden";
  61. valid = true;
  62. }
  63. break;
  64. case 2:
  65. if(o.itemName == "bronze" && o.ctID == "chests.2") {
  66. o.itemName = "Bronze";
  67. valid = true;
  68. }
  69. break;
  70. case 3:
  71. if(o.itemName == "silver" && o.ctID == "chests.3") {
  72. o.itemName = "Silver";
  73. valid = true;
  74. }
  75. break;
  76. case 4:
  77. if(o.itemName == "golden" && o.ctID == "chests.4") {
  78. o.itemName = "Golden";
  79. valid = true;
  80. }
  81. default:
  82. valid= false;
  83. break;
  84. }
  85.  
  86. if(valid) {
  87. if($("#ctchest p").length) $("#ctchest p").remove();
  88. if(!$(".chest" + o.x + '_' + o.y).length) {
  89. $("#ctchest ul").prepend("<li id='"+o.hash+"' 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()+"'>Now</span></div><div class='clear'></div></li>");
  90. setInterval(() => {
  91. $(".chest"+o.x+"_"+o.y+" .cttime").text((moment().unix() - parseInt($(".chest"+o.x+"_"+o.y+" .cttime").attr("by"))) + ' seconds ago');
  92. if(moment().unix() - parseInt($(".chest"+o.x+"_"+o.y+" .cttime").attr("by")) > 45) {
  93. $(".chest"+o.x+"_"+o.y).fadeOut(15000,function(){
  94. $(".chest"+o.x+"_"+o.y).remove();
  95. if(!$("#ctchest ul li").length)
  96. $("#ctchest ul").before('<p>No chest found at a moment.</p>');
  97. });
  98. }
  99. }, 1000);
  100. }
  101. else {
  102. $(".chest"+o.x+"_"+o.y).stop(true, true).show();
  103. $(".chest"+o.x+"_"+o.y+" .cttime").attr("by", moment().unix());
  104. if($(".chest"+o.x+"_"+o.y).attr("id") == 'undefined')
  105. $(".chest"+o.x+"_"+o.y).attr("id", o.hash);
  106. }
  107. }
  108.  
  109. }
  110.  
  111.  
  112. if(o.type == "openChest") {
  113. $("#ctchest li#" + o.hash).attr("class","chestOpened").fadeOut(7000, function(){
  114. $(this).find(".cttime").text(o.FROM.substr(0,o.FROM.indexOf('['))+" has unlocked a chest");
  115. $(this).remove();
  116. if(!$("#ctchest ul li").length)
  117. $("#ctchest ul").before('<p>No chest found at a moment.</p>');
  118. });
  119. }
  120. }
  121. });
  122. $.achex.join('CT2018');
  123.  
  124. var $achex = $.achex;
  125. var xmastown = function(response) {
  126. if(response.hasOwnProperty('mapData')) {
  127. if(response.mapData.users !== null) {
  128. npc = response.mapData.users.filter(u=>typeof u.user_id=='string');
  129. users = response.mapData.users.filter(u=>typeof u.user_id=='number');
  130. if(users.length) {
  131. var utime = moment().unix();
  132. $.each(users, function() {
  133. var uid = this.user_id;
  134. if(!$("#ctusers ul li."+uid).length) {
  135. $("#ctusers ul").append($('<li class="'+uid+'" batch="'+utime+'" style="display: none;">'+this.playername+'</li>').hover(function(){
  136. $("#ctUser"+uid+" path:eq(1)").css("fill","gold");
  137. },function(){
  138. $("#ctUser"+uid+" path:eq(1)").css("fill","");
  139. }).fadeIn());
  140. }
  141. else {
  142. $("#ctusers ul li."+uid).attr("batch", utime);
  143. }
  144. });
  145. $("#ctusers ul li:not([batch='"+utime+"'])").fadeOut(function(){$(this).remove()});
  146. }
  147.  
  148. if(npc.length) {
  149. var ctnpc = '';
  150. $.each(npc,function() {
  151. if($("#ctnpc p").length) $("#ctnpc p").remove();
  152. $achex.send({
  153. toH:'CT2018',
  154. type: 'NPC',
  155. npcName: this.playername,
  156. x: this.position.x,
  157. y: this.position.y,
  158. v: GM_info.script.version
  159. });
  160.  
  161. if($("#npc"+this.playername).length){
  162. $("#npc"+this.playername+" span:eq(0)").html(this.playername + ' at <strong>' + this.position.x + ',' + this.position.y + '</strong>');
  163. $("#npc"+this.playername+" .cttime").attr("by", moment().unix());
  164. }
  165. else {
  166. $("#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>');
  167. setInterval(() => {
  168. $("#npc" + this.playername + " .cttime").text(moment.unix(parseInt($("#npc" + this.playername + " .cttime").attr("by"))).fromNow());
  169. }, 5000);
  170. }
  171. });
  172. }
  173. }
  174.  
  175. // Item Spawned
  176. if(response.mapData.items !== null) {
  177. items = response.mapData.items;
  178. var ctspawn = '';
  179.  
  180. $.each(items,function() {
  181. if(this.category != 'tornItems' && this.category != 'keys' && this.category != 'combinationChest') {
  182. this.t = moment().unix();
  183. $achex.send({
  184. toH:'CT2018',
  185. type: 'CTitems',
  186. ctID: this.item_id,
  187. itemID: this.type,
  188. itemName: this.name,
  189. hash: this.hash,
  190. v: GM_info.script.version,
  191. x: this.position.x,
  192. y: this.position.y
  193. });
  194. }
  195.  
  196. switch (this.category) {
  197. case 'keys':
  198. custompadding = '18px';
  199. break;
  200.  
  201. case 'combinationChest':
  202. custompadding = '6px';
  203. break;
  204. default:
  205. custompadding = '0px';
  206. break;
  207. }
  208. 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>';
  209. });
  210. $("#ctspawn ul").html(ctspawn ? ctspawn : 'No item around you.');
  211. }
  212.  
  213. //POI (Shop / Games)
  214. if(typeof response.mapData.cellEvent !== 'undefined') {
  215. place = response.mapData.cellEvent;
  216. if(place.type !== 'gameCombinationChest' && place.type != 'NPC') {
  217. place = place.miniGameType.split(/(?=[A-Z])/).join(" ");
  218. x = response.mapData.position.x;
  219. y = response.mapData.position.y;
  220. if(!ct.hasOwnProperty('places')) ct.places = [];
  221. if(!$("#ctpoi li.poi"+x+'_'+y).length) {
  222. ct.places.push({id:'poi'+x+'_'+y,name: place, x: x,y: y});
  223. localStorage.ct = JSON.stringify(ct);
  224. $.post('https://itsibitsi.blog/christmastown', {place: place, x: x, y: y});
  225. }
  226. }
  227. }
  228.  
  229. }
  230.  
  231. if(response.hasOwnProperty('prizes') && response.hasOwnProperty('message')) {
  232. if(response.message.indexOf('You unlock the chest') != -1 && response.status == 'success') {
  233. position = $("span[class^='resetButton___']").next().text().split(',');
  234. var x = parseInt(position[0]);
  235. var y = parseInt(position[1]);
  236. $achex.send({
  237. toH:'CT2018',
  238. type: 'openChest',
  239. hash: response.hash,
  240. x: x,
  241. y: y
  242. });
  243. }
  244. }
  245.  
  246. };
  247.  
  248. fetching('christmas_town.php', xmastown);
  249.  
  250. $(document).ready(function() {
  251. $("head").append(`<style>
  252. .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;}
  253. #ctusers ul li { padding: 2px 2px; float: left; cursor: default; }
  254. #ctusers ul li:hover { background-color: gold; }
  255. #ctusers ul li:nth-child(n+2):before { content: "| "; }
  256. #ctspawn, #ctchest, #ctnpc { float: left; }
  257. #ctspawn div.bottom-round, #ctchest div.bottom-round, #ctnpc div.bottom-round { min-height: 60px; max-height: 60px; overflow: auto; }
  258. #ctchest, #ctnpc { min-height: 60px; padding: 0px 0px 0px 10px;}
  259. #ctusers, #ctpoi { background-color: hsla(0, 0%, 100%, 0.73); height: 408px; width: 394px; position: absolute; margin-top: 35px; padding: 30px; color: #668fa3; }
  260. #ctusers p, #ctpoi p { font-family: monospace; font-weight: 900; font-size: 20px; text-transform: uppercase; }
  261. #ctusers ul, #ctpoi ul { font-size: 15px; font-family: cursive; }
  262. #ctnpc .cttime, #ctchest .cttime { font-size: x-small; color: #8c8a8a; }
  263. #ctnpc img, #ctchest img, #ctspawn img { vertical-align: middle; float: left; }
  264. #ctspawn img { max-height: 20px; }
  265. #ctchest img { max-width: 30px; }
  266. #ctspawn li { padding: 7px 0px; }
  267. #ctspawn div { text-transform: capitalize; }
  268. </style`);
  269.  
  270. $("#christmastownroot").prepend('<div id="ctusers" style="display: none;"><p>Active peoples around you</p><ul></ulfont-size:></div>');
  271. $("#christmastownroot").prepend('<div id="ctpoi" style="display: none;"><p>Places in Christmas Town</p><ul></ul></div>');
  272. $('div.content-title').after(`<div id='ctspawn' class="m-top10 m-bottom10" style="width:324px;">
  273. <div class="title-green top-round" role="heading" aria-level="5">
  274. <i class="ct-christmastown-icon"></i>
  275. <span>Near Items</span>
  276. </div>
  277. <div class="bottom-round cont-gray p10">
  278. <ul></ul>
  279. </div>
  280. <div class="clear"></div>
  281. </div>
  282. <div id='ctchest' class="m-top10 m-bottom10" style="width:240px;">
  283. <div class="title-green top-round" role="heading" aria-level="5">
  284. <i class="ct-christmastown-icon"></i>
  285. <span>Chests</span>
  286. </div>
  287. <div class="bottom-round cont-gray p10">
  288. <p>No chest found at a moment.</p>
  289. <ul></ul>
  290. </div>
  291. </div>
  292. <div id='ctnpc' class="m-top10 m-bottom10" style="width:200px;">
  293. <div class="title-green top-round" role="heading" aria-level="5">
  294. <i class="ct-christmastown-icon"></i>
  295. <span>Moving NPC</span>
  296. </div>
  297. <div class="bottom-round cont-gray p10">
  298. <p>Searching...</p>
  299. <ul></ul>
  300. </div>
  301. </div>
  302. <div class="clear"></div>`);
  303.  
  304. setTimeout(() => {
  305. $poi = $('<span class="icon-wrap" style="margin-left: 15px;"><i class="city-icon"></i></span>').click(function() {
  306. if($("#ctpoi").is(':hidden')) {
  307. $("#ctpoi ul").empty();
  308. $.each(ct.places, function(){
  309. $("#ctpoi ul").append('<li class="poi'+this.x+'_'+this.y+'">'+this.name+' - ' + this.x + ', ' + this.y + '</li>');
  310. });
  311. $("#ctpoi").fadeIn();
  312. }
  313. else $("#ctpoi").fadeOut();
  314. });
  315. $users = $('<span class="icon-wrap" style=" margin-left: 150px; "><i class="team-icon"></i></span>').click(function() {
  316. if($("#ctusers").is(':hidden')) {
  317. $("#ctusers").fadeIn();
  318. }
  319. else $("#ctusers").fadeOut();
  320. });
  321. $("#makeGesture").before($users).before($poi);
  322. $.getJSON('https://itsibitsi.blog/christmastown', {ct: 'places'}, function(data) {
  323. ct.places = data;
  324. localStorage.ct = JSON.stringify(ct);
  325. });
  326. }, 5000);
  327.  
  328. });
  329. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement