// ==UserScript== // @name InventoryPlus // @namespace https://github.com/MyRequiem/comfortablePlayingInGW // @description Упаковка одинаковых предметов в инвентаре. // @id comfortablePlayingInGW@MyRequiem // @updateURL https://raw.githubusercontent.com/MyRequiem/comfortablePlayingInGW/master/separatedScripts/InventoryPlus/inventoryPlus.meta.js // @downloadURL https://raw.githubusercontent.com/MyRequiem/comfortablePlayingInGW/master/separatedScripts/InventoryPlus/inventoryPlus.user.js // @include https://*gwars*/items.php* // @grant none // @license MIT // @version 2.51-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, 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; }; /** * @lends General.prototype */ General.prototype = { /** * @method getRoot * @return {Object} */ getRoot: function () { var rt = typeof unsafeWindow; return rt !== 'undefined' ? unsafeWindow : window; } }; var general = new General(); /** * @class InventoryPlus * @constructor */ var InventoryPlus = function () { /** * @method openCloseItem * @param {String} id */ this.openCloseItem = function (id) { return function () { var tb = general.doc.getElementById('tr_' + id), _this = this; if (tb.style.display === '') { tb.style.display = 'none'; _this.innerHTML = _this.innerHTML.replace('-', '+'); } else { tb.style.display = ''; _this.innerHTML = _this.innerHTML.replace('+', '-'); } }; }; /** * @method compareLines * @param {Object} line * @param {Array} linesObj * @return {Object|null} */ this.compareLines = function (line, linesObj) { var i; line.link = line.line_1.querySelectorAll('a')[1]; line.id = /id=(.*)$/.exec(line.link.href)[1]; for (i = 0; i < linesObj.length; i++) { if (linesObj[i].line.id === line.id) { return linesObj[i]; } } return null; }; /** * @method startInventoryPlus * @param {Object} _this */ this.startInventoryPlus = function (_this) { // ищем таблицу с инвентарем var tbody = general.doc.querySelector('table[border="0"]' + '[cellspacing="1"][cellpadding="5"][align="center"]' + '[width="700"] tr[id^="item_tr"]'); if (!tbody) { return; } tbody = tbody.parentNode; if (!tbody.firstElementChild) { return; } var node = tbody.firstElementChild.nextElementSibling; if (/предметов нет/.test(node.innerHTML)) { return; } var allLines = [], // все узлы