Greasy Fork is available in English.

TW Fred Timer

Fred's Timer View

Stan na 16-04-2015. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name        TW Fred Timer
// @name:ru     TW Fred Timer
// @namespace   TW Fred Timer
// @description Fred's Timer View
// @description:ru Счет времени бандита Фреда
// @include         http://*.the-west.*/game.php*
// @include         https://*.the-west.*/game.php*

// @version     0.01 alfa
// @grant       none

// ==/UserScript==


function TWFredScript(fn) {
	var script = document.createElement('script');
	script.setAttribute("type", "application/javascript");
	script.textContent = '(' + fn + ')();';
	document.body.appendChild(script);
	document.body.removeChild(script);
}

TWFredScript(function() {
  
  var VERSION = "0.01 alfa";
  var NAME = "TW Fred Timer";
  var installURL = '';
  
  
  fcContainer = $("<div />", 
                   { 
id: "twfred_container", 
style: "position: absolute; top: 64px; right: 50%; margin-right: 140px; z-index: 10; width: 142px; height: 16px;  background: url('/images/interface/character/character.png') no-repeat scroll left -160px transparent;" 
                   }
                  );
  
  fcContainer.appendTo("#user-interface");
  
  fcWrap = $('<div />',
              {
id: "twfred_wrap",
style:"padding-top:1px; font-size:10px; color:#FFF; text-align:center;",
              }
            );
    
  fcContainer.append(fcWrap);
  
  TWFred = {
    wofid:2, // don't know where find it
    diff: 0,
    timer:2, // seconds
    execCount:0,
    reInitVal:60, // execs to reinit data - on start
    reInitValN:60, // execs to reinit data - on normal work
    clickObj: null,
  };
  
  fcWrap.click(function(){TWFred.click()});
  
  TWFred.init = function()
  {
    TWFred.execCount = 0;
    TWFred.clicker();
    
    $.post("/game.php?window=wheeloffortune&mode=init", {wofid:TWFred.wofid},
           function(data)
           {
             //console.log(data);
             
             var cd = data.mode.cooldowns[0].cdstamp;
             var stime = Game.getServerTime();
             TWFred.diff = cd-stime;
             
             TWFred.count();
             setTimeout(TWFred.doTimer,TWFred.timer * 1000);
           }
          ); //post
  };
  
  TWFred.count = function()
  {
    var str = TWFred.diff.formatDuration();
    fcWrap.html(str);
  };
  
  TWFred.doTimer = function()
  {
    if (undefined === TWFred) return;
    
    if (!TWFred.clickObj) TWFred.clicker();
    
    var diff = TWFred.diff - TWFred.timer;
    if (diff < 0) diff = 0;
    TWFred.diff = diff;
    
    TWFred.count();
    TWFred.execCount++;
    if (TWFred.execCount > TWFred.reInitVal)
    {
      TWFred.init();
    }
    else
    {
      setTimeout(TWFred.doTimer,TWFred.timer * 1000);
    }
  };
  
  
  TWFred.clicker = function()
  {
    if (TWFred.clickObj) return;
    
    var bar = WestUi.NotiBar.getBar();
        
    if (!bar) return;
    bar = bar.list;
        
    TWFred.reInitVal = TWFred.reInitValN;
    
    $.each(bar, function(key,val)
    {
      //console.log(val);
           
      if (val.uid == 'easter2015')
      {
        TWFred.clickObj = val.element;
      }
    });
    
    fcWrap.css("cursor","pointer");
    if (!TWFred.clickObj) TWFred.destroy();
  };
  
  TWFred.click = function()
  {
    if (!TWFred.clickObj) return;
    TWFred.clickObj.click();
  };
  
  TWFred.destroy = function()
  {
    fcContainer.remove();
    delete TWFred;
  };
  
  
  TWFred.init();
  
}
);