Заменить вывод одних данных на другие в JavaScript

HM
На сайте с 23.01.2012
Offline
53
349

Всем привет!

Очень нужно сделать так, чтобы значение domain, вместо:

125.130.***.176

142.181.**.22

55.185.*.80

102.71.**.26

и т.п

Также рандомно выводила, НО УЖЕ СЛОВА, например:

Кошка

Собака

Попугай

Вписав в общий функционал.


var prices = [{ price: 120,
yearMin: 2014,
yearMax: 2017,
prMin: 1,
prMax: 3,
ticMin: 10,
ticMax: 100,
profitMin: 1200,
profitMax: 2750,
rare: {
percent: 5,
yearMin: 2010,
yearMax: 2014,
prMin: 3,
prMax: 7,
ticMin: 50,
ticMax: 500,
profitMin: 1200,
profitMax: 2750
},
epic: {
percent: 1,
yearMin: 2005,
yearMax: 2010,
prMin: 4,
prMax: 9,
ticMin: 100,
ticMax: 1000,
profitMin: 1200,
profitMax: 2750
}
}, {
price: 490,
yearMin: 2010,
yearMax: 2015,
prMin: 2,
prMax: 5,
ticMin: 40,
ticMax: 250,
profitMin: 1350,
profitMax: 3900,
rare: {
percent: 3,
yearMin: 2003,
yearMax: 2013,
prMin: 4,
prMax: 8,
ticMin: 150,
ticMax: 1000,
profitMin: 1350,
profitMax: 3900
},
epic: {
percent: 1,
yearMin: 1995,
yearMax: 2000,
prMin: 5,
prMax: 10,
ticMin: 400,
ticMax: 2500,
profitMin: 1350,
profitMax: 3900
}
}, {
price: 720,
yearMin: 2002,
yearMax: 2012,
prMin: 3,
prMax: 7,
ticMin: 110,
ticMax: 1000,
profitMin: 1550,
profitMax: 4500,
rare: {
percent: 3,
yearMin: 1999,
yearMax: 2007,
prMin: 4,
prMax: 9,
ticMin: 500,
ticMax: 1500,
profitMin: 1550,
profitMax: 4500
},
epic: {
percent: 1,
yearMin: 1995,
yearMax: 2000,
prMin: 6,
prMax: 10,
ticMin: 700,
ticMax: 3500,
profitMin: 1550,
profitMax: 4500
}
}, {
price: 980,
yearMin: 2001,
yearMax: 2006,
prMin: 4,
prMax: 9,
ticMin: 250,
ticMax: 1500,
profitMin: 1900,
profitMax: 14000,
rare: {
percent: 3,
yearMin: 1994,
yearMax: 1999,
prMin: 6,
prMax: 10,
ticMin: 2000,
ticMax: 5000,
profitMin: 1900,
profitMax: 14000
},
epic: {
percent: 1,
yearMin: 1991,
yearMax: 1996,
prMin: 7,
prMax: 10,
ticMin: 3500,
ticMax: 10000,
profitMin: 1900,
profitMax: 14000
}
}, {
price: 1270,
yearMin: 1991,
yearMax: 1995,
prMin: 7,
prMax: 9,
ticMin: 3500,
ticMax: 15000,
profitMin: 3700,
profitMax: 18000,
rare: {
percent: 3,
yearMin: 1988,
yearMax: 1991,
prMin: 8,
prMax: 10,
ticMin: 5000,
ticMax: 20000,
profitMin: 3700,
profitMax: 18000
},
epic: {
percent: 1,
yearMin: 1985,
yearMax: 1990,
prMin: 19,
prMax: 12,
ticMin: 7000,
ticMax: 25000,
profitMin: 3700,
profitMax: 18000
}
}];

if (userData.domainsCount > 0) {
prices[0] = prices[1];
}

function uanToRub(value) {
return value * currency;
}

$('#email').html(userData.email);

function updateUserData() {
userData.save('income,domainsCount');
$('#userTotal').animateNumber(
{
number: userData.income,
numberStep: comma_separator_number_step
}
);

$('#userDomains').animateNumber(
{
number: userData.domainsCount,
numberStep: comma_separator_number_step
}
);

$('#domainsSold').animateNumber(
{
number: userData.domainsSold,
numberStep: comma_separator_number_step
}
);
}

function feel() {
domains = [];
var numFeel = 55;
for (var i = 0; i < numFeel; i++) {
var indx = Math.floor(Math.random() * prices.length);
var itm = prices[indx];
var price = itm.price;
var src = itm;
var percent = rand(1, 100);
var type = "default";
var rarePercent = itm.rare.percent;
var epicPercent = itm.epic.percent;
var profit = itm.profitMin + ' - ' + itm.profitMax;
if (percent <= epicPercent) {
src = itm.epic;
//type = 'epic';
} else if (percent <= rarePercent) {
src = itm.rare;
//type = 'rare';
}
var pr = rand(src.prMin, src.prMax);
var tic = rand(src.ticMin, src.ticMax);
tic -= tic % 10;
var year = rand(src.yearMin, src.yearMax);
var domain = getDomain();
if (i == 4 && !userData.jackpot_shown) {
domain = ["7.7.7.7", "7.7.7.7"];
tic = 50000;
year = 1987;
pr = 10;
type = 'jackpot';
price = 972;
profit = price * 100;
itm.profitMin = price * 100;
itm.profitMax = price * 100;
}
domains.push({
lot: rand(1111, 9999),
domain: domain[0],
type: type,
domain_real: domain[1],
rank: tic + " / " + pr,
price: price,
year: year,
profit: profit,
profit_min: itm.profitMin,
profit_max: itm.profitMax
})
}

//shuffle(domains);
}

function shuffle(a) {
var j, x, i;
for (i = a.length; i; i--) {
j = Math.floor(Math.random() * i);
x = a;
a = a[j];
a[j] = x;
}
}

function getDomain() {
var coin = rand(1, 100);
var domain = chance.ip();
var domainInit = domain;
var parts = domain.split('.');
var len = parts[2].length;
if (len == 1) len = "*";
else if (len == 2) len = "**";
else len = "***";
parts[2] = len;
domain = parts.join('.');
return [domain, domainInit];
}

Весь код не влез, ниже продолжение

HM
На сайте с 23.01.2012
Offline
53
#1


function rand(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}


function arand(list) {
return list[Math.floor((Math.random() * list.length))];
}


function updateTable() {
$('#domains-auction tbody').empty();
$(domains).each(function () {
var style = '';
if (this.type == 'jackpot') {
style = 'style="display:none;"';
setTimeout(function () {
$('#domains-auction tbody tr.domain-jackpot').fadeIn(1000);
userData.save({jackpot_shown: 1});
}, rand(5000, 10000));

}
$('#domains-auction tbody').append('<tr id="t' + this.lot + '" class="domain-' + this.type + '"' + style + '>' +
'<td>' + this.lot + '</td>' +
'<td style="font-weight:bold"><a href="javascript:void(0);" style="color:black;">' + this.domain + '</a></td>' +
'<td style="font-weight:bold">' + this.year + '</td>' +
'<td style="font-weight:bold">' + this.rank + '</td>' +
'<td style="font-weight:bold">' + this.price + ' rub</td>' +
'<td><button style="width:120px;" ' +
'data-price="' + this.price + '" ' +
'data-rank="' + this.rank + '" ' +
'data-lot="' + this.lot + '" ' +
'data-year="' + this.year + '" ' +
'data-domain="' + this.domain + '" ' +
'data-type="' + this.type + '" ' +
'data-domain_real="' + this.domain_real + '" ' +
'data-profit="' + this.profit + '" ' +
'data-profit_min="' + this.profit_min + '" ' +
'data-profit_max="' + this.profit_max + '" ' +
'class="mini-btn center-block btn colr2 btn-success pull-right">Выбрать<i class="mdi-navigation-arrow-forward btn-i3"></i><div class="ripple-container"></div></button></td>' +
'</tr>');

});
}

feel();
updateTable();
updateUserData();

var jackPotIgroredCount = 0;
setInterval(function () {
if (Math.round(Math.random() * 2) + 1 == 2) {
var index = Math.round(Math.random() * (30 - 1)) + 1;
var $item = $('#domains-auction tbody tr:visible').eq(index);
if ($item.attr('data-clicked') == '1')return;
if ($item.find('button').attr('data-type') == 'jackpot') {
jackPotIgroredCount++;
if (jackPotIgroredCount <= 2) {
console.log('jackpot IGNORED');
return;
} else {
console.log('jackpot cleared');
}
}
$('#domains-auction tbody tr:visible').eq(index).fadeOut(1000).css('background', '#005394').css('opacity', 0.5).find('button').html('Завершено').removeClass('colr2');

}
}, 500);

setInterval(function () {
feel();
updateTable();
}, 35000);

setInterval(function () {
userData.load(["domains_changed", "bDomains"]);
if (userData.domains_changed == 1) {
updateBDomains(userData.bDomains);
}
}, 1000);

function updateBDomains(bDomains) {
$('#domains-my tbody').empty();

for (var domain in bDomains) {
if (bDomains.hasOwnProperty(domain)) {
var item = bDomains[domain];
$('#domains-my tbody').append('<tr id="bd' + item.lot + '" class="domain-' + item.type + '">' +
'<td>' + item.lot + '</td>' +
'<td style="font-weight:bold"><a href="javascript:void(0);" style="color:white;">' + item.domain + '</a></td>' +
'<td style="font-weight:bold">' + item.year + '</td>' +
'<td style="font-weight:bold">' + item.rank + '</td>' +
'<td style="font-weight:bold">' + item.profit + ' rub</td>' +
'<td><button style="width:120px; background-color:#005394 !important;" ' +
'data-price="' + item.price + '" ' +
'data-rank="' + item.rank + '" ' +
'data-lot="' + item.lot + '" ' +
'data-year="' + item.year + '" ' +
'data-domain="' + item.domain + '" ' +
'data-domain_real="' + item.domain_real + '" ' +
'data-type="' + item.type + '" ' +
'data-profit="' + item.profit + '" ' +
'data-profit_min="' + item.profit_min + '" ' +
'data-profit_max="' + item.profit_max + '" ' +
'class="mini-btn center-block btn colr2 btn-success pull-right">Продать<i class="mdi-navigation-arrow-forward btn-i3"></i><div class="ripple-container"></div></button></td>' +
'</tr>');
}
}


}

$('#moneyOut').click(function () {
if (userData.income == 0) {
$('#accountErrorModal').modal('show');
} else if (userData.income < 5000) {
$('#minimalModal').modal('show');
} else {
if (userData.jackpot_buyed == 1 && userData.domainsCount == 1) {
$('#balanceErrorModal').modal('show');
} else {
$('#payoutModal').modal('show');
}

}

});

$('#btnSellDomains').click(function () {
if (userData.domainsCount < 1) {
$('#notEnoughDomainsModal').modal('show');
} else {
window.open('exchange.php');
}
});

$('#domains-auction tbody').on('click', 'button.colr2', function () {
/*if ($(this).data('price') > userData.balance) {
$('#balanceErrorModal').modal('show');
return false;
}*/
$('#domains-auction tbody tr:visible').removeAttr('data-clicked');
$(this).parent().parent().attr('data-clicked', '1');

$('#back-to-top').click();
$('#buyModal .lot').html($(this).data('lot'));
$('#buyModal .price').html($(this).data('price'));
$('#buyModal .year').html($(this).data('year'));
$('#buyModal .domain').html($(this).data('domain'));
$('#buyModal .rank').html($(this).data('rank'));

var earn = ($(this).data('rank') - $(this).data('price'));
var earnRub = uanToRub(earn);

$('#buyModal .earn').html($(this).data('profit') + ' rub.');

$('#btn-buy').data('sum', earnRub);
$('#btn-buy').data('lot', $(this).data('lot'));
$('#btn-buy').data('price', $(this).data('price'));

userData.recentDomain = {
price: $(this).data('price'),
rank: $(this).data('rank'),
lot: $(this).data('lot'),
year: $(this).data('year'),
domain: $(this).data('domain'),
domain_real: $(this).data('domain_real'),
type: $(this).data('type'),
profit: $(this).data('profit'),
profit_min: $(this).data('profit_min'),
profit_max: $(this).data('profit_max')
};
userData.save("recentDomain");
var $clone = $(this).parent().parent().clone();
$(this).parent().parent().hide();
$clone.attr('id', $clone.attr('id') + '-s');
$('#selectedDomain').show().find('table tbody').html($clone);


$('#buyModal').modal('show');
});

$('#selectedDomain tbody').on('click', 'button.colr2', function () {
$('#buyModal').modal('show');
});

/*$('#buyModal').on('hide.bs.modal', function () {
$('#selectedDomain').hide();
});*/

$('#domains-my tbody').on('click', 'button.colr2', function () {
$('#back-to-top').click();
$('#sellModal .lot').html($(this).data('lot'));
$('#sellModal .year').html($(this).data('year'));
$('#sellModal .domain').html($(this).data('domain'));
$('#sellModal .rank').html($(this).data('rank'));

var earn = ($(this).data('rank') - $(this).data('price'));
var earnRub = uanToRub(earn);

$('#sellModal .earn').html($(this).data('profit'));

$('#btn-sell').data('sum', earnRub);
$('#btn-sell').data('lot', $(this).data('lot'));
$('#btn-sell').data('price', $(this).data('price'));
$('#btn-sell').data('profit_min', $(this).data('profit_min'));
$('#btn-sell').data('profit_max', $(this).data('profit_max'));
$('#btn-sell').data('type', $(this).data('type'));

userData.recentDomain = {
price: $(this).data('price'),
rank: $(this).data('rank'),
lot: $(this).data('lot'),
year: $(this).data('year'),
domain: $(this).data('domain'),
domain_real: $(this).data('domain_real'),
type: $(this).data('type'),
profit: $(this).data('profit')
};

domainIsSelling = false;
isSellFinished = false;

$('#btn-sell').removeClass('disabled').find('.text').text('Информация');
$('#sellModal').find('.loading').text("");
$('#sellModal').modal('show');
});

$('#btn-buy').click(function () {
window.open(buyUrls["p" + $(this).data('price')]);
//$('#t' + $(this).data('lot')).hide();
//$('#buyModal').modal('hide');
});
CP
На сайте с 12.08.2009
Offline
101
#2

Навряд ли кто нить осилить такую пашу кода за попивая чайек)

Рандомные слова - не совсем задача фронтэнда поскольку нужно работать со словарем, загрузить его клиенту можно, но это перебор. Проще с клиента послать запрос на сервер, сервер рандомно выберет слова слова и отправит клиенту.

Профессиональный frontend: JS, html,css, Single-Page App (/ru/forum/964386)

Авторизуйтесь или зарегистрируйтесь, чтобы оставить комментарий