seasons by ctsigma

shows cultures that will appear next month on unit list

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        seasons by ctsigma
// @namespace   virtonomica
// @include     https://*virtonomic*.*/*/main/company/view/*/unit_list
// @description shows cultures that will appear next month on unit list
// @version     1.04
// @grant       none
// ==/UserScript==
var run = function () {
  var win = (typeof (unsafeWindow) != 'undefined' ? unsafeWindow : top.window);
  $ = win.$;
  var agro = $('<img style="cursor:pointer;vertical-align:middle;" width="32" src="/img/artefact/icons/color/agriculture.gif" title="сезонность">').click(function () {seasons()});
//  $('table.unit-top tr:eq(1)>td:eq(1)').prepend(agro);  //конфликтовало
  $('img[src="/img/icon/unit_build.png"]').parents('td').prepend(agro);
  
  function seasons() {
    var realm = readCookie('last_realm');
    const week = 604800000; // неделя в ms
    var srv_date = $('.date_time').text().trim();
    var months = {'янв':0,'фев':1,'мар':2,'апр':3,'май':4,'мая':4,'июн':5,'июл':6,'авг':7,'сен':8,'окт':9,'ноя':10,'дек':11};
    var yy = (/([0-9]+)\s([^0-9\s]+)\s([0-9]+)/.exec(srv_date)) [3];
    var mm = months[(/([0-9]+)\s([^0-9\s]+)\s([0-9]+)/.exec(srv_date)) [2].substr(0, 3)];
    var dd = (/([0-9]+)\s([^0-9\s]+)\s([0-9]+)/.exec(srv_date)) [1];
    var srvDate = new Date(yy, mm, dd);
    $('.unit-list-2014>tbody td[class^=info]').each(function () {
      UnitType = $(this).prop('class');
      if (UnitType == 'info i-farm' || UnitType == 'info i-orchard') {
        var id = $(this).parent().find($('.unit_id')).text();
        if (id == '') return;
        var url = '/%realm%/window/unit/produce_change/%id%'.replace('%realm%', realm).replace('%id%', id);
        var prod = '';
        $.ajax({
          type: 'GET',
          url: url,
          success: function (data) {
            $('.list tr[class]', data).each(function () {
              var season = months[$(this).find('>td:eq(4)').find('[title*=", уборка урожая"]:eq(0)').attr('title').replace(', уборка урожая', '').toLowerCase().substr(0, 3)];
              var yyy = parseInt(yy);
              if (season < mm) {
                yyy = 1 + yyy
              }
              var ssnDate = new Date(yyy, season, '01');
              var weeks = Math.ceil((ssnDate - srvDate) / week);
//              console.log(weeks);
              if (weeks < 6) {
                prod = prod + $(this).find('>td:eq(3) a').html().replace(RegExp('/img/products/24/', 'g'), '/img/products/16/') + '(' + weeks + ')</img>';
              }
            });
          },
          async: false
        });
        var b = $(prod);
        b.each(function () {
          b.attr('align', '');
        })
        $(this).parent().find('.alerts').prepend(b);
      }
    }) //each function
  }
}
if (window.top == window) {
  var script = document.createElement('script');
  script.textContent = '(' + run.toString() + ')();';
  document.documentElement.appendChild(script);
}