// ==UserScript== // @name TimeNpc // @namespace https://github.com/MyRequiem/comfortablePlayingInGW // @description На главной странице выводит время, оставшееся до взятия квеста и сcылку на NPC, у которого в последний раз брали квест. Звуковое оповещение. Умеет выводить список NPC с информацией о них для каждого острова. // @id comfortablePlayingInGW@MyRequiem // @updateURL https://raw.githubusercontent.com/MyRequiem/comfortablePlayingInGW/master/separatedScripts/TimeNpc/timeNpc.meta.js // @downloadURL https://raw.githubusercontent.com/MyRequiem/comfortablePlayingInGW/master/separatedScripts/TimeNpc/timeNpc.user.js // @include https://*gwars*/me.php* // @include https://*gwars*/me/* // @include https://*gwars*/npc.php?id=* // @grant none // @license MIT // @version 2.37-140522 // @author MyRequiem [https://www.gwars.io/info.php?id=2095458] // ==/UserScript== /*global unsafeWindow */ /*jslint browser: true, maxlen: 80, vars: true, nomen: true, plusplus: true, devel: true, regexp: 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'; // ================= НАСТРОЙКИ ========================== var soundNPC = 17; // номер звука, когда пора делать квест (0 - без звука) // ============== КОНЕЦ НАСТРОЕК ======================== /** * @class General * @constructor */ var General = function () { /** * @property root * @type {Object} */ this.root = this.getRoot(); /** * @property doc * @type {Object} */ this.doc = this.root.document; /** * @property loc * @type {String} */ this.loc = this.root.location.href; /** * @property st * @type {Object} */ this.st = this.root.localStorage; /** * @property STNAME * @type {String} */ this.STNAME = 'timeNpc'; /** * @property imgPath * @type {String} */ this.imgPath = 'https://raw.githubusercontent.com/MyRequiem/' + 'comfortablePlayingInGW/master/imgs/'; /** * @property domain * @type {String} */ this.domain = this.doc.domain; }; /** * @lends General.prototype */ General.prototype = { /** * @method getRoot * @return {Object} */ getRoot: function () { var rt = typeof unsafeWindow; return rt !== 'undefined' ? unsafeWindow : window; }, /** * @method setData * @param {Array} data */ setData: function (data) { this.st.setItem(this.STNAME, data.join('|')); }, /** * @method getData * @return {Array} */ getData: function () { var stData = this.st.getItem(this.STNAME); if (stData) { return stData.split('|'); } stData = ['1', '', '']; this.setData(stData); return stData; }, /** * @method $ * @param {string} id * @return {HTMLElement|null} */ $: function (id) { return this.doc.querySelector('#' + id); } }; var general = new General(); /** * @class AjaxQuery * @constructor */ var AjaxQuery = function () { /** * @method init * @param {String} url * @param {Function} onsuccess * @param {Function} onfailure */ this.init = function (url, onsuccess, onfailure) { var xmlHttpRequest = new XMLHttpRequest(); if (!xmlHttpRequest) { general.root.console.log('Error create xmlHttpRequest !!!'); return; } xmlHttpRequest.open('GET', url, true); xmlHttpRequest.send(null); var timeout = general.root.setTimeout(function () { xmlHttpRequest.abort(); }, 10000); xmlHttpRequest.onreadystatechange = function () { if (xmlHttpRequest.readyState === 4) { clearTimeout(timeout); if (xmlHttpRequest.status === 200) { onsuccess(xmlHttpRequest); } else { onfailure(); } } }; }; }; /** * @class PlaySound * @constructor */ var PlaySound = function () { /** * @method init * @param {int|String} sound */ this.init = function (sound) { if (sound && sound !== '0') { var audio = general.$('cpingw_audio'); if (!audio) { audio = general.doc.createElement('audio'); audio.setAttribute('id', 'cpingw_audio'); var divAudio = general.doc.createElement('div'); divAudio.setAttribute('style', 'display: none;'); divAudio.appendChild(audio); general.doc.body.appendChild(divAudio); } audio.volume = 0.3; audio.src = 'https://raw.githubusercontent.com/MyRequiem/' + 'comfortablePlayingInGW/master/sounds/' + sound + '.ogg'; // noinspection JSIgnoredPromiseFromCall audio.play(); } }; }; /** * @class TimeNpc * @constructor */ var TimeNpc = function () { /** * @property imgPath * @type {String} */ this.imgPath = general.imgPath + 'TimeNpc/'; /** * @property npc * @type {Object} */ this.npc = { g: ['2', '3', '6', '8', '10', '12'], z: ['1', '4', '5', '7', '9', '11'], p: ['16', '17', '18', '19', '20'] }; /** * @property tm * @type {int} */ this.tm = 1000; /** * @method clearNPCData */ this.clearNPCData = function () { general.$('dataNPC').innerHTML = ''; }; /** * @method setCloseButton */ this.setCloseButton = function () { general.$('dataNPC').innerHTML += '

';
tr.appendChild(td);
general.$('dataNPC').appendChild(tr);
new AjaxQuery().init(url, function (xml) {
var spanContent = general.doc.createElement('span');
spanContent.innerHTML = xml.responseText;
if (/Вы находитесь в пути/.test(spanContent.innerHTML)) {
general.$('dataNPC').lastElementChild.innerHTML = ' + '/img/synds/' +
/\?id=(\d+)/.exec(syndLink.href)[1] + '.gif)
' +
'