// ==UserScript== // @name CurrentQuestOnInfo // @namespace https://github.com/MyRequiem/comfortablePlayingInGW // @description Вывод текущего ужедневного мини-квеста на странице информации персонажа. // @id comfortablePlayingInGW@MyRequiem // @updateURL https://raw.githubusercontent.com/MyRequiem/comfortablePlayingInGW/master/separatedScripts/CurrentQuestOnInfo/currentQuestOnInfo.meta.js // @downloadURL https://raw.githubusercontent.com/MyRequiem/comfortablePlayingInGW/master/separatedScripts/CurrentQuestOnInfo/currentQuestOnInfo.user.js // @include https://*gwars*/info.php?id=* // @grant none // @license MIT // @version 1.20-130522 // @author MyRequiem [https://www.gwars.io/info.php?id=2095458], идея kaa // ==/UserScript== /*global unsafeWindow */ /*jslint browser: true, maxlen: 80, vars: true, nomen: true, regexp: true, plusplus: true */ /*eslint-env browser */ /*eslint no-useless-escape: 'warn', linebreak-style: ['error', 'unix'], quotes: ['error', 'single'], semi: ['error', 'always'], eqeqeq: 'error', curly: 'error' */ /*jscs:disable requireMultipleVarDecl, requireVarDeclFirst */ /*jscs:disable disallowKeywords, disallowDanglingUnderscores */ /*jscs:disable validateIndentation */ (function () { 'use strict'; /** * @class CurrentQuestOnInfo * @constructor */ var CurrentQuestOnInfo = function () { /** * @property root * @type {Object} */ this.root = this.getRoot(); /** * @property doc * @type {Object} */ this.doc = this.root.document; /** * @property persID * @type {String} */ this.persID = /\?id=(\d+)/.exec(this.root.location.href)[1]; /** * @property target * @type {Element|null} */ this.target = this.doc.querySelector('#actiondivin'); /** * @property domain * @type {String} */ this.domain = this.doc.domain; }; /** * @lends CurrentQuestOnInfo.prototype */ CurrentQuestOnInfo.prototype = { /** * @method getRoot * @return {Object} */ getRoot: function () { var rt = typeof unsafeWindow; return rt !== 'undefined' ? unsafeWindow : window; }, /** * @method $ * @param {String} id * @return {HTMLElement|null} */ $: function (id) { return this.doc.querySelector('#' + id); }, /** * @method ajax * @param {String} url * @param {Function} onsuccess * @param {Function} onfailure */ ajax: function (url, onsuccess, onfailure) { var xmlHttpRequest = new XMLHttpRequest(); if (xmlHttpRequest) { xmlHttpRequest.open('GET', url, true); xmlHttpRequest.send(null); var timeout = this.root.setTimeout(function () { xmlHttpRequest.abort(); }, 10000); xmlHttpRequest.onreadystatechange = function () { if (xmlHttpRequest.readyState === 4) { clearTimeout(timeout); if (xmlHttpRequest.status === 200) { onsuccess(xmlHttpRequest); } else { onfailure(); } } }; } }, /** * @method showQuest * @param {String} url */ showQuest: function (url) { var _this = this; this.ajax(url, function (xhr) { var spanContent = _this.doc.createElement('span'); spanContent.innerHTML = xhr.responseText; // noinspection JSUnresolvedVariable var cssSelector = 'td[valign="top"][align="right"]>' + 'a[href*="/help/index.php?sid="]', td = spanContent.querySelector(cssSelector).parentNode. previousElementSibling, questDescr = td.firstElementChild.nextSibling.nodeValue, reg = /^\s*(.*):\s*(\d+) из (\d+)/.exec(questDescr), acQuests = />(\d+)= +reg[3], span = _this.doc.createElement('span'); span.setAttribute('style', 'margin-left: 7px; font-size: 8pt;'); span.innerHTML = '' + reg[1] + ' [' + '' + reg[2] + '/' + reg[3] + '] ' + '(' + acQuests[1] + ')' + '' + ''; _this.target.parentNode.setAttribute('width', '100%'); _this.target.parentNode.nextElementSibling. removeAttribute('width'); _this.target.appendChild(span); var desc = _this.$('questDesc'); if (/суммарный урон.* \d+ HP/.test(desc.innerHTML)) { var val = bLevel * 20; desc.innerHTML = desc.innerHTML. replace(/\d+ HP/, val + ' HP'); desc.innerHTML = desc.innerHTML. replace(/\/\d+\]/, '/' + val + ']'); } var questList = _this.$('questList'), li = questList.querySelectorAll('li'), i; desc = /^(.*) \[/.exec(desc.innerHTML)[1]; for (i = 0; i < li.length; i++) { if (li[i].innerHTML.indexOf(desc) !== -1) { li[i].setAttribute('style', 'border: #000000 1px ' + 'dotted; background: ' + (isDone ? '#D0EED0;' : '#DADADA') + ';'); break; } } _this.$('showHideQuestList'). addEventListener('click', function () { var display = questList.style.display; questList.style.display = display ? '' : 'none'; }, false); }, function () { _this.root.setTimeout(function () { _this.showQuest(url); }, 1200); }); }, /** * @method init */ init: function () { if (this.persID && this.target) { this.showQuest('https://' + this.domain + '/questlog.php?id=' + this.persID); } } }; new CurrentQuestOnInfo().init(); }());