· 6 years ago · Jun 28, 2019, 05:02 PM
1// ==UserScript==
2// @author blablubbb
3// @namespace T4
4// @name Travian T4 Auction bid
5// @description The Script bids predefined prices
6// @include http://*.travian.*/hero.php?t=4*
7// @include https://*.travian.*/hero.php?t=4*
8// @version 2.8.8.
9// @updateURL https://openuserjs.org/meta/blablubbb/Travian_T4_Auction_bid.meta.js
10// ...
11// @grant GM_getValue
12// @grant GM_log
13// @grant GM_openInTab
14// @grant GM_registerMenuCommand
15// @grant GM_setValue
16// @grant GM_xmlhttpRequest
17// @license MIT
18// ...
19// ==/UserScript==
20
21// find out whether 503-Error or Log-out...
22// Thanks sowrov for your minor contribution, but I don't think that is enough to qualify as author.
23//
24if(document.getElementsByTagName("h1")[0].innerHTML == "503 Service Unavailable"){
25window.location.href = "http://"+window.location.hostname+"/hero.php?t=4&action=buy";}
26
27if(document.getElementsByTagName("h1")[0].innerHTML == "502 Bad Gateway"){
28window.location.href = "http://"+window.location.hostname+"/hero.php?t=4&action=buy";}
29
30if(document.getElementsByClassName("outerLoginBox")){//log-outerHeight
31warten = Math.random()*1200000+1500000; //30min +- 10min
32 window.setTimeout ( function() {
33 window.location.href = "http://"+window.location.hostname+"/hero.php?t=4&action=buy";
34 },
35 warten );
36}
37
38const XPFirst = XPathResult.FIRST_ORDERED_NODE_TYPE;
39function getVersion (){
40if(document.getElementById("villageList")){
41return "T4";
42}
43else{//T4.2 fix
44return "T4.2";
45}}
46var version = getVersion ();
47//GM_log("version"+version);
48
49function getLang (){
50g_metadata = document.getElementsByTagName("meta");
51var len = g_metadata.length;
52for (var i = 0; i < len; i++) {
53 if (g_metadata[i].name == 'content-language') {
54 lang = g_metadata[i].content;
55 }}
56 return lang;
57}
58//GM_log("lang:"+getLang ());
59/***************** Functions adopted from "Travian: Antifarm\Troop saver" script and "autotask gotgs" script"...**************************/
60/**
61 * XPath wrapper - simplifies searching for items in the document.
62 */
63
64
65function find(xpath, xpres, startnode)
66{
67 if (!startnode) {startnode = document;}
68 var ret = document.evaluate(xpath, startnode, null, xpres, null);
69 if (ret == null) return null;
70 return xpres == XPFirst ? ret.singleNodeValue : ret;
71}
72
73function getLoginButton(doc) {
74 var loginButton = find(".//input[ @value='login' and @id='btn_login' ]", XPFirst, doc); // login button // travian version 3.6
75 if ( loginButton == null ) { // travian version 4.0
76 var xpathLoginButtonT4 = ".//button[ @id='s1' and @name='s1' and @type='submit' and contains(@onclick,'screen.width') and contains(@onclick,'screen.height') ]";
77 loginButton = find(xpathLoginButtonT4, XPFirst, doc); // login button
78 }
79 if ( loginButton != null )
80 return loginButton;
81 else
82 return null;
83}
84
85var aTravianVersion = "";
86var var_get_uid = null;
87function getuid() {
88 var loginButton = getLoginButton(document);
89 if ( loginButton != null ) // when login page return null
90 return null;
91 if ( var_get_uid == "" || var_get_uid == null || var_get_uid == undefined ) {
92 var tag = document.evaluate('.//div[@id="side_navi"]//a[contains(@href,"spieler.php")]', document, null, XPFirst, null).singleNodeValue;
93 if ( tag != null ) {
94 aTravianVersion = "3.6";
95 var_get_uid = tag.href.match(/\buid=\d{1,}\b/)[0].split("=")[1];
96 }
97 else {
98 tag = document.evaluate('.//div[@id="side_info"]//a[contains(@href,"spieler.php")]', document, null, XPFirst, null).singleNodeValue;
99 if ( tag != null ) {
100 var_get_uid = tag.href.match(/\buid=\d{1,}\b/)[0].split("=")[1];
101 aTravianVersion = "4.0";
102 }
103 else {
104 var_get_uid = null;
105 }
106 }
107 }
108 return var_get_uid;
109}
110
111function currentServer() {
112 var serverr = window.location.hostname.replace(/\.travian\./, "");
113 return serverr;
114}
115
116function myacc() {
117 return currentServer() + "_" + getuid();
118}
119
120function promptLangBid() {
121 var curentSetup = GM_getValue ( myacc() + "_lang_bid", "" );
122 var newSetup = prompt("Put in the name of the button to bid in your travian version (language dependent... e.g. bid):\n\n",curentSetup);
123 if ( newSetup != null ){
124 GM_setValue ( myacc() + "_lang_bid", newSetup );}
125}
126GM_registerMenuCommand("Language setting", promptLangBid );
127
128function promptFriends() {
129 var curentSetup = GM_getValue ( myacc() + "_friends", "" );
130 var newSetup = prompt("List friends you do not wish to overbid, seperate names by coma (make sure to not use additional spaces except the ones which are really in a player-name):\n\n",curentSetup);
131 if ( newSetup != null ){
132 GM_setValue ( myacc() + "_friends", newSetup );}
133}
134GM_registerMenuCommand("Friends", promptFriends );
135
136function deleteFriedsBids(){
137GM_setValue ( myacc() + "_friends_bids", "");
138}
139
140function addFriendsBid(id){
141var newVal ="";
142var oldVal = GM_getValue ( myacc() + "_friends_bids", "");
143if (oldVal == ""){newVal = id;}//.toString()
144else{newVal = oldVal+"["+id;}//.toString()
145GM_setValue ( myacc() + "_friends_bids", newVal);
146//GM_log("addFriendBid "+id+" neue Liste"+newVal);
147}
148
149function removeFriendsBid(id){
150var newVal ="";
151var oldVal = GM_getValue ( myacc() + "_friends_bids", "");
152var oldValArr = [];
153oldValArr = oldVal.split("[");
154for (i=0; i<oldValArr.length;i++){
155if(oldValArr[i] != id){// .toString()
156if (newVal == ""){newVal = oldValArr[i];}
157else{newVal += "["+oldValArr[i];}
158}
159}
160GM_setValue ( myacc() + "_friends_bids", newVal);
161//GM_log("addFriendBid "+id+" neue Liste"+newVal);
162}
163
164function getFriendsBids(){
165var friendsBids=[];
166var oldVal = GM_getValue ( myacc() + "_friends_bids", "");
167friendsBids = oldVal.split("[");
168return friendsBids;
169}
170
171function promptPrice_bandage25() {
172 var curentSetup = GM_getValue ( myacc() + "_bandage25", "0" );
173 var newSetup = prompt("Put in price for "+"_bandage25"+" (e.g. 2.3). If you do not wish to bit, set it to 0 :\n\n",curentSetup);
174 if ( newSetup != null ){
175 GM_setValue ( myacc() + "_bandage25", newSetup.replace(/\s/g,"") );
176 document.getElementById('myPriceFor_bandage25').textContent = newSetup.replace(/\s/g,"");}
177}
178GM_registerMenuCommand("Price of "+"_bandage25", promptPrice_bandage25 );
179
180function promptPrice_bandage33() {
181 var curentSetup = GM_getValue ( myacc() + "_bandage33", "0" );
182 var newSetup = prompt("Put in price for "+"_bandage33"+" (e.g. 2.3). If you do not wish to bit, set it to 0 :\n\n",curentSetup);
183 if ( newSetup != null ){
184 GM_setValue ( myacc() + "_bandage33", newSetup.replace(/\s/g,"") );
185 document.getElementById('myPriceFor_bandage33').textContent = newSetup.replace(/\s/g,"");}
186}
187GM_registerMenuCommand("Price of "+"_bandage33", promptPrice_bandage33 );
188
189function promptPrice_cage() {
190 var curentSetup = GM_getValue ( myacc() + "_cage", "0" );
191 var newSetup = prompt("Put in price for "+"_cage"+" (e.g. 2.3). If you do not wish to bit, set it to 0 :\n\n",curentSetup);
192 if ( newSetup != null ){
193 GM_setValue ( myacc() + "_cage", newSetup.replace(/\s/g,"") );
194 document.getElementById('myPriceFor_cage').textContent = newSetup.replace(/\s/g,"");}
195}
196GM_registerMenuCommand("Price of "+"_cage", promptPrice_cage );
197
198function promptPrice_scroll() {
199 var curentSetup = GM_getValue ( myacc() + "_scroll", "0" );
200 var newSetup = prompt("Put in price for "+"_scroll"+" (e.g. 2.3). If you do not wish to bit, set it to 0 :\n\n",curentSetup);
201 if ( newSetup != null ){
202 GM_setValue ( myacc() + "_scroll", newSetup.replace(/\s/g,"") );
203 document.getElementById('myPriceFor_scroll').textContent = newSetup.replace(/\s/g,"");}
204}
205GM_registerMenuCommand("Price of "+"_scroll", promptPrice_scroll );
206
207function promptPrice_ointment() {
208 var curentSetup = GM_getValue ( myacc() + "_ointment", "0" );
209 var newSetup = prompt("Put in price for "+"_ointment"+" (e.g. 2.3). If you do not wish to bit, set it to 0 :\n\n",curentSetup);
210 if ( newSetup != null ){
211 GM_setValue ( myacc() + "_ointment", newSetup.replace(/\s/g,"") );
212 document.getElementById('myPriceFor_ointment').textContent = newSetup.replace(/\s/g,"");}
213}
214GM_registerMenuCommand("Price of "+"_ointment", promptPrice_ointment );
215
216function promptPrice_lawTables() {
217 var curentSetup = GM_getValue ( myacc() + "_lawTables", "0" );
218 var newSetup = prompt("Put in price for "+"_lawTables"+" (e.g. 2.3). If you do not wish to bit, set it to 0 :\n\n",curentSetup);
219 if ( newSetup != null ){
220 GM_setValue ( myacc() + "_lawTables", newSetup.replace(/\s/g,"") );
221 document.getElementById('myPriceFor_lawTables').textContent = newSetup.replace(/\s/g,"");}
222}
223GM_registerMenuCommand("Price of "+"_lawTables", promptPrice_lawTables );
224
225function promptPrice_artWork() {
226 var curentSetup = GM_getValue ( myacc() + "_artWork", "0" );
227 var newSetup = prompt("Put in price for "+"_artWork"+" (e.g. 2.3). If you do not wish to bit, set it to 0 :\n\n",curentSetup);
228 if ( newSetup != null ){
229 GM_setValue ( myacc() + "_artWork", newSetup.replace(/\s/g,"") );
230 document.getElementById('myPriceFor_artWork').textContent = newSetup.replace(/\s/g,"");}
231}
232GM_registerMenuCommand("Price of "+"_artWork", promptPrice_artWork );
233
234function promptPrice_bookOfWisdom() {
235 var curentSetup = GM_getValue ( myacc() + "_bookOfWisdom", "0" );
236 var newSetup = prompt("Put in price for "+"_bookOfWisdom"+" (e.g. 2.3). If you do not wish to bit, set it to 0 :\n\n",curentSetup);
237 if ( newSetup != null ){
238 GM_setValue ( myacc() + "_bookOfWisdom", newSetup.replace(/\s/g,"") );
239 document.getElementById('myPriceFor_bookOfWisdom').textContent = newSetup.replace(/\s/g,"");}
240}
241GM_registerMenuCommand("Price of "+"_bookOfWisdom", promptPrice_bookOfWisdom );
242
243function promptPrice_bucketOfWater() {
244 var curentSetup = GM_getValue ( myacc() + "_bucketOfWater", "0" );
245 var newSetup = prompt("Put in price for "+"_bucketOfWater"+" (e.g. 2.3). If you do not wish to bit, set it to 0 :\n\n",curentSetup);
246 if ( newSetup != null ){
247 GM_setValue ( myacc() + "_bucketOfWater", newSetup.replace(/\s/g,"") );
248 document.getElementById('myPriceFor_bucketOfWater').textContent = newSetup.replace(/\s/g,"");}
249}
250GM_registerMenuCommand("Price of "+"_bucketOfWater", promptPrice_bucketOfWater );
251
252function promptPrice_otherItems() {
253 var curentSetup = GM_getValue ( myacc() + "_otherItems", "" );
254 var newSetup = prompt("Put in price for "+"_otherItems"+". The syntax must be 'item,price;next item,price;...;last item,price' (e.g. 'Hatchet of the Axeman,200;Spear of the Spearman,150;Small shield,500'). Put it in without quotation marks. This feature is experimental:\n\n",curentSetup);
255 if ( newSetup != null ){
256 GM_setValue ( myacc() + "_otherItems", newSetup );
257 makeOtherItemHTLM();
258 }
259}
260GM_registerMenuCommand("Price of "+"_otherItems", promptPrice_otherItems );
261
262function prompt_MySilverMin() {
263 var curentSetup = GM_getValue ( myacc() + "_MySilverMin", "0" );
264 var newSetup = prompt("Set value for Silver reserve to remain:\n\n",curentSetup);
265 if ( newSetup != null ){
266 GM_setValue ( myacc() + "_MySilverMin", newSetup.replace(/\s/g,"") );
267 document.getElementById('mySilverMin').textContent = newSetup.replace(/\s/g,"");}
268}
269GM_registerMenuCommand("Silvermin", prompt_MySilverMin );
270
271function prompt_MyInstantSwitch() {
272 var curentSetup = GM_getValue ( myacc() + "_MyInstantSwitch", "0" );
273 var newSetup = prompt("Set value value to the number of pages the bot bids in advance (default is 0 and that means all pages):\n\n",curentSetup);
274 if ( newSetup != null ){
275 GM_setValue ( myacc() + "_MyInstantSwitch", newSetup.replace(/\s/g,"") );
276 document.getElementById('MyInstantSwitch').textContent = newSetup.replace(/\s/g,"");}
277}
278GM_registerMenuCommand("First pages only?", prompt_MyInstantSwitch );
279/**************************************************************End of stolen code... more or less...*********************************************************************************/
280//Arry-Funktionen:
281function include(arr, obj) {for(var i=0; i<arr.length; i++) {if (arr[i] == obj) return true;}}
282/**************************************************************Start Wartefunktionen*********************************************************************************/
283//Startet nach warte-Zeit neu mit Gebote einlesen...
284function startNewCycle(warten){
285 deleteFriedsBids();
286 window.setTimeout ( function() {
287 window.location.href = "http://"+window.location.hostname+"/hero.php?t=4&action=buy";
288 },
289 warten );
290 var wartenStd = Math.floor(warten/3600000);
291 var wartenMin = Math.floor((warten/60000)-wartenStd*60);
292 var wartenSec = Math.floor((warten/1000)-wartenStd*3600-wartenMin*60);
293 document.getElementById('warten').innerHTML = "sleep <span class=\"my_counter\">" + wartenStd + ":"+wartenMin+":"+wartenSec+"</span>";
294 var MyAddDiv = document.createElement("div");
295 var addFrame = '<div><p>sleeping total...' + wartenStd + ":"+wartenMin+":"+wartenSec + '</p></div>';
296 MyAddDiv.innerHTML = addFrame;
297 var filterNode = document.getElementById("filter").nextSibling;
298 //document.getElementById("filter").nextSibling
299 document.getElementById("auction").insertBefore(MyAddDiv,filterNode);
300 }
301
302function loadNextPage(warten){ // gehe eine Seite weiter...
303var nextpage = document.getElementsByClassName('next')[0].href;
304if (nextpage == undefined ){return false;}
305else{
306 window.setTimeout ( function() {
307 window.location.href = nextpage;
308 },
309 warten );
310 var wartenTxt = Math.round(warten/1000);
311 document.getElementById('warten').innerHTML = "next page in <span class=\"my_counter\"> 00:00:0"+wartenTxt+"</span>";
312 return true;
313}}
314
315function loadThisPage(warten){ // neu laden ohne resend
316var search = [];
317var pagenr =0;
318var nextpage = document.getElementsByClassName('next')[0].href;
319if (nextpage == undefined )
320{
321 var previouspage = document.getElementsByClassName('previous')[0].href;
322 if (previouspage == undefined )
323 {nextpage = window.location.href;}
324 else
325 {search = previouspage.split("page=");
326 pagenr = parseInt(search[1])+1;
327 nextpage = search[0]+"page="+pagenr;}
328}
329else{
330search = nextpage.split("page=");
331pagenr = parseInt(search[1])-1;
332nextpage = search[0]+"page="+pagenr;
333}
334window.setTimeout ( function() {
335 window.location.href = nextpage;
336 },
337 warten );
338var wartenTxt = Math.round(warten/1000);
339document.getElementById('warten').textContent = "next page in " + wartenTxt + " s";
340return true;}
341
342function getPageNumber(){
343var search = [];
344var pagenr =0;
345var nextpage = document.getElementsByClassName('next')[0].href;
346if (nextpage == undefined )
347{
348 var previouspage = document.getElementsByClassName('previous')[0].href;
349 if (previouspage != undefined )
350 {search = previouspage.split("page=");
351 pagenr = parseInt(search[1])+1;
352 }
353}
354else{
355search = nextpage.split("page=");
356pagenr = parseInt(search[1])-1;
357}
358return pagenr;
359}
360
361function makeOtherItemForm(){
362var otherItems = GM_getValue ( myacc() + "_otherItems", "" ).split(";");
363var innerHTLMtxt = "";
364var item = "";
365var price = "";
366if (otherItems[0]!=""){
367 for(i = 0; i<otherItems.length; i++){
368 item = otherItems[i].split(",")[0];
369 price = otherItems[i].split(",")[1];
370innerHTLMtxt += "<tr><td>"+item+"</td><td><a id='"+item.replace(/\s/g,"")+"' href='javaScript:void(0)' >"+price+"</a></td><td><a id='del_"+item.replace(/\s/g,"")+"' href='javaScript:void(0)' >X</a></td></tr>";
371 }}
372
373document.getElementById("otherItemForm").innerHTML = innerHTLMtxt;
374}
375function makeOtherItemEventListen(){
376var otherItems = GM_getValue ( myacc() + "_otherItems", "" ).split(";");
377var innerHTLMtxt = "";
378var item = "";
379var price = "";
380if (otherItems[0]!=""){
381 for(i = 0; i<otherItems.length; i++){
382 item = otherItems[i].split(",")[0];
383 price = otherItems[i].split(",")[1];
384document.getElementById(item.replace(/\s/g,"")).addEventListener("click", function(){changePrice(this.id)}, true);
385document.getElementById("del_"+item.replace(/\s/g,"")).addEventListener("click", function(){changePrice(this.id)}, true);
386 }}
387}
388function changePrice(DoItem){
389var otherItems = GM_getValue ( myacc() + "_otherItems", "" ).split(";");
390var innerHTLMtxt = "";
391var item = [];
392var price = [];
393var replaceList = "";
394if(DoItem.split("_")[0] == "del"){//delete item
395DoItem = DoItem.split("_")[1];
396if (otherItems[0]!=""){
397 for(i = 0; i<otherItems.length; i++){
398 item[i] = otherItems[i].split(",")[0].replace(/\s/g,"");
399if(item[i]==DoItem){//delete last semicolon if last item is deleted.
400if(i+1==otherItems.length){replaceList = replaceList.substr(0,replaceList.length -1);}
401}
402else{
403if(i+1==otherItems.length){replaceList += otherItems[i];}
404else{replaceList += otherItems[i]+';';}
405}
406 }}}
407else{//change Price
408if (otherItems[0]!=""){
409 for(i = 0; i<otherItems.length; i++){
410 item[i] = otherItems[i].split(",")[0];
411price[i] = otherItems[i].split(",")[1];
412if(item[i].replace(/\s/g,"")==DoItem){//change price
413var newPrice = prompt("Put in price for "+item[i]+" (e.g. 100). If you do not wish to bit, set it to 0. You can also delete object from list by pressing the X next to the price:\n\n",price[i]);
414if(i+1==otherItems.length){
415if ( newPrice != null ){replaceList += item[i]+","+newPrice;}
416else{replaceList += item[i]+","+price[i];}
417}
418else{if ( newPrice != null ){replaceList += item[i]+","+newPrice+';';}else{replaceList += item[i]+","+price[i]+';';}}
419}
420else{
421if(i+1==otherItems.length){replaceList += otherItems[i];}
422else{replaceList += otherItems[i]+';';}
423}
424 }}
425}
426GM_setValue ( myacc() + "_otherItems", replaceList );
427makeOtherItemForm();
428makeOtherItemEventListen();
429}
430
431function AddItemToList(){
432var otherItems = GM_getValue ( myacc() + "_otherItems", "" );
433var Item = prompt("Put in the name of the item (e.g.\"Hatchet of the Axeman\") without quotation marks and without additional spaces:\n\n","Hatchet of the Axeman");
434var price = prompt("Put in the price you want to pay for "+Item+" (e.g. 100):\n\n","100");
435if ((Item != null)&&(price != null)&&(Item!= "")){
436if ( otherItems != "" ){
437otherItems+=";"+Item+","+price;
438}
439else{
440otherItems=Item+","+price;
441}
442GM_setValue ( myacc() + "_otherItems", otherItems );
443makeOtherItemForm();
444makeOtherItemEventListen();
445}
446}
447
448function makePricesTable(version){
449itemlist = [
450 "_bandage25",
451 "_bandage33",
452 "_cage",
453 "_scroll",
454 "_ointment",
455 "_lawTables",
456 "_artWork",
457 "_bucketOfWater",
458 "_bookOfWisdom",
459/* "_helmet",
460 "_body",
461 "_leftHand",
462 "_rightHand",
463 "_shoes",
464 "_horse" */
465 ];
466var price=[];
467var silbermin = GM_getValue ( myacc() + "_MySilverMin", "0" );
468var MyInstantSwitch = GM_getValue ( myacc() + "_MyInstantSwitch", "0" );
469var startStop = GM_getValue ( myacc() + "_startStop" , "Start" );
470if(version=="T4"){
471var pricelisthtmltxt = "<table><thead><tr><th>Item</th><th>Price</th></tr></thead><tbody id=\"mySellTable\" >";
472for (i = 0; i<itemlist.length; i++){
473price[i] = GM_getValue ( myacc() + itemlist[i] , "0" );
474pricelisthtmltxt += '<tr><td><img src="img/x.gif" class="itemCategory itemCategory'+itemlist[i] +'" alt="itemCategory itemCategory'+itemlist[i] +'"></td><td><a id="myPriceFor'+itemlist[i]+'" href="javaScript:void(0)"> '+price[i] +'</a></td></tr>';
475}
476pricelisthtmltxt +='<tr><td></td><td></td></tr>'+'<tr><td>Silvermin</td><td><a id="mySilverMin" href="javaScript:void(0)"> '+silbermin+'</a></td></tr>'+'<tr><td>PagesToScan</td><td><a id="MyInstantSwitch" href="javaScript:void(0)"> '+MyInstantSwitch+'</a></td></tr>';
477pricelisthtmltxt +='</tbody></table><p style="text-align: center;" ><a id="pause_markt" href="javaScript:void(0)">'+startStop+'</a></p><p style="text-align: center;"><a id="freunde" href="javaScript:void(0)">exclude Friends</a></p><table><thead><tr><th>Item</th><th>Price</th></tr></thead><tbody id="otherItemForm" ></tbody></table><p><a id="AddItemToList" href="javaScript:void(0)">Add Item to List</a></p>';
478var myhtmltxt = '<div class="listing" id="preise"><div class="head"><a id="lang_bid" href="javaScript:void(0)" >Settings of Auto-Bid:</a></div><div class="no list">'+pricelisthtmltxt+'<span id="warten" style="text-align: center;" >waiting...</span><div class="list"><br /><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=shaolujing%40gmail%2ecom&lc=US&item_name=blablubbbs%20userscripts&no_note=0¤cy_code=USD&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHostedGuest"><img src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif" alt="donate" /></a></div> </div></div><div class="foot"></div>';
479var villageList = document.getElementById("villageList");
480}
481else{//T4.2 fix
482var pricelisthtmltxt = "";
483for (i = 0; i<itemlist.length; i++){
484price[i] = GM_getValue ( myacc() + itemlist[i] , "0" );
485pricelisthtmltxt += '<tr><td><img src="img/x.gif" class="itemCategory itemCategory'+itemlist[i] +'" alt="itemCategory itemCategory'+itemlist[i] +'"></td><td><a id="myPriceFor'+itemlist[i]+'" href="javaScript:void(0)"> '+price[i] +'</a></td></tr>';
486}
487var myhtmltxt = '<div id="sidebarBoxQuestmaster2" class="sidebarBox "><div class="sidebarBoxBaseBox"><div class="baseBox baseBoxTop"><div class="baseBox baseBoxBottom"><div class="baseBox baseBoxCenter"></div></div></div></div><div class="sidebarBoxInnerBox"><div class="innerBox header "><div class="clear"></div><div class="boxTitle"><a href="https://openuserjs.org/scripts/blablubbb/Travian_T4_Auction_bid" target="_blank" >Auto-Bid Script:</a></div><div></div></div><div class="innerBox content"><ul id="mentorTaskList2" class=""><table><thead><tr><th>Item</th><th>Price</th></tr></thead><tbody id=\"mySellTable\" >'+pricelisthtmltxt+'</tbody><tfoot><tr><td>Silvermin</td><td><a id="mySilverMin" href="javaScript:void(0)"> '+silbermin+'</a></td></tr>'+'<tr><td>PagesToScan</td><td><a id="MyInstantSwitch" href="javaScript:void(0)"> '+MyInstantSwitch+'</a></td></tr></tfoot></table></ul><p><a id="pause_markt" href="javaScript:void(0)">'+startStop+'</a></p><p><span>Status:</span><span id="warten" style="text-align: center;" >waiting...</span></p><p><a id="lang_bid" href="javaScript:void(0)" >Language Setting</a></p><p><a id="freunde" href="javaScript:void(0)">Friends Setting</a></p><p></p><table><thead><tr><th>Item</th><th>Price</th></tr></thead><tbody id="otherItemForm" ></tbody></table><a id="AddItemToList" href="javaScript:void(0)">Add Item to List</a><br /><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=shaolujing%40gmail%2ecom&lc=US&item_name=blablubbbs%20userscripts&no_note=0¤cy_code=USD&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHostedGuest"><img src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif" alt="donate" /></a></div><div class="innerBox footer"></div></div></div><div class="clear"></div>';
488var villageList = document.getElementById("sidebarAfterContent");
489}
490villageList.innerHTML += myhtmltxt;
491makeOtherItemForm();
492makeOtherItemEventListen();
493
494document.getElementById('myPriceFor_bandage25').addEventListener("click", function(){promptPrice_bandage25()}, true);
495document.getElementById('myPriceFor_bandage33').addEventListener("click", function(){promptPrice_bandage33()}, true);
496document.getElementById('myPriceFor_cage').addEventListener("click", function(){promptPrice_cage()}, true);
497document.getElementById('myPriceFor_scroll').addEventListener("click", function(){promptPrice_scroll()}, true);
498document.getElementById('myPriceFor_ointment').addEventListener("click", function(){promptPrice_ointment()}, true);
499document.getElementById('myPriceFor_lawTables').addEventListener("click", function(){promptPrice_lawTables()}, true);
500document.getElementById('myPriceFor_artWork').addEventListener("click", function(){promptPrice_artWork()}, true);
501document.getElementById('myPriceFor_bucketOfWater').addEventListener("click", function(){promptPrice_bucketOfWater()}, true);
502document.getElementById('myPriceFor_bookOfWisdom').addEventListener("click", function(){promptPrice_bookOfWisdom()}, true);
503//document.getElementById('myPriceFor_otherItems').addEventListener("click", function(){promptPrice_otherItems()}, true);
504document.getElementById('mySilverMin').addEventListener("click", function(){prompt_MySilverMin()}, true);
505document.getElementById('MyInstantSwitch').addEventListener("click", function(){prompt_MyInstantSwitch()}, true);
506document.getElementById('pause_markt').addEventListener("click", function(){pauseMarkt()}, true);
507document.getElementById('freunde').addEventListener("click", function(){promptFriends()}, true);
508document.getElementById('lang_bid').addEventListener("click", function(){promptLangBid()}, true);
509document.getElementById('AddItemToList').addEventListener("click", function(){AddItemToList()}, true);
510}
511
512function pauseMarkt(){
513var startStop = GM_getValue ( myacc() + "_startStop" , "Start" );
514if (startStop=="Stop"){
515GM_setValue ( myacc() + "_startStop" , "Start" );
516document.getElementById('pause_markt').textContent = "Start";
517}
518else{
519GM_setValue ( myacc() + "_startStop" , "Stop" );
520document.getElementById('pause_markt').textContent = "Stop";
521loadThisPage(1);
522}
523}
524
525function isMarketPaused(){var startStop = GM_getValue ( myacc() + "_startStop" , "Start" ); if (startStop=="Stop"){return false;}else{return true;}}
526
527function replaceTimer(){ // stolen from my own Script hehehe...
528var j = 1;
529while (document.getElementById('timer'+j))
530{
531document.getElementById('timer'+j).setAttribute('class','my_counter');
532document.getElementById('timer'+j).removeAttribute('id');
533j++;
534}
535}
536
537function myTimer() {
538var timers = [];
539var timer = [];
540var timeleft = 0;
541var newtxt = "";
542var h = 0;
543var m = 0;
544var s = 0;
545function kl10(number){if(number<10){return "0"+number;}else{return number}};
546timers = document.getElementsByClassName('my_counter');
547for (var i = 0;i<timers.length;i++){
548 timer = timers[i].textContent.split(":");
549 timeleft = parseInt(timer[0],10) * 3600;
550 timeleft += parseInt(timer[1],10) * 60;
551 timeleft += parseInt(timer[2],10);
552if(timeleft<1){
553}else{
554timeleft--;
555s = timeleft%60;
556m= ((timeleft-s)/60)%60;
557h= ((timeleft-s)/60-m)/60;
558newtxt = kl10(h)+":"+kl10(m)+":"+kl10(s);
559timers[i].textContent = newtxt;
560}}
561window.setTimeout ( function() {
562 myTimer();
563 },
564 1000 );
565}
566replaceTimer();
567myTimer();
568
569function timeToSeconds(time){
570var timePos1 = time.search(/\:/);
571var t1 = parseInt(time.substr(0, timePos1 ));
572var t2 = parseInt(time.substr(timePos1+1 , 2 ));
573var t3 = parseInt(time.substr(timePos1+4 , 2 ));
574var t = 3600*t1+60*t2+t3;
575return t;
576}
577
578function getPageLocation(){
579var pageLocation="";
580try{
581 pageLocation = window.location.href;
582 pageLocation = pageLocation.split("&action=")[1].split("&")[0];
583 }
584catch(err){pageLocation = "buy";}
585return pageLocation;}
586
587function MyParseInt(str){return parseInt(String(str.match(/[-0-9]+/g)).replace(",",""));}
588
589function GetHighestBidder(item){
590 var HighestBidder = "";
591 try{HighestBidder = item.getElementsByTagName('span')[1].getElementsByTagName('a')[0].textContent;}
592 catch(err){HighestBidder="Multihunter";}
593 if (HighestBidder == ""){HighestBidder="Multihunter";}
594 return HighestBidder;
595}
596
597function getThingAndVal(tdKnode){
598txt = tdKnode.textContent;
599lang = getLang ();
600ThingAndVal = [];
601if(getVersion()=="T4"){
602ThingAndVal[0]=txt.split(" x ")[1].replace(/\s/g,"");
603ThingAndVal[1]=txt.split(" x ")[0];
604}else if(lang == "ae" || lang == "sa" || lang == "eg" || lang == "ir" || lang == "sy"){//T4.2 fix for arabic servers
605number = txt.split("× ")[0].replace(/(\r\n|\n|\r|\s)/gm,"");
606ThingAndVal[0]=txt.split("× ")[1].replace(/\s/g,"");
607ThingAndVal[1]=number.slice(3,number.length-1);
608}else{//T4.2 fix
609number = txt.split("× ")[0].replace(/(\r\n|\n|\r|\s)/gm,"");
610//GM_log(number);
611ThingAndVal[0]=txt.split("× ")[1].replace(/\s/g,"");
612ThingAndVal[1]=number.match(/\d+/)[0];//.slice(3,number.length-1);
613}
614return ThingAndVal;
615}
616
617//Display functions for average prices inspired by mrreza and his code was used as template...
618function mrreza(ThingCol,SilvCol,HeadCols,BodyCols,tableNr){// the exampel numbers are for bids page. mrreza(2,4,5,7,0)
619//there are 5 header colums, so insertCell(5) will create the 6th header. the last number "TableNr" stands for: how many tables are before that table.
620firsttab = document.getElementsByTagName("table")[tableNr].getElementsByTagName("tr")[0].insertCell(HeadCols)
621firsttab.innerHTML="Ø Cost per Unit";
622
623t_loop = document.getElementsByTagName("tbody")[tableNr].getElementsByTagName("tr").length;
624
625for(i=0 ; i<t_loop ; i++){
626base = document.getElementsByTagName("tbody")[tableNr].getElementsByTagName("tr")[i];
627//There are 7 colums with informations originally, so it checks whether we are in the correct table and in a valid row
628if(base.childElementCount==BodyCols){
629//[2] means in the 3rd coumn is the number of things mentioned
630
631Iclas = base.getElementsByClassName("itemCategory")[0].getAttribute('class');
632ThingAndVal = getThingAndVal(base.getElementsByTagName("td")[ThingCol]);
633number = parseInt(ThingAndVal[1]);
634//GM_log(number);
635thingName = ThingAndVal[0];
636//GM_log(thingName);
637//[4] is the silver in the 5th column
638silv2 = parseInt(base.getElementsByTagName("td")[SilvCol].textContent);
639bets = base.getElementsByTagName("td")[SilvCol-1].textContent;//how many people bid on the item
640cost = (Math.round((silv2 / number)*100))/100;
641//There are 7 colums with informations originally, so insertCell(7) will create the 8th column.
642base.insertCell(BodyCols).innerHTML=cost;
643itemlist3 = [
644 "_helmet",
645 "_body",
646 "_leftHand",
647 "_rightHand",
648 "_shoes",
649 "_horse",
650 "_other"
651 ];
652if(include(itemlist3,Iclas.replace(/itemCategory itemCategory/,""))){
653try{
654price = document.getElementById(thingName).textContent;
655}
656catch(err){
657price = 0;
658}
659//return "1";
660}else{
661price = GM_getValue ( myacc() + Iclas.replace(/itemCategory itemCategory/,""), "0" );
662}
663
664base.IwouldPay = Math.floor(price*number);
665
666if (price==0){// not interested in item
667base.style.color='#AAAAAA';
668}
669else{
670if(Math.floor(price*number)<=silv2){//price too expansive, except...
671if(bets==0 && price==(silv2 / number)){
672base.style.color='#99C01A'; //price not too expansive
673}else{
674base.style.color='#AA0000';//price too expansive
675}}else{//price interesting
676base.style.color='#99C01A'; //price not too expansive
677}
678}
679}
680else
681{
682//changed it to make it work in last column...
683selected = base.insertCell(base.childElementCount).innerHTML="";
684}
685
686}
687}
688
689//End of mrreza inspired code...
690function getBuyPrice(Iclas,thingName){
691itemlist3 = [
692 "_helmet",
693 "_body",
694 "_leftHand",
695 "_rightHand",
696 "_shoes",
697 "_horse",
698 "_other"
699 ];
700if(include(itemlist3,Iclas.replace(/itemCategory itemCategory/,""))){
701try{
702return document.getElementById(thingName).textContent;
703}
704catch(err){
705return "0";
706}
707//return "1";
708}else{
709return GM_getValue ( myacc() + Iclas.replace(/itemCategory itemCategory/,""), "0" );
710}}
711
712var lang_Bieten = GM_getValue ( myacc() + "_lang_bid", "bid" );
713
714function btype (item, lang_Bieten){ //a aendern, b bieten, c zu wenig Silber +o falls offen... vorsicht Sprachabhaengig!!!
715 try
716 {
717 var txt ="";
718 var buttontxt = item.getElementsByTagName('a')[0].textContent;
719 if(buttontxt!= lang_Bieten){txt = "a";} else {txt = "b";}
720 if (item.getElementsByTagName('a')[0].getAttribute('class') !="bidButton openedClosedSwitch switchOpened") {txt += "c" ;} else{ txt += "o" ;}
721 return txt;
722 }
723 catch(err)
724 {
725 return "c";
726 }
727 };
728
729var warten = Math.ceil ( Math.random() * 5000 + 3000 ); // random ( 5 sec ) + 3 sec
730makePricesTable(version);
731//GM_log("Page location:" + getPageLocation());
732switch(getPageLocation())
733 {
734 case "accounting": //Accounting
735{//Display average row mrraza
736firsttab = document.getElementsByTagName("tr")[0].insertCell(4)
737firsttab.innerHTML="Ø Cost per Unit";
738/************************************************************** START Collecting Infos
739distinguish product groups by the picture
740distinguish buy and sell by + or -
741Calculate average buying and selling price of this table
742Other= No picture.
743*********************************************************************************/
744itemlist2 = [
745 "_bandage25",
746 "_bandage33",
747 "_cage",
748 "_scroll",
749 "_ointment",
750 "_lawTables",
751 "_artWork",
752 "_bucketOfWater",
753 "_bookOfWisdom",
754 "_helmet",
755 "_body",
756 "_leftHand",
757 "_rightHand",
758 "_shoes",
759 "_horse",
760 "_other"
761 ];
762var causeClassRep = 0;
763var accouClassrep = 0;
764var AccountingAmount = 0;
765var AccStatsPos = [];
766var AccStatsNeg = [];
767var AccountingAmountPos = [];
768var AccountingAmountNeg = [];
769var AccountingImg = [];
770for(var i=0;i<itemlist2.length;i++){
771AccStatsPos[i]=0;
772AccStatsNeg[i]=0;
773AccountingAmountPos[i]=0;
774AccountingAmountNeg[i]=0;
775}
776var causesTable = document.getElementsByClassName("date");
777for(var i=1;i<causesTable.length;i++)
778{
779try
780{
781causeClassRep = itemlist2.indexOf(causesTable[i].parentNode.getElementsByClassName("cause")[0].getElementsByTagName("img")[0].getAttribute('class').replace(/itemCategory itemCategory/,""));
782//AccountingAmount = parseInt(causesTable[i].parentNode.getElementsByClassName("cause")[0].innerHTML.split('">')[1], 10);
783AccountingAmount = parseInt(getThingAndVal(causesTable[i].parentNode.getElementsByClassName("cause")[0])[1].match(/[-0-9]+/g));
784//GM_log("AccountingAmount:"+parseInt(getThingAndVal(causesTable[i].parentNode.getElementsByClassName("cause")[0])[1].match(/[0-9]+/g)) );
785AccountingImg[causeClassRep] = causesTable[i].parentNode.getElementsByClassName("cause")[0].getElementsByTagName("img")[0].cloneNode(true);
786}
787catch(err)
788{
789causeClassRep = itemlist2.indexOf("_other");
790AccountingAmount = 1;
791AccountingImg[causeClassRep] = document.getElementsByClassName("silver")[1].cloneNode(true);
792}
793//accouClassrep= parseInt(causesTable[i].parentNode.getElementsByClassName("accounting")[0].innerHTML.replace(/\s/g,""),10);
794accouClassrep= MyParseInt(causesTable[i].parentNode.getElementsByClassName("accounting")[0].innerHTML);
795//GM_log("accouClassrep:"+MyParseInt(causesTable[i].parentNode.getElementsByClassName("accounting")[0].innerHTML) );
796//fill in price per unit
797causesTable[i].parentNode.insertCell(4).innerHTML=Math.round(accouClassrep/AccountingAmount*100)/100;
798if(accouClassrep>0){
799AccStatsPos[causeClassRep] += accouClassrep;
800AccountingAmountPos[causeClassRep] += AccountingAmount;
801}
802else{
803AccStatsNeg[causeClassRep] += accouClassrep;
804AccountingAmountNeg[causeClassRep] += AccountingAmount;
805}
806}
807/************************************************************** ENDE Collecting Infos *********************************************************************************/
808var AccountingTableIncome = document.createElement("table");
809//var AccountingTableIncomeHeaderRow = document.createElement("tr");
810AccountingTableIncome.innerHTML="<tr><th></th><th colspan='3'>Income (Yield)</th><th colspan='3'>Expense</th><th colspan='3'>Profit</th></tr><tr><td>Object</td><td>Units Sold</td><td>Summe Price</td><td>Ø Revenue/Unit</td><td>Units Bought</td><td>Summe Price</td><td>Ø Expense/Unit</td><td>Ø Profit/Unit</td><td>Cash Flow</td><td>Units Stocked</td><td>Silver Stocked</td></tr>";
811//AccountingTableIncome.appendChild(AccountingTableIncomeHeaderRow);
812var TotalIncome =0;
813var TotalSpending =0;
814var TotalSilverStock =0;
815for(var i=0;i+1<itemlist2.length;i++){
816if(AccountingAmountPos[i]!=0 || AccountingAmountNeg[i]!= 0){
817var AccountingTableIncomeRow = document.createElement("tr");
818var AccountingTableIncomeCol1 = document.createElement("td");
819var AccountingTableIncomeCol2 = document.createElement("td");
820var AccountingTableIncomeCol3 = document.createElement("td");
821var AccountingTableIncomeCol4 = document.createElement("td");
822var AccountingTableIncomeCol5 = document.createElement("td");
823var AccountingTableIncomeCol6 = document.createElement("td");
824var AccountingTableIncomeCol7 = document.createElement("td");
825var AccountingTableIncomeCol8 = document.createElement("td");
826var AccountingTableIncomeCol9 = document.createElement("td");
827var AccountingTableIncomeCol10 = document.createElement("td");
828var AccountingTableIncomeCol11 = document.createElement("td");
829//AccountingTableIncomeCol1.innerHTML = itemlist2[i];
830AccountingTableIncomeCol1.appendChild(AccountingImg[i]);
831AccountingTableIncomeCol2.innerHTML = AccountingAmountPos[i];
832AccountingTableIncomeCol3.innerHTML = AccStatsPos[i];
833AccountingTableIncomeCol4.innerHTML = Math.round(100*AccStatsPos[i]/AccountingAmountPos[i])/100;
834AccountingTableIncomeCol5.innerHTML = AccountingAmountNeg[i];
835AccountingTableIncomeCol6.innerHTML = AccStatsNeg[i];
836AccountingTableIncomeCol7.innerHTML = Math.round(100*AccStatsNeg[i]/AccountingAmountNeg[i])/100;
837AccountingTableIncomeCol9.innerHTML = AccStatsPos[i] + AccStatsNeg[i];
838AccountingTableIncomeCol8.innerHTML = Math.round(100*(AccStatsPos[i]/AccountingAmountPos[i])+100*(AccStatsNeg[i]/AccountingAmountNeg[i]))/100;
839AccountingTableIncomeCol10.innerHTML = AccountingAmountNeg[i]-AccountingAmountPos[i];
840AccountingTableIncomeCol11.innerHTML = Math.round(100*(AccountingAmountNeg[i]-AccountingAmountPos[i])*((AccStatsPos[i]/AccountingAmountPos[i])+(AccStatsNeg[i]/AccountingAmountNeg[i])))/100;
841if(AccountingTableIncomeCol11.innerHTML != "NaN") TotalSilverStock += ((AccountingTableIncomeCol10.innerHTML)*AccStatsNeg[i]/AccountingAmountNeg[i]);
842AccountingTableIncomeRow.appendChild(AccountingTableIncomeCol1);
843AccountingTableIncomeRow.appendChild(AccountingTableIncomeCol2);
844AccountingTableIncomeRow.appendChild(AccountingTableIncomeCol3);
845AccountingTableIncomeRow.appendChild(AccountingTableIncomeCol4);
846AccountingTableIncomeRow.appendChild(AccountingTableIncomeCol5);
847AccountingTableIncomeRow.appendChild(AccountingTableIncomeCol6);
848AccountingTableIncomeRow.appendChild(AccountingTableIncomeCol7);
849AccountingTableIncomeRow.appendChild(AccountingTableIncomeCol8);
850AccountingTableIncomeRow.appendChild(AccountingTableIncomeCol9);
851AccountingTableIncomeRow.appendChild(AccountingTableIncomeCol10);
852AccountingTableIncomeRow.appendChild(AccountingTableIncomeCol11);
853AccountingTableIncome.appendChild(AccountingTableIncomeRow);
854TotalIncome += AccStatsPos[i];
855TotalSpending += AccStatsNeg[i];
856}
857}
858var AccountingTableIncomeTotalTrade = document.createElement("tr");
859AccountingTableIncomeTotalTrade.innerHTML = "<td colspan='2'> Total Trade Income</td><td>"+TotalIncome+"</td><td colspan='2'>Total Trade Expenses</td><td>"+TotalSpending+"</td><td colspan='2'>Total Trade Cash Flow</td><td>"+(TotalIncome+TotalSpending)+"</td><td>Total Silver Stocked</td><td>"+ Math.round(-TotalSilverStock)+"</td>";
860AccountingTableIncome.appendChild(AccountingTableIncomeTotalTrade);
861//other Income/Expenses
862for(var i=itemlist2.indexOf("_other");i<itemlist2.length;i++){
863if(AccountingAmountPos[i]!=0 || AccountingAmountNeg[i]!= 0){
864var AccountingTableIncomeRow = document.createElement("tr");
865var AccountingTableIncomeCol1 = document.createElement("td");
866var AccountingTableIncomeCol2 = document.createElement("td");
867var AccountingTableIncomeCol3 = document.createElement("td");
868var AccountingTableIncomeCol4 = document.createElement("td");
869var AccountingTableIncomeCol5 = document.createElement("td");
870var AccountingTableIncomeCol6 = document.createElement("td");
871var AccountingTableIncomeCol7 = document.createElement("td");
872var AccountingTableIncomeCol8 = document.createElement("td");
873var AccountingTableIncomeCol9 = document.createElement("td");
874var AccountingTableIncomeCol10 = document.createElement("td");
875var AccountingTableIncomeCol11 = document.createElement("td");
876//AccountingTableIncomeCol1.innerHTML = itemlist2[i];
877AccountingTableIncomeCol1.appendChild(AccountingImg[i]);
878AccountingTableIncomeCol2.innerHTML = AccountingAmountPos[i];
879AccountingTableIncomeCol3.innerHTML = AccStatsPos[i];
880AccountingTableIncomeCol4.innerHTML = "";
881AccountingTableIncomeCol5.innerHTML = AccountingAmountNeg[i];
882AccountingTableIncomeCol6.innerHTML = AccStatsNeg[i];
883AccountingTableIncomeCol7.innerHTML = "";
884AccountingTableIncomeCol9.innerHTML = AccStatsPos[i] + AccStatsNeg[i];
885AccountingTableIncomeCol8.innerHTML = "";
886AccountingTableIncomeCol10.innerHTML = "";
887AccountingTableIncomeCol11.innerHTML = "";
888AccountingTableIncomeRow.appendChild(AccountingTableIncomeCol1);
889AccountingTableIncomeRow.appendChild(AccountingTableIncomeCol2);
890AccountingTableIncomeRow.appendChild(AccountingTableIncomeCol3);
891AccountingTableIncomeRow.appendChild(AccountingTableIncomeCol4);
892AccountingTableIncomeRow.appendChild(AccountingTableIncomeCol5);
893AccountingTableIncomeRow.appendChild(AccountingTableIncomeCol6);
894AccountingTableIncomeRow.appendChild(AccountingTableIncomeCol7);
895AccountingTableIncomeRow.appendChild(AccountingTableIncomeCol8);
896AccountingTableIncomeRow.appendChild(AccountingTableIncomeCol9);
897AccountingTableIncomeRow.appendChild(AccountingTableIncomeCol10);
898AccountingTableIncomeRow.appendChild(AccountingTableIncomeCol11);
899AccountingTableIncome.appendChild(AccountingTableIncomeRow);
900}
901}
902var AccountingTableIncomeTotal = document.createElement("tr");
903AccountingTableIncomeTotal.innerHTML = "<td colspan='2'> Total Income</td><td>"+(TotalIncome+AccStatsPos[itemlist2.indexOf("_other")])+"</td><td colspan='2'>Total Expenses</td><td>"+(TotalSpending+AccStatsNeg[itemlist2.indexOf("_other")])+"</td><td colspan='2'>Total Cash Flow</td><td>"+((TotalIncome+AccStatsPos[itemlist2.indexOf("_other")])+(TotalSpending+AccStatsNeg[itemlist2.indexOf("_other")]))+"</td><td></td><td></td>";
904AccountingTableIncome.appendChild(AccountingTableIncomeTotal);
905document.getElementById("auction").appendChild(AccountingTableIncome);
906//mrreza(1,2,4,4);// does not work because more stupid things in same td...
907}
908 break;
909 case "bids": //Gebote-Seite: Anzeige
910{/************************************************************** Sende Gebote auf Server *********************************************************************************/
911//mrreza1();
912mrreza(2,4,5,7,0);
913mrreza(2,4,5,7,1);
914/************************************************************** ENDE von Sende Gebote auf Server *********************************************************************************/
915}
916 break;
917 case "sell": //Verkaufs-Seite: Anzeige
918{/************************************************************** Verkaus-Seite- Aktuelle Verkaefe *********************************************************************************/
919//GM_log("sell 1");
920mrreza(2,4,4,6,0);
921//GM_log("sell 2");
922mrreza(1,3,4,5,1);
923}
924 break;
925 default: // Kauf-Seite: Anzeige
926{/************************************************************** *********************************************************************************/
927mrreza(1,3,5,6,0);// brakes bidding
928// walk through rows and
929//3. Mark bids of friends purple and entree friends bids into list... get part of code from
930//4. put in value for bidding... move from other section...
931
932t_loop = document.getElementsByTagName("tbody")[0].getElementsByTagName("tr").length;
933
934for(i=0 ; i<t_loop ; i++){
935base = document.getElementsByTagName("tbody")[0].getElementsByTagName("tr")[i];
936var type = btype (base, lang_Bieten);
937if( type =="ao" || type =="ac" ){base.style.color='#655EE6';} //selber schon geboten
938if( type =="ao" || type =="bo"){// offener Kasten... fill in Numbers.
939document.getElementsByClassName('maxBid')[0].value= base.IwouldPay;
940//now test for friend status... and test whether in friends-bids list...
941//get name of highest bidder and compare with friends list.
942var HighestBidder = GetHighestBidder(document.getElementsByTagName("tbody")[0].getElementsByTagName("tr")[i+1]);
943//try{HighestBidder = document.getElementsByTagName("tbody")[0].getElementsByTagName("tr")[i+1].getElementsByTagName('span')[1].textContent;}
944//catch(err){HighestBidder="Multihunter";}
945//if (HighestBidder == ""){HighestBidder="Multihunter";}
946//GM_log("Highest Bidder="+HighestBidder);
947var friends = new Array;
948friends = GM_getValue ( myacc() + "_friends", "" ).split(",");
949var IncludeInFriends = include(friends,HighestBidder);
950if(IncludeInFriends){//If in this list mark bidder-name bold+purple and turn line purple
951document.getElementsByTagName("tbody")[0].getElementsByTagName("tr")[i+1].getElementsByTagName('span')[1].style.color='#991AC0';
952document.getElementsByTagName("tbody")[0].getElementsByTagName("tr")[i+1].getElementsByTagName('span')[1].style.fontWeight='bold';
953base.style.color='#991AC0';
954}
955// get auction id aid and check whether in friends-bids list
956var friendsBidsArr = [];
957friendsBidsArr = getFriendsBids();
958if(version=="T4"){aid = document.getElementsByTagName("input")[4].value;}else{aid = document.getElementsByTagName("input")[6].value;}
959var IncludeInFriendsBids = include(friendsBidsArr,aid);
960// if not in list and friend, add to list
961if( !IncludeInFriendsBids && IncludeInFriends){addFriendsBid(aid);}
962 //if not friend, but in list, remove from list
963if( !IncludeInFriends && IncludeInFriendsBids ){removeFriendsBid(aid);}
964i++;
965}else{// change to purple if in friends-bids-list...
966try{
967var aid_href = base.getElementsByTagName('a')[0].search;
968// GM_log("aid_href"+aid_href);
969var aidPos1 = aid_href.search(/\&a=/);
970var aidPos2 = aid_href.search(/\&z=/);
971var aid = aid_href.substr(aidPos1+3 , aidPos2-aidPos1-3 );
972var friendsBidsArr = [];
973friendsBidsArr = getFriendsBids();
974if(include(friendsBidsArr,aid)){base.style.color='#991AC0';}
975}
976catch(err){//too less silver ==> No bid button ==> No aid
977base.style.color='#E39210'; // some orange
978}
979}
980}
981}
982}
983//GM_log("Finished analyzing. Now Auto-Action");
984if(!isMarketPaused()){
985switch(getPageLocation()){
986case "acco": //Accounting
987{/************************************************************** START Collecting Infos
988just empty atm...
989*********************************************************************************/}
990 break;
991 case "bids": //Gebote-Seite: Lade Inhalte auf Server und loesche danach Inhalte
992{/************************************************************** Sende Gebote auf Server *********************************************************************************/
993
994/************************************************************** ENDE von Sende Gebote auf Server *********************************************************************************/
995}
996 break;
997 case "sell": //Verkaufs-Seite: Erstelle Angebote
998{/************************************************************** Verkaus-Seite- Aktuelle Verkaefe *********************************************************************************/
999}
1000 break;
1001 default: // Kauf-Seite: Biete auf Schnaeppchen
1002{/************************************************************** Biete auf Schnaeppchen *********************************************************************************/
1003
1004//Multiplicator
1005var m = "";
1006//get bid
1007var btable = document.getElementsByTagName('tbody')[0].firstChild;
1008if(version=="T4"){
1009var silver = document.getElementById('plusLink').childNodes[1].childNodes[3].childNodes[1].textContent;
1010//GM_log("Silber"+silver);
1011}
1012else{
1013var silver = document.getElementsByClassName('ajaxReplaceableSilverAmount')[0].textContent;
1014}
1015var silbermin = GM_getValue ( myacc() + "_MySilverMin", "0" );
1016var silverval = parseInt(silver)-silbermin;
1017//GM_log("Silber zur verfuegung="+silverval);
1018var bitable = false;
1019var item=btable.nextSibling;
1020for (var i=0;i<21;i++){
1021try
1022 {
1023 while(item.nodeType!=1)
1024 {
1025 item=item.nextSibling;
1026 }
1027var test = 1;
1028try{test = item.getElementsByTagName('a')[0].getAttribute('class');}catch(err){test=0;
1029//GM_log("log_Err:"+err);
1030}
1031if(item.childNodes[1].childNodes[1]){
1032 var time = item.childNodes[9].textContent;
1033// GM_log("time="+time);
1034 var timeval = parseInt(time);
1035// GM_log("timeval"+timeval);
1036//try{GM_log("Node if exists: "+item.childNodes[1].innerHTML) + " test="+test;}catch(err){GM_log("log_Err");}
1037if (test)//pruefe ob normale Reihe
1038 {//GM_log("Node exists... normal row and button is labeled: "+item.getElementsByTagName('a')[0].textContent);
1039 var Iclas = item.childNodes[1].childNodes[1].getAttribute('class');
1040// GM_log("Iclas="+Iclas);
1041 ThingAndVal = getThingAndVal(item.childNodes[3]);
1042 var thingval = parseInt(ThingAndVal[1]);//how many items
1043 var thingName = ThingAndVal[0];
1044// GM_log("thing="+thingName);
1045 var betsval = parseInt(item.childNodes[5].textContent);//how many bets
1046// GM_log("betsval"+betsval);
1047 var priceval = parseInt(item.childNodes[7].textContent);//whats the price
1048// GM_log("priceval"+priceval);
1049 var aid_href = item.getElementsByTagName('a')[0].search;
1050// GM_log("aid_href"+aid_href);
1051 var aidPos1 = aid_href.search(/\&a=/);
1052 var aidPos2 = aid_href.search(/\&z=/);
1053 var aid = aid_href.substr(aidPos1+3 , aidPos2-aidPos1-3 );
1054 var friendsBidsArr = [];
1055 friendsBidsArr = getFriendsBids();
1056// GM_log(" aid="+aid);
1057 if (aid) {
1058 //GM_log("Geschlossener Kasten und aid="+aid);
1059 } //Stats an server
1060 else{//wir haben Anfang von offenem Kasten
1061 if(version=="T4"){aid = document.getElementsByTagName("input")[4].value;}else{aid = document.getElementsByTagName("input")[6].value;}
1062 GM_log("Offener Kasten und aid="+aid);
1063 }
1064GM_log("time="+time+" aid="+aid);
1065var type = btype (item, lang_Bieten);
1066GM_log("btype="+type);
1067
1068m=getBuyPrice(Iclas,thingName);
1069 var bidval =Math.floor(parseFloat(m) * thingval);
1070GM_log("thing="+thingName+"; Log...priceval:"+priceval+"; type:"+type+"; bidval:"+bidval + "; betsval:"+betsval+"; m="+m);
1071if(include(friendsBidsArr,aid)){GM_log("1.Angebot von Freund an aid("+aid+")erkannt...list of aid:"+friendsBidsArr);bitable = false;} else
1072if (type =="ao" || type =="ac") //selber schon geboten
1073 {
1074GM_log("Selber Hoechster Bieter");
1075 bitable = false;
1076 }
1077 else if ( priceval>bidval || (priceval==bidval && betsval!=0) )//teure Items...
1078 {
1079GM_log("Teuer...priceval:"+priceval+"; price:"+priceval+"; bidval:"+bidval + "; betsval:"+betsval+" und aid:" + aid);
1080 bitable = false;
1081 }
1082 else if ((type=="c") ||(bidval>silverval)) // zu wenig Silber...
1083 {
1084GM_log("log log zu wenig Silber und aid:" + aid);
1085 item.style.color='#AAAACC';
1086 bitable = false;
1087 // i=23;
1088 // var warten=100*warten;
1089 // if(timeval>1){warten= 1800000*timeval-100*warten;}
1090 // window.setTimeout ( function() {
1091 // window.location.href = "http://"+window.location.hostname+"/hero_auction.php?action=bids";
1092 // },
1093 // warten );
1094 // var wartenStd = Math.floor(warten/3600000);
1095 // var wartenMin = Math.floor((warten/60000)-wartenStd*60);
1096 // var wartenSec = Math.floor((warten/1000)-wartenStd*3600-wartenMin*60);
1097 // document.getElementById('warten').textContent = "sleeping " + wartenStd + ":"+wartenMin+":"+wartenSec+" of "+time;
1098 // bitable = true;
1099
1100 }
1101 else if (type=="bc") //zum bieten oeffen...
1102 {
1103 {
1104GM_log("Bieten vorbereiten von aid"+aid);
1105 window.hrefvar = item.getElementsByTagName('a')[0].href;
1106 i=23;
1107 window.setTimeout ( function() {
1108 window.location.href = window.hrefvar;
1109 },
1110 warten );
1111 var wartenTxt = Math.round(warten/1000);
1112 document.getElementById('warten').innerHTML = "prepare bidding in <span class=\"my_counter\"> 00:00:0"+wartenTxt+"</span>";
1113 bitable = true;
1114 }
1115 }
1116 else // type ist bo
1117 {
1118GM_log("Bieten!");
1119 {bitable = true;}
1120 }
1121 }
1122}else if (bitable)
1123 {// Knoten ist aktiver Knoten
1124 if (bidval>silverval)
1125 {
1126 bidval=silverval;
1127 item.style.color='#AAAACC';
1128 }
1129 //Ausgabe
1130var HighestBidder = GetHighestBidder(item);
1131 //var HighestBidder = item.getElementsByTagName('span')[1].getElementsByTagName('a')[0].textContent;
1132//if (HighestBidder == ""){HighestBidder="Multihunter";}
1133GM_log("Highest Bidder="+HighestBidder);
1134var friends = new Array;
1135friends = GM_getValue ( myacc() + "_friends", "" ).split(",");
1136if(include(friends,HighestBidder)){
1137GM_log("Freund "+HighestBidder+" wird nicht ueberboten");
1138if(version=="T4"){aid = document.getElementsByTagName("input")[4].value;}else{aid = document.getElementsByTagName("input")[6].value;}
1139GM_log("neue aid" + aid);
1140addFriendsBid(aid);
1141bitable = false;
1142}else{
1143GM_log("jetzt bieten!!!" + aid);
1144 document.getElementsByClassName('maxBid')[0].value= bidval ;
1145 if(version=="T4"){
1146 setTimeout ( function() {
1147 document.getElementsByTagName('button')[15].click();
1148 },
1149 warten );
1150 var wartenTxt = Math.round(warten/1000);
1151 }else{
1152 setTimeout ( function() {
1153 document.getElementsByClassName("auctionDetails")[0].getElementsByTagName("button")[0].click();
1154 },
1155 warten );
1156 var wartenTxt = Math.round(warten/1000);
1157 }
1158 document.getElementById('warten').innerHTML = "make bid in <span class=\"my_counter\"> 00:00:0"+wartenTxt+"</span>";
1159 i=23;
1160 }}
1161if (i != 23){
1162item=item.nextSibling;
1163}
1164}
1165catch(err)
1166{
1167GM_log("Loop broke, i=22 and Error" + err);
1168i=22;
1169}}
1170/************************************************************** ENDE von Biete auf Schnaeppchen *********************************************************************************/
1171if ( !bitable && silverval){
1172GM_log("NextPage...");
1173var MyInstantSwitch = GM_getValue ( myacc() + "_MyInstantSwitch", "0" );
1174if (MyInstantSwitch>0){
1175 var pagenr = getPageNumber();
1176 if( MyInstantSwitch > pagenr ){//go to next page as usual
1177 var nextPage = loadNextPage(warten);
1178 if (!nextPage){
1179 warten = timeToSeconds(time)*1000-10000;
1180 startNewCycle(warten);
1181 }}
1182 else{//sleep for time then start new cycle
1183 warten = timeToSeconds(time)*1000-10000;
1184 startNewCycle(warten);
1185 }
1186 }
1187else{
1188 var nextPage = loadNextPage(warten);
1189 if (!nextPage){startNewCycle(8000*warten);}}}
1190else if (!bitable){
1191//warten = 2*3600000- 150*warten;//starte so in knapp 2 Stunden erneut...
1192 warten = timeToSeconds(time)*1000-10000;
1193startNewCycle(warten);
1194}
1195}
1196 break;
1197}
1198}
1199GM_log("Code zuende... was vergessen?");