Advertisement
Guest User

Christmas Town Script

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