hwm_tavern_new_game

Создание заявки в таверне в один клик

当前为 2015-11-02 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name           hwm_tavern_new_game
// @author         Pahan https://greasyfork.org/uk/users/18377-pahan
// @namespace      hwm_pahan
// @description    Создание заявки в таверне в один клик
// @include        http://*heroeswm.ru/*
// @include        http://*lordswm.com/*
// @include        http://178.248.235.15/*
// @exclude        */rightcol.php*
// @exclude        */ch_box.php*
// @exclude        */chat*
// @exclude        */ticker.html*
// @exclude        */frames*
// @exclude        */brd.php*
// @homepage       https://greasyfork.org/en/users/18377-pahan
// @icon           http://dcdn.heroeswm.ru/avatars/30/nc-5/30547.gif
// @version        1.1
// @encoding 	   utf-8
// @grant          GM_deleteValue
// @grant          GM_getValue
// @grant          GM_listValues
// @grant          GM_setValue
// @grant          GM_addStyle
// @grant          GM_log
// @grant          GM_openInTab
// @grant          GM_xmlhttpRequest
// ==/UserScript==

if (typeof GM_deleteValue != 'function') {
	this.GM_getValue=function (key,def) {return localStorage[key] || def;};
	this.GM_setValue=function (key,value) {return localStorage[key]=value;};
	this.GM_deleteValue=function (key) {return delete localStorage[key];};

	this.GM_addStyle=function (key) {
		var style = document.createElement('style');
		style.textContent = key;
		document.querySelector("head").appendChild(style);
	}
}
if (typeof GM_listValues != 'function') {
	this.GM_listValues=function () {
		var values = [];
		for (var i=0; i<localStorage.length; i++) {
			values.push(localStorage.key(i));
		}
		return values;
	}
}

function addEvent(elem, evType, fn) {
//    elem["on" + evType] = fn;
	if (elem.addEventListener) {
		elem.addEventListener(evType, fn, false);
	}
	else if (elem.attachEvent) {
		elem.attachEvent("on" + evType, fn);
	}
	else {
		elem["on" + evType] = fn;
	}
}

function $(id) { return document.querySelector(id); } 

function URLAttrValueGet(attr_name, aurl)
{
 attr_name = attr_name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
 var regexS = "[\\?&]" + attr_name + "=([^&#]*)";
 var regex = new RegExp( regexS );
 var results = regex.exec( aurl );
 if( results == null )
  return "";
 else
  return results[1];
}

// -----------------------------------------------



function AddNewGameLink()
{
  var Golds = [0, 40, 200, 400, 600, 1000, 2000, 3000,
    4000, 5000, 6000, 7000, 10000, 11000, 12000];
    
  var timeout = GM_getValue('timeout', '30');
  var ktype = GM_getValue('ktype', '1');
  var gold = GM_getValue('gold', '0');
  
  var Lhref = '/create_card_game.php?timeout=' + timeout + '&ktype=' +
    ktype + '&gold=' + gold + '';
  var Ltitle =
    'Создать заявку\n' +
    'Время: ' + timeout + '\n' +
    'Тип: ' + (ktype == 1 ? 'Одна колода карт' : 'Бесконечная колода карт') + '\n' +
    'Ставка: ' + Golds[gold];

  var LLinks = document.querySelectorAll('a[href^="/tavern.php?form=1"]');
  if (LLinks && (LLinks.length > 0))
  {
    var LLink = LLinks[0];
    var LNewLotHref = document.createElement('a');
    LNewLotHref.href = Lhref;
    LNewLotHref.title = Ltitle;
    LNewLotHref.innerHTML = '<font color="red"><b>Создать заявку(+)</b></font>';
    
    LLink.parentNode.insertBefore(LNewLotHref, LLink);
    var LBR = document.createElement('br');
    LLink.parentNode.insertBefore(LBR, LLink);
  }
  
  var LLinks = document.querySelectorAll('a[href="tavern.php"]');
  if (LLinks && (LLinks.length > 0))
  {
    var LLink = LLinks[0];
    var LNewLotHref = document.createElement('a');
    LNewLotHref.href = Lhref;
    LNewLotHref.title = Ltitle;
    LNewLotHref.innerHTML = '<font color="#ffd875"><b>+</b></font>';
    
    LLink.parentNode.appendChild(LNewLotHref);
  }      
}

function SaveSettings()
{
  GM_setValue('timeout', document.forms.create.timeout.options[document.forms.create.timeout.selectedIndex].value);
  GM_setValue('ktype', document.forms.create.ktype.options[document.forms.create.ktype.selectedIndex].value);
  GM_setValue('gold', document.forms.create.gold.options[document.forms.create.gold.selectedIndex].value);
}

function InitOneInput(AInput, AName)
{
  var LValue = GM_getValue(AName, '');
  for(i = 0; i < AInput.options.length; i++)
  {                    
    var LOption = AInput.options[i];
    if (LOption.value == LValue)
      AInput.selectedIndex = LOption.index;
  }                    
  
  addEvent(AInput, 'change', SaveSettings);
}

function InitInputs()
{
  InitOneInput(document.forms.create.timeout, 'timeout');
  InitOneInput(document.forms.create.ktype, 'ktype');
  InitOneInput(document.forms.create.gold, 'gold');
}


if (URLAttrValueGet('form', location.href) == '1') 
  InitInputs();
AddNewGameLink();