Javascript.RU

Создать новую тему Ответ
 
Опции темы Искать в теме
  #1 (permalink)  
Старый 13.03.2017, 14:24
Новичок на форуме
Отправить личное сообщение для Dima2204 Посмотреть профиль Найти все сообщения от Dima2204
 
Регистрация: 13.03.2017
Сообщений: 1

Как исправить ошибку "is better written in dot notation"
// ==UserScript==
// @name FaceIT Extra info in Match Room
// @version 0.4.0
// @description More info for FaceIT match room.
// @author BONNe
// @include https://www.faceit.com/*
// @connect api.worldoftanks.ru
// @connect api.worldoftanks.com
// @license MIT License
// @namespace https://greasyfork.org/users/63466
// ==/UserScript==
/* jshint -W097 */
'use strict';

// Inject script
angular.element(document).ready(function()
{
var $body = angular.element(document.body);
var $rootScope = $body.injector().get('$rootScope');

$rootScope.$on('USER_LOGGED_IN', function()
{
initUser($rootScope);
});

$rootScope.$on('USER_LOGGED_OUT', function()
{
initUser($rootScope);
});

$rootScope.$watch(
function()
{
setTimeout(function()
{
runStatsFunction();
}, 5000);
});
});


// Run script that will collect and add all information
function runStatsFunction()
{
var gameElement = $('section.match-vs');

if (angular.element(gameElement).length)
{
var matchItems = $(".match-team-member .match-team-member__details__name");

matchItems.each(function(idx, el)
{
var href = $(el.getElementsByTagName("a")[0]).attr("href");

if (href)
{
var splitHref = href.split("/");
var nickIdx = splitHref.length - 1;
if (splitHref[nickIdx])
{
$.get("https://api.faceit.com/api/nicknames/" + splitHref[nickIdx], function(data)
{
var game = window.location.href.split('/')[4];

if ($(matchItems[idx]).has('.match-team-member_custom_info').length === 0)
{
$(matchItems[idx]).append("<div class='match-team-member_custom_info'></div>");
var $customInfo = $(matchItems[idx]).children(".match-team-member_custom_info");
var $controlList = $(matchItems[idx]).parent().parent().children(".match-team-member__controls");

var playload = data['payload']['games'][game];
var skill = playload['faceit_elo'];
var country = data['payload']['country'];

$customInfo.append('<div class="custom-info-user-info"></div>');
$customInfo.append('<div class="custom-info-user-ratings"></div>');

getUserDetails(game, playload['game_id'], country, $controlList, $customInfo);
addUserSkill(game, skill, $customInfo);
}
});
}
}
});
}
}

case "wot_RU":
$.ajax(
{
url: 'https://api.worldoftanks.ru/wot/account/info/?application_id=c3b3e8c9b7c294ff52b43396b83384a9&a ccount_id=' + userID,
type: 'GET',
timeout: 30000,
error: function()
{
return true;
},
success: function(json)
{
var userName = json['data'][userID]['nickname'];
var wgRating = json['data'][userID]['global_rating'];
var clanID = json['data'][userID]['clan_id'];
var profileLink = "http://worldoftanks.ru/ru/community/accounts/" + userID + "-" + userName + "/";
var clanLink = "https://ru.wargaming.net/clans/wot/" + clanID + "/";

addWGIcon(profileLink, $controlList);
addFlagIcon(country, $controlList);

addUserName(userName, profileLink, $customInfo);
addUserRating(wgRating, $customInfo);
getClanDetails(clanID, game, $customInfo, $controlList);
}
});
break;


// Add ELO rating value to custom info panel
function addUserSkill(game, skill, $customInfo)
{
// Common, if you havn't got premium, then you should not see this.
if (userHasPremium)
{
var text = "ELO: <strong style='color: " + getLeagueColor(game, skill) + "'>" + skill + "</strong> ";
$customInfo.children(".custom-info-user-ratings").append(text);
}
}


// Add username to custom info panel
function addUserName(userName, profileLink, $customInfo)
{
var text = 'Nickname: <a target="_blank" href="' + profileLink + '"><strong>' + userName + '</strong></a>';

$customInfo.children(".custom-info-user-info").append(text);
}

// Add user ratings to custom info panel
function addUserRating(wgRating, $customInfo)
{
var text = 'WG Rating: <strong style="color: ' + wgColor(wgRating) + '">' + wgRating + '</strong>';

$customInfo.children(".custom-info-user-ratings").append(text);
}

// Add clan details to custom info panel


// Add User WG profile icon to control list panel
function addWGIcon(link, $controlList)
{
var wgIcon = '<a target="_blank" href="' + link + '" tooltip="WG Account" ' +
'class="btn btn-sm btn-text btn-link btn-link-primary match-team-member__controls__button">' +
'<img src="http://cdn-frm-eu.wargaming.net/wot/eu//profile/3/83/15/photo-thumb-535158303-56af78dc.jpeg?_r=1454340319" ' +
'style="width:18px;margin-top:6px;" class="icon-md"></img> </a>';

$(wgIcon).insertBefore($controlList.children(".mat ch-team-member__controls__space"));
}


// Add User Country flag icon to control list panel
function addFlagIcon(country, $controlList)
{
var flagIcon = '<button class="btn btn-sm btn-text btn-link btn-link-primary match-team-member__controls__button">' +
'<img src="https://flags.fmcdn.net/data/flags/small/' + country + '.png" class="icon-md" alt="' + country + '" Flag" height="18px" width="18px"></img></button>';

$(flagIcon).insertBefore($controlList.children(".m atch-team-member__controls__space"));
}


// Add Clan icon to control list panel
function addClanIcon(clanIcon, clanLink, $controlList)
{
var icon = '<a target="_blank" href="' + clanLink + '" tooltip="WG Clan" ' +
'class="btn btn-sm btn-text btn-link btn-link-primary match-team-member__controls__button">' +
'<img src="' + clanIcon + '" style="width:18px;margin-top:6px;" class="icon-md"></img> </a>';

$(icon).insertBefore($controlList.children(".match-team-member__controls__space"));
}


// Get league color depending which game user plays.
function getLeagueColor(game, skill)
{
var color = "grey";

switch (game)
{
case "wot_EU":
color = "#912600";
if (skill > 1099) color = "silver";
if (skill > 1499) color = "gold";
if (skill > 1849) color = "#b9f2ff";
if (skill > 1949) color = "orange";
break;
case "wot_RU":
color = "#912600";
if (skill > 1099) color = "silver";
if (skill > 1499) color = "gold";
if (skill > 1849) color = "#b9f2ff";
if (skill > 1949) color = "orange";
break;
case "wot_NA":
color = "#912600";
if (skill > 1099) color = "silver";
if (skill > 1499) color = "gold";
if (skill > 1849) color = "#b9f2ff";
if (skill > 1949) color = "orange";
break;
default:
if (skill > 800) color = "green";
if (skill > 1100) color = "gold";
if (skill > 1700) color = "orange";
if (skill > 2000) color = "red";
}

return color;
}


// Get wg rating color.
function wgColor(skill)
{
var color = "black";

if (skill > 2020) color = "#cd3333";
if (skill > 4185) color = "#d7b600";
if (skill > 6340) color = "#6d9521";
if (skill > 8525) color = "#4a92b7";
if (skill > 9930) color = "#83579d";

return color;
}


// Init user
function initUser($scope)
{
if ($scope.currentUser === null)
{
userHasPremium = false;
}
else
{
userHasPremium = $scope.currentUser.membership.type === "premium";
}
}


var userHasPremium = false;
Изображения:
Тип файла: jpg код.jpg (11.9 Кб, 5 просмотров)
Ответить с цитированием
  #2 (permalink)  
Старый 13.03.2017, 16:04
Профессор
Отправить личное сообщение для Manyasha Посмотреть профиль Найти все сообщения от Manyasha
 
Регистрация: 21.09.2015
Сообщений: 196

Dima2204,
это не ошибка, а предупреждение.
На сколько я поняла, рекомендуют писать вместо
var country = data['payload']['country'];

так
var country = data.payload.country;

(остальные строчки - аналогично)

P.S. Код проще разбирать, если он оформлен тегами
http://javascript.ru/formatting
Ответить с цитированием
Ответ



Опции темы Искать в теме
Искать в теме:

Расширенный поиск


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
script.onload Как отследить ошибку загрузки файла? khusamov Events/DOM/Window 5 28.01.2012 00:01
.mouseover тормозит в Mozilla. Как исправить? denisOgr jQuery 1 30.08.2011 15:13
Как исправить баг?) Spamol jQuery 2 24.11.2010 23:10
Как вывести ошибку в javascript? MCTrane Общие вопросы Javascript 13 05.05.2010 08:36
Как выдавать ошибку при сбросе загрузки страницы? AvaGet Общие вопросы Javascript 2 11.12.2008 19:04