// ==UserScript== // @name HistorySms // @namespace https://github.com/MyRequiem/comfortablePlayingInGW // @description При просмотре входящего/исходящего сообщения устанавливает ссылку для вывода предыдущей переписки с персонажем. // @id comfortablePlayingInGW@MyRequiem // @updateURL https://raw.githubusercontent.com/MyRequiem/comfortablePlayingInGW/master/separatedScripts/HistorySms/historySms.meta.js // @downloadURL https://raw.githubusercontent.com/MyRequiem/comfortablePlayingInGW/master/separatedScripts/HistorySms/historySms.user.js // @include https://*gwars*/sms-read.php?type=* // @grant none // @license MIT // @version 2.14-140522 // @author MyRequiem [https://www.gwars.io/info.php?id=2095458] // ==/UserScript== /*global unsafeWindow */ /*jslint browser: true, maxlen: 80, vars: true, plusplus: true, nomen: 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'; /** * @class General * @constructor */ var General = function () { /** * @property root * @type {Object} */ this.root = this.getRoot(); /** * @property doc * @type {Object} */ this.doc = this.root.document; /** * @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 $ * @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 UrlEncode * @constructor */ var UrlEncode = function () { /** * @method init * @param {String} str * @return {String} */ this.init = function (str) { var mass = {1040: 192, 1041: 193, 1042: 194, 1043: 195, 1044: 196, 1045: 197, 1046: 198, 1047: 199, 1048: 200, 1049: 201, 1050: 202, 1051: 203, 1052: 204, 1053: 205, 1054: 206, 1055: 207, 1056: 208, 1057: 209, 1058: 210, 1059: 211, 1060: 212, 1061: 213, 1062: 214, 1063: 215, 1064: 216, 1065: 217, 1066: 218, 1067: 219, 1068: 220, 1069: 221, 1070: 222, 1071: 223, 1072: 224, 1073: 225, 1074: 226, 1075: 227, 1076: 228, 1077: 229, 1078: 230, 1079: 231, 1080: 232, 1081: 233, 1082: 234, 1083: 235, 1084: 236, 1085: 237, 1086: 238, 1087: 239, 1088: 240, 1089: 241, 1090: 242, 1091: 243, 1092: 244, 1093: 245, 1094: 246, 1095: 247, 1096: 248, 1097: 249, 1098: 250, 1099: 251, 1100: 252, 1101: 253, 1102: 254, 1103: 255, 1025: 168, 1105: 184, 8470: 185}, result = '', code, i; for (i = 0; i < str.length; i++) { code = str.charCodeAt(i); code = mass[code] || code; if (code < 16) { result += '%0' + code.toString(16); } else { result += '%' + code.toString(16); } } return result; }; }; /** * @class HistorySms * @constructor */ var HistorySms = function () { /** * @property nik * @type {String|null} */ this.nik = null; /** * @property uncodeNik * @type {String|null} */ this.uncodeNik = null; /** * @property spanContent * @type {Object} */ this.spanContent = general.doc.createElement('span'); /** * @property sms * @type {Array} */ this.sms = []; /** * @property numberSms * @type {int} */ this.numberSms = 3; // noinspection FunctionWithInconsistentReturnsJS /** * @method sortMess * @return {int} */ this.sortMess = function () { this.sms.sort(function (a, b) { var ret; if (a.id < b.id) { ret = 1; } else if (a.id > b.id) { ret = -1; } else { ret = 0; } return ret; }); }; /** * @method createDivSms * @return {Object} */ this.createDivSms = function () { var target = general.doc. querySelector('div[style*="overflow:auto"]'), divSms = general.doc.createElement('div'); divSms.setAttribute('name', 'historySms'); divSms.setAttribute('style', 'font-size: 8pt; margin-bottom: 7px;'); target.insertBefore(divSms, target.firstChild); return divSms; }; /** * @method showOfSyndLinks */ this.showOfSyndLinks = function () { var mass = [], i; for (i = 0; i < this.sms.length; i++) { mass.push(this.sms[i].ofSyndLink); } this.createDivSms().innerHTML = '' + 'Ссылки на сообщения, доступные для официальных синдикатов:' + '