// ==UserScript==
// @name HWM_MGRewardsStats
// @namespace Небылица
// @version 1.06
// @description Статистика золота и элементов, полученных в ГН
// @author Небылица
// @include /^https{0,1}:\/\/((www|qrator)\.heroeswm\.ru|178\.248\.235\.15)\/mercenary_guild\.php/
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_deleteValue
// @downloadURL https://update.greasyfork.icu/scripts/36802/HWM_MGRewardsStats.user.js
// @updateURL https://update.greasyfork.icu/scripts/36802/HWM_MGRewardsStats.meta.js
// ==/UserScript==
(function() {
"use strict";
// Вспомогательные функции
function sendGETRequest(url, mimeType, callback){ // Универсалка для отправки GET-запроса к url с выставлением заданного MIME Type и исполнением функции callback при получении ответа
var xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
if (typeof mimeType === "string"){
xhr.overrideMimeType(mimeType);
}
if (typeof callback === "function"){
xhr.onreadystatechange = function(){
if (xhr.readyState === 4 && xhr.status === 200){
callback.apply(xhr);
}
};
}
xhr.send();
}
function saveToFile(data, filename, type){ // Сохраняет данные data в файл с именем filename, используя blob-объект с типом type (на базе https://stackoverflow.com/a/30832210)
var file = new Blob([data], {type: type});
if (window.navigator.msSaveOrOpenBlob){ // IE10+
window.navigator.msSaveOrOpenBlob(file, filename);
} else{ // Others
var a = document.createElement("a"),
url = URL.createObjectURL(file);
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
setTimeout(function(){
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
}, 0);
}
}
function addLeadingZero(string){ // Вставляет ведущий ноль в строку с элементом даты/времени, если в ней только 1 цифра
string = string.toString();
if (string.length === 1){string = "0" + string;}
return string;
}
//
// получаем id текущего персонажа и кусок ключа по нему
var plId = document.querySelector("li > a[href^='pl_hunter_stat.php']").getAttribute("href").split("id=")[1],
plIdSubKey = "|#" + plId;
// Забиваем в хранилище дефолтные значения для текущего персонажа (при наличии id-неспецифичных значений из версий 1.03- берём их и затем удаляем, иначе как обычно)
if (GM_getValue("dataCollectionSince" + plIdSubKey) === undefined){ // дата начала сбора статистики
if (GM_getValue("dataCollectionSince") === undefined){
var currentMoment = new Date(),
currentMomentOnServer = new Date(Date.now() + currentMoment.getTimezoneOffset()*60000 + 10800000);
GM_setValue("dataCollectionSince" + plIdSubKey,
addLeadingZero(currentMomentOnServer.getDate()) + "." +
addLeadingZero((currentMomentOnServer.getMonth() + 1)) + "." +
currentMomentOnServer.getFullYear().toString().slice(2, 4) + " " +
addLeadingZero(currentMomentOnServer.getHours()) + ":" +
addLeadingZero(currentMomentOnServer.getMinutes())
);
} else{
GM_setValue("dataCollectionSince" + plIdSubKey, GM_getValue("dataCollectionSince"));
GM_deleteValue("dataCollectionSince");
}
}
if (GM_getValue("currentTask" + plIdSubKey) === undefined){ // текущее задание
if (GM_getValue("currentTask") === undefined){
GM_setValue("currentTask" + plIdSubKey, "-1");
} else{
GM_setValue("currentTask" + plIdSubKey, GM_getValue("currentTask"));
GM_deleteValue("currentTask");
}
}
if (GM_getValue("rewardsList" + plIdSubKey) === undefined){ // полный список наград
if (GM_getValue("rewardsList") === undefined){
GM_setValue("rewardsList" + plIdSubKey, "");
} else{
GM_setValue("rewardsList" + plIdSubKey, GM_getValue("rewardsList"));
GM_deleteValue("rewardsList");
}
}
if (GM_getValue("tasksTotal" + plIdSubKey) === undefined){ // общее число заданий
if (GM_getValue("tasksTotal") === undefined){
GM_setValue("tasksTotal" + plIdSubKey, 0);
} else{
GM_setValue("tasksTotal" + plIdSubKey, GM_getValue("tasksTotal"));
GM_deleteValue("tasksTotal");
}
}
if (GM_getValue("tasksAccomplished" + plIdSubKey) === undefined){ // успешно выполненных
if (GM_getValue("tasksAccomplished") === undefined){
GM_setValue("tasksAccomplished" + plIdSubKey, 0);
} else{
GM_setValue("tasksAccomplished" + plIdSubKey, GM_getValue("tasksAccomplished"));
GM_deleteValue("tasksAccomplished");
}
}
if (GM_getValue("tasksFailed" + plIdSubKey) === undefined){ // проваленных
if (GM_getValue("tasksFailed") === undefined){
GM_setValue("tasksFailed" + plIdSubKey, 0);
} else{
GM_setValue("tasksFailed" + plIdSubKey, GM_getValue("tasksFailed"));
GM_deleteValue("tasksFailed");
}
}
if (GM_getValue("goldTotal" + plIdSubKey) === undefined){ // всего золота получено
if (GM_getValue("goldTotal") === undefined){
GM_setValue("goldTotal" + plIdSubKey, 0);
} else{
GM_setValue("goldTotal" + plIdSubKey, GM_getValue("goldTotal"));
GM_deleteValue("goldTotal");
}
}
if (GM_getValue("elementsTotal" + plIdSubKey) === undefined){ // всего элементов получено
if (GM_getValue("elementsTotal") === undefined){
GM_setValue("elementsTotal" + plIdSubKey, 0);
} else{
GM_setValue("elementsTotal" + plIdSubKey, GM_getValue("elementsTotal"));
GM_deleteValue("elementsTotal");
}
}
if (GM_getValue("elementsDouble" + plIdSubKey) === undefined){ // двойных выпадений
if (GM_getValue("elementsDouble") === undefined){
GM_setValue("elementsDouble" + plIdSubKey, 0);
} else{
GM_setValue("elementsDouble" + plIdSubKey, GM_getValue("elementsDouble"));
GM_deleteValue("elementsDouble");
}
}
// счётчики полученного золота по типам заданий
if (GM_getValue("goldFromArmies" + plIdSubKey) === undefined){ // армии
if (GM_getValue("goldFromArmies") === undefined){
GM_setValue("goldFromArmies" + plIdSubKey, 0);
} else{
GM_setValue("goldFromArmies" + plIdSubKey, GM_getValue("goldFromArmies"));
GM_deleteValue("goldFromArmies");
}
}
if (GM_getValue("goldFromConspirators" + plIdSubKey) === undefined){ // заговорщики
if (GM_getValue("goldFromConspirators") === undefined){
GM_setValue("goldFromConspirators" + plIdSubKey, 0);
} else{
GM_setValue("goldFromConspirators" + plIdSubKey, GM_getValue("goldFromConspirators"));
GM_deleteValue("goldFromConspirators");
}
}
if (GM_getValue("goldFromInvaders" + plIdSubKey) === undefined){ // захватчики
if (GM_getValue("goldFromInvaders") === undefined){
GM_setValue("goldFromInvaders" + plIdSubKey, 0);
} else{
GM_setValue("goldFromInvaders" + plIdSubKey, GM_getValue("goldFromInvaders"));
GM_deleteValue("goldFromInvaders");
}
}
if (GM_getValue("goldFromMonsters" + plIdSubKey) === undefined){ // монстры
if (GM_getValue("goldFromMonsters") === undefined){
GM_setValue("goldFromMonsters" + plIdSubKey, 0);
} else{
GM_setValue("goldFromMonsters" + plIdSubKey, GM_getValue("goldFromMonsters"));
GM_deleteValue("goldFromMonsters");
}
}
if (GM_getValue("goldFromRaids" + plIdSubKey) === undefined){ // набеги
if (GM_getValue("goldFromRaids") === undefined){
GM_setValue("goldFromRaids" + plIdSubKey, 0);
} else{
GM_setValue("goldFromRaids" + plIdSubKey, GM_getValue("goldFromRaids"));
GM_deleteValue("goldFromRaids");
}
}
if (GM_getValue("goldFromVanguards" + plIdSubKey) === undefined){ // отряды
if (GM_getValue("goldFromVanguards") === undefined){
GM_setValue("goldFromVanguards" + plIdSubKey, 0);
} else{
GM_setValue("goldFromVanguards" + plIdSubKey, GM_getValue("goldFromVanguards"));
GM_deleteValue("goldFromVanguards");
}
}
if (GM_getValue("goldFromBrigands" + plIdSubKey) === undefined){ // разбойники
if (GM_getValue("goldFromBrigands") === undefined){
GM_setValue("goldFromBrigands" + plIdSubKey, 0);
} else{
GM_setValue("goldFromBrigands" + plIdSubKey, GM_getValue("goldFromBrigands"));
GM_deleteValue("goldFromBrigands");
}
}
// счётчики выполненных заданий по типам
if (GM_getValue("accomplishedArmies" + plIdSubKey) === undefined){ // армии
if (GM_getValue("accomplishedArmies") === undefined){
GM_setValue("accomplishedArmies" + plIdSubKey, 0);
} else{
GM_setValue("accomplishedArmies" + plIdSubKey, GM_getValue("accomplishedArmies"));
GM_deleteValue("accomplishedArmies");
}
}
if (GM_getValue("accomplishedConspirators" + plIdSubKey) === undefined){ // заговорщики
if (GM_getValue("accomplishedConspirators") === undefined){
GM_setValue("accomplishedConspirators" + plIdSubKey, 0);
} else{
GM_setValue("accomplishedConspirators" + plIdSubKey, GM_getValue("accomplishedConspirators"));
GM_deleteValue("accomplishedConspirators");
}
}
if (GM_getValue("accomplishedInvaders" + plIdSubKey) === undefined){ // захватчики
if (GM_getValue("accomplishedInvaders") === undefined){
GM_setValue("accomplishedInvaders" + plIdSubKey, 0);
} else{
GM_setValue("accomplishedInvaders" + plIdSubKey, GM_getValue("accomplishedInvaders"));
GM_deleteValue("accomplishedInvaders");
}
}
if (GM_getValue("accomplishedMonsters" + plIdSubKey) === undefined){ // монстры
if (GM_getValue("accomplishedMonsters") === undefined){
GM_setValue("accomplishedMonsters" + plIdSubKey, 0);
} else{
GM_setValue("accomplishedMonsters" + plIdSubKey, GM_getValue("accomplishedMonsters"));
GM_deleteValue("accomplishedMonsters");
}
}
if (GM_getValue("accomplishedRaids" + plIdSubKey) === undefined){ // набеги
if (GM_getValue("accomplishedRaids") === undefined){
GM_setValue("accomplishedRaids" + plIdSubKey, 0);
} else{
GM_setValue("accomplishedRaids" + plIdSubKey, GM_getValue("accomplishedRaids"));
GM_deleteValue("accomplishedRaids");
}
}
if (GM_getValue("accomplishedVanguards" + plIdSubKey) === undefined){ // отряды
if (GM_getValue("accomplishedVanguards") === undefined){
GM_setValue("accomplishedVanguards" + plIdSubKey, 0);
} else{
GM_setValue("accomplishedVanguards" + plIdSubKey, GM_getValue("accomplishedVanguards"));
GM_deleteValue("accomplishedVanguards");
}
}
if (GM_getValue("accomplishedBrigands" + plIdSubKey) === undefined){ // разбойники
if (GM_getValue("accomplishedBrigands") === undefined){
GM_setValue("accomplishedBrigands" + plIdSubKey, 0);
} else{
GM_setValue("accomplishedBrigands" + plIdSubKey, GM_getValue("accomplishedBrigands"));
GM_deleteValue("accomplishedBrigands");
}
}
// счётчики полученных элементов по типам
if (GM_getValue("gainedAbrasives" + plIdSubKey) === undefined){ // арбазивы
if (GM_getValue("gainedAbrasives") === undefined){
GM_setValue("gainedAbrasives" + plIdSubKey, 0);
} else{
GM_setValue("gainedAbrasives" + plIdSubKey, GM_getValue("gainedAbrasives"));
GM_deleteValue("gainedAbrasives");
}
}
if (GM_getValue("gainedViperVenoms" + plIdSubKey) === undefined){ // змеиные яды
if (GM_getValue("gainedViperVenoms") === undefined){
GM_setValue("gainedViperVenoms" + plIdSubKey, 0);
} else{
GM_setValue("gainedViperVenoms" + plIdSubKey, GM_getValue("gainedViperVenoms"));
GM_deleteValue("gainedViperVenoms");
}
}
if (GM_getValue("gainedTigerClaws" + plIdSubKey) === undefined){ // клыки тигра
if (GM_getValue("gainedTigerClaws") === undefined){
GM_setValue("gainedTigerClaws" + plIdSubKey, 0);
} else{
GM_setValue("gainedTigerClaws" + plIdSubKey, GM_getValue("gainedTigerClaws"));
GM_deleteValue("gainedTigerClaws");
}
}
if (GM_getValue("gainedIceCrystals" + plIdSubKey) === undefined){ // ледяные кристаллы
if (GM_getValue("gainedIceCrystals") === undefined){
GM_setValue("gainedIceCrystals" + plIdSubKey, 0);
} else{
GM_setValue("gainedIceCrystals" + plIdSubKey, GM_getValue("gainedIceCrystals"));
GM_deleteValue("gainedIceCrystals");
}
}
if (GM_getValue("gainedMoonstones" + plIdSubKey) === undefined){ // лунные камни
if (GM_getValue("gainedMoonstones") === undefined){
GM_setValue("gainedMoonstones" + plIdSubKey, 0);
} else{
GM_setValue("gainedMoonstones" + plIdSubKey, GM_getValue("gainedMoonstones"));
GM_deleteValue("gainedMoonstones");
}
}
if (GM_getValue("gainedFireCrystals" + plIdSubKey) === undefined){ // огненные кристаллы
if (GM_getValue("gainedFireCrystals") === undefined){
GM_setValue("gainedFireCrystals" + plIdSubKey, 0);
} else{
GM_setValue("gainedFireCrystals" + plIdSubKey, GM_getValue("gainedFireCrystals"));
GM_deleteValue("gainedFireCrystals");
}
}
if (GM_getValue("gainedMeteoriteShards" + plIdSubKey) === undefined){ // осколки метеорита
if (GM_getValue("gainedMeteoriteShards") === undefined){
GM_setValue("gainedMeteoriteShards" + plIdSubKey, 0);
} else{
GM_setValue("gainedMeteoriteShards" + plIdSubKey, GM_getValue("gainedMeteoriteShards"));
GM_deleteValue("gainedMeteoriteShards");
}
}
if (GM_getValue("gainedWitchBlooms" + plIdSubKey) === undefined){ // цветки ведьм
if (GM_getValue("gainedWitchBlooms") === undefined){
GM_setValue("gainedWitchBlooms" + plIdSubKey, 0);
} else{
GM_setValue("gainedWitchBlooms" + plIdSubKey, GM_getValue("gainedWitchBlooms"));
GM_deleteValue("gainedWitchBlooms");
}
}
if (GM_getValue("gainedWindflowers" + plIdSubKey) === undefined){ // цветки ветров
if (GM_getValue("gainedWindflowers") === undefined){
GM_setValue("gainedWindflowers" + plIdSubKey, 0);
} else{
GM_setValue("gainedWindflowers" + plIdSubKey, GM_getValue("gainedWindflowers"));
GM_deleteValue("gainedWindflowers");
}
}
if (GM_getValue("gainedFernFlowers" + plIdSubKey) === undefined){ // цветки папоротника
if (GM_getValue("gainedFernFlowers") === undefined){
GM_setValue("gainedFernFlowers" + plIdSubKey, 0);
} else{
GM_setValue("gainedFernFlowers" + plIdSubKey, GM_getValue("gainedFernFlowers"));
GM_deleteValue("gainedFernFlowers");
}
}
if (GM_getValue("gainedToadstools" + plIdSubKey) === undefined){ // ядовитые грибы
if (GM_getValue("gainedToadstools") === undefined){
GM_setValue("gainedToadstools" + plIdSubKey, 0);
} else{
GM_setValue("gainedToadstools" + plIdSubKey, GM_getValue("gainedToadstools"));
GM_deleteValue("gainedToadstools");
}
}
//
// задаём некоторые глобальные переменные
var documentInnerHTHL = document.documentElement.innerHTML,
currentTask = GM_getValue("currentTask" + plIdSubKey),
rewardsList = GM_getValue("rewardsList" + plIdSubKey);
// Код для страницы принятого задания
if (documentInnerHTHL.indexOf("минут") !== -1 && documentInnerHTHL.indexOf("Принять") === -1 && documentInnerHTHL.indexOf("Вы еще не приняли это задание") === -1){
// получаем и запоминаем текущее задание
var currentTaskArr = documentInnerHTHL.match(/'(.+?)<\/b>/);
if (currentTaskArr !== null){
GM_setValue("currentTask" + plIdSubKey, currentTaskArr[1]);
}
} else if (documentInnerHTHL.indexOf("мин.") === -1){ // если ни принятого, ни сданного (но ещё не обсчитанного) задания нет, то стираем сохранённое значение
GM_setValue("currentTask" + plIdSubKey, "-1");
}
// Код для страницы сданного задания (с защитой от двойного прогона при обновлении страницы до появления нового)
if (documentInnerHTHL.indexOf("мин.") !== -1 && currentTask !== "-1"){
// увеличиваем счётчик сданных заданий
GM_setValue("tasksTotal" + plIdSubKey, GM_getValue("tasksTotal" + plIdSubKey) + 1);
// получаем текст награды (без статуса)
var rewardArr = documentInnerHTHL.match(/Вы\sполучаете\s(.+?)<\/b>/);
if (rewardArr !== null){ // если награда есть
var reward = rewardArr[1];
// увеличиваем счётчик успешно выполненных заданий
GM_setValue("tasksAccomplished" + plIdSubKey, GM_getValue("tasksAccomplished" + plIdSubKey) + 1);
// увеличиваем кол-во полученного золота
var gainedGold = parseInt(reward.match(/([\d]+?)\sзолота/)[1]);
GM_setValue("goldTotal" + plIdSubKey, GM_getValue("goldTotal" + plIdSubKey) + gainedGold);
// получаем тип задания
var taskTypeArr = (currentTask !== undefined) ? currentTask.match(/(Армия|заговорщики|захватчики|монстр|набеги|Отряд|разбойники)/) : null,
subKey = "";
if (taskTypeArr !== null){
// выставляем кусок ключа в зависимости от типа задания
switch (taskTypeArr[1]){
case "Армия": subKey = "Armies";
break;
case "заговорщики": subKey = "Conspirators";
break;
case "захватчики": subKey = "Invaders";
break;
case "монстр": subKey = "Monsters";
break;
case "набеги": subKey = "Raids";
break;
case "Отряд": subKey = "Vanguards";
break;
case "разбойники": subKey = "Brigands";
}
// увеличиваем пару переменных (сумму полученного золота и счётчик выполненных), соответствующих типу задания
if (subKey !== ""){
GM_setValue("goldFrom" + subKey + plIdSubKey, GM_getValue("goldFrom" + subKey + plIdSubKey) + gainedGold);
GM_setValue("accomplished" + subKey + plIdSubKey, GM_getValue("accomplished" + subKey + plIdSubKey) + 1);
}
}
// получаем выпавшие элементы
var gainedElementsArr = reward.match(/(абразив|змеиный\sяд|клык\sтигра|ледяной\sкристалл|лунный\sкамень|огненный\sкристалл|осколок\sметеорита|цветок\sведьм|цветок\sветров|цветок\sпапоротника|ядовитый\sгриб)/g);
if (gainedElementsArr !== null){ // если элементы есть
var gainedElementsNumber = gainedElementsArr.length;
// увеличиваем общий счётчик выпавших элементов
GM_setValue("elementsTotal" + plIdSubKey, GM_getValue("elementsTotal" + plIdSubKey) + gainedElementsNumber);
// если выпало 2 элемента, то увеличиваем счётчик двойных
if (gainedElementsNumber === 2){
GM_setValue("elementsDouble" + plIdSubKey, GM_getValue("elementsDouble" + plIdSubKey) + 1);
}
// цикл по массиву с элементами
var i,
maxI = gainedElementsNumber;
subKey = "";
for (i=0;i
" +
"
" +
"Выполнено: " + tasksAccomplished + "" + tasksAccomplishedPercentageString + "
" +
"Провалено: " + tasksFailed + "" + tasksFailedPercentageString + "
" +
"
" +
"Золота получено: " + goldTotal + "" + goldTotalPerTaskString + "
" +
"Элементов: " + elementsTotal + "" + elementsTotalPercentageString + "
" +
"Двойных: " + elementsDouble + "" + elementsDoublePercentageString + "
" +
"
" +
"Сбор данных идёт с " + GM_getValue("dataCollectionSince" + plIdSubKey) + "" +
"
" +
"Заговорщики: " + goldFromConspirators + "" + goldFromConspiratorsPerTaskString + "
" +
"Захватчики: " + goldFromInvaders + "" + goldFromInvadersPerTaskString + "
" +
"Монстры: " + goldFromMonsters + "" + goldFromMonstersPerTaskString + "
" +
"Набеги: " + goldFromRaids + "" + goldFromRaidsPerTaskString + "
" +
"Отряды: " + goldFromVanguards + "" + goldFromVanguardsPerTaskString + "
" +
"Разбойники: " + goldFromBrigands + "" + goldFromBrigandsPerTaskString + "
" +
"
" +
"Змеиный яд: " + gainedViperVenoms + "" + gainedViperVenomsPercentageString + "
" +
"Клык тигра: " + gainedTigerClaws + "" + gainedTigerClawsPercentageString + "
" +
"Ледяной кристалл: " + gainedIceCrystals + "" + gainedIceCrystalsPercentageString + "
" +
"Лунный камень: " + gainedMoonstones + "" + gainedMoonstonesPercentageString + "
" +
"Огненный кристалл: " + gainedFireCrystals + "" + gainedFireCrystalsPercentageString + "
" +
"Осколок метеорита: " + gainedMeteoriteShards + "" + gainedMeteoriteShardsPercentageString + "
" +
"Цветок ведьм: " + gainedWitchBlooms + "" + gainedWitchBloomsPercentageString + "
" +
"Цветок ветров: " + gainedWindflowers + "" + gainedWindflowersPercentageString + "
" +
"Цветок папоротника: " + gainedFernFlowers + "" + gainedFernFlowersPercentageString + "
" +
"Ядовитый гриб: " + gainedToadstools + "" + gainedToadstoolsPercentageString + "
" +
"