Advertisement
root2

MTV_Statistical_Data

Aug 5th, 2016
429
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         MTV Statistical Data For Tampermonkey & Greasemonkey
  3. // @namespace    MTV_statistical_data
  4. // @include     /^https?://(www\.)?mytrafficvalue\.com/shareholders\.html(\#marketplace)?$/
  5. // @author       facebook.com/igor39
  6. // @version      7.5
  7. // @grant        none
  8. // @description  Improving the user experience & provide more of statistics on the page www.mytrafficvalue.com/shareholders.html
  9. // ==/UserScript==
  10. function main(){
  11. var handle, arr=[], counter, market, price_sign, onlyOne, tbody1_headers='<tr><th id="TheMarketID" style="width:120px"></th><th>RP\'s amount</th><th>RP\'s value</th></tr>',
  12. my_form_code='<form id="myform"><div id="brd7">To Show/Hide the table above you need to click on overlay (outside of this window)</div>Lines per page: <span id="brd3"></span><input checked type="input" id="number_of_lines" size="5" value="" /> <button id="input_submit1" type="button">Submit</button></form>   <form id="myform2"><div id="brd6"><table class="commissions"><tbody>'+tbody1_headers+'</tbody></table>Start with a price: <input type="input" id="input_price" size="4" value="" /> End on a price <input type="input" id="input_limit" size="4" value="" /> <button id="input_submit2" type="button">Submit</button></div></form>',
  13. style_of_table='table.commissions td, #tbody0 th{font-family: Verdana; font-size: 12px; padding: 0; color: #778899} #tbody1 th, #tbody1 td{text-align:left; width:100px;height:auto;font-size:1.0em} table.commissions tr:nth-child(even){background: #000075} table.commissions tr:nth-child(odd){background: black} table.commissions tr:hover:nth-child(even) td{color: springgreen} table.commissions tr:hover:nth-child(odd) td{color: aqua} #brd6{background: black; color: turquoise; font-size: 16px; font-family: Verdana} #brd6:hover{color: springgreen}',
  14. prefix ='//'+window.location.hostname+'/shareholders/fullMarketList/', re=new RegExp('(\\d)(?=(\\d\\d\\d)+([^\\d]|$))', 'g'), current_number_of_lines=50,number_of_lines=50;
  15.  
  16. // share market view
  17. var sh=0; function show_hide(){if(getById("tbody0")){if(!sh){getById("tbody0").style="display: block;";sh=1;}else{getById("tbody0").style="display: none;";sh=0;}}}
  18. function getById(id){return document.getElementById(id);}
  19. function getBySel(sel){return document.querySelector(sel);}
  20. function click(sel){var event=document.createEvent('MouseEvents');event.initMouseEvent('click',1,1,window,1,0,0,0,0,0,0,0,0,0,null);document.querySelector(sel).dispatchEvent(event);}
  21. function click_close(){if(getById("modal").getAttribute("is")=="bap_market"){modal.close();click("a[href$=\"shareholders/bap_market.html\"]");}else if(getById("modal").getAttribute("is")=="user_bids"){modal.close();click("a[href$=\"shareholders/bids.html\"]");}else if(getById("modal").getAttribute("is")=="rp_market"){modal.close();click("a[href$=\"shareholders/market.html\"]");}}
  22. function at_first(){getById("TheMarketID").innerHTML=market; click('div.paging > a.pagination[href$="/1/'+number_of_lines+'"]'); if(getById("tbody1")){getById("tbody1").innerHTML=tbody1_headers;getById("TheMarketID").innerHTML=market;}}
  23. function rp_market(){getById("modal").setAttribute("is","rp_market");market="RP's Market:"; price_sign="$";console.log("rp_market");}
  24. function user_bids(){getById("modal").setAttribute("is","user_bids");market="User Bids:";   price_sign="$";console.log("user_bids");}
  25. function bap_market(){getById("modal").setAttribute("is","bap_market");market="BAP Market:";price_sign ="";console.log("bap_market");}
  26. function replace2(el){ var style, newDiv, elem, new_attr;
  27. if(!getById('myform')){newDiv=document.createElement('div'); newDiv.innerHTML =my_form_code; getById('modalContent').appendChild(newDiv);
  28. getById("brd3").innerHTML=number_of_lines+' (Click to Close) ';
  29. style=document.createElement('style'); style.appendChild(document.createTextNode(style_of_table)); elem=getById("modalContent"); elem.insertBefore(style, elem.childNodes[0]);
  30. } if(!getById("tbody1")||current_number_of_lines!=number_of_lines){current_number_of_lines=number_of_lines; getById("brd3").innerHTML=number_of_lines+' (Click to Close) '; if(el.href.match(/list/g)){new_attr= prefix+'list/1/'+number_of_lines;}else if(el.href.match(/bid/g)){new_attr= prefix+'bid/1/'+number_of_lines;} else if(el.href.match(/bap/g)){new_attr= prefix+'bap/1/'+number_of_lines;}el.href=new_attr;at_first();}
  31. }
  32. function total_sum_on(price){if(getById(price)){ var RPs_value=0,RPs_amount=0,text,i,x=document.querySelectorAll('tbody#tbody0 tr[id="'+price+'"]');
  33. // we will also add the results of previous calculation to the next:
  34. if(getBySel('div#modal div.paging')&&getBySel('div#modal strong').innerHTML!="1"){ var j,k=document.querySelectorAll('tbody#tbody1 tr[id="'+price+'"]'); for(j=0;j<k.length;j++){var isNum=k[j].children[1].children[0];isNum*=1;isNum=typeof(isNum); if(isNum=="number"){text=k[j].children[1].children[0].innerHTML.replace(/[$\s]/g,''); text*=1;RPs_amount+=text;}} }
  35. for(i=0;i < x.length;i++){if(x[i].children[3]){text=x[i].children[1].innerHTML.replace(/\,/g,''); text*=1;RPs_amount+=text;}}
  36. RPs_value=RPs_amount*price; RPs_value=RPs_value.toFixed(2); RPs_value*=1; RPs_value=RPs_value.toString().replace(re,'$1 '); RPs_amount=RPs_amount.toString().replace(re,'$1 '); arr[counter]='<tr id="'+price+'"><td>RPs at '+price+':</td><td><b>'+RPs_amount+'</b></td><td><b>'+price_sign+RPs_value+'</b></td></tr>';counter++;
  37. }}
  38. var prev_price=[ [],[],[] ],//rp_market, user_bids, bap_market.
  39. min_price=     [999999,0,999999],
  40. counter2=      [0,0,0];
  41.  
  42. function run_total_sum_on(price,limit){ if(onlyOne||!getBySel('div#modal div.paging')||getBySel('div#modal strong').innerHTML=="1"){onlyOne=0;//Only one calculation per page. (excluding the first page) (otherwise the results of previous calculation will be added to the next on the same page)
  43. var e,j; if(getById("modal").getAttribute('is').match(/(rp_market|bap_market)/g)){ e=0; if(getById("modal").getAttribute('is')=="bap_market"){e=2;}
  44.               prev_price[e][counter2[e]]=price; counter2[e]++; j= prev_price[e].length; while(j--){if(prev_price[e][j] < min_price[e]){min_price[e] = prev_price[e][j];}} if(price>min_price[e]){price=min_price[e];}}// price won't be bigger than previous minimum.
  45.     else{e=1; prev_price[e][counter2[e]]=price; counter2[e]++; j= prev_price[e].length; while(j--){if(prev_price[e][j] > min_price[e]){min_price[e] = prev_price[e][j];}} if(price<min_price[e]){price=min_price[e];}}// price won't be smaller than previous maximum.
  46. if(getBySel('div#modal div.paging')&&getBySel('div#modal strong').innerHTML=="1"){getById("tbody1").innerHTML=tbody1_headers;getById("TheMarketID").innerHTML=market;}price*=1;limit*=1;counter=0;clearInterval(handle);handle=0;
  47.  
  48. var start1 =new Date(),end1,a;
  49. if(getById("modal").getAttribute('is')=="rp_market"){limit+=0.0001; while(price <= limit){price= +price.toFixed(5);total_sum_on(price);price+=0.0001;}} else if(getById("modal").getAttribute('is')=="user_bids"){limit-=0.0001; while(price >= limit){price= +price.toFixed(5);total_sum_on(price);price-=0.0001;}}
  50. else if(getById("modal").getAttribute('is')=="bap_market"){while(price <= limit){total_sum_on(price);price+=1;}}
  51.  
  52. getById("tbody1").innerHTML=tbody1_headers;   getById("TheMarketID").innerHTML=market;
  53. for(a=0;a<arr.length;a++){if(arr[a]){getById("tbody1").innerHTML+=arr[a];arr[a]='';}}
  54. var i,x=document.querySelectorAll('tbody#tbody1 tr'),RPs_value=0,RPs_amount=0,text;
  55. for(i=1;i < x.length;i++){if(x[i].children[1].children[0]){text=x[i].children[1].children[0].innerHTML.replace(/[$\s]/g,''); text*=1; RPs_amount+=text; text=x[i].children[2].children[0].innerHTML.replace(/[$\s]/g,'');text*=1; RPs_value+=text;}}     RPs_value= +RPs_value.toFixed(2); RPs_value=RPs_value.toString().replace(re,'$1 '); RPs_amount=RPs_amount.toString().replace(re,'$1 ');
  56. getById("tbody1").innerHTML+='<tr><td>Total:</td><td><b>'+RPs_amount+'</b></td><td><b>'+price_sign+RPs_value+'</b></td></tr>';  end1=new Date();console.log('The calculation lasted: '+(end1.getTime()-start1.getTime())+' ms\n'+end1+'\n'); handle=setInterval(for_modal,100);
  57. }}
  58. function for_modal(){//for processing of a modal window
  59. var qs1=getById("modal"), qs2, qs3, qs4=getBySel('div#modalContent a.pagination'), qs5; if(getById("modalContent")){qs2=getById("modalContent"); if(qs2.children[0]&&!getBySel("div#modalContent a[href$=\"cashier.html\"]")){qs3=1;}}
  60. if(qs3){ if(qs1.style.width!="570px"){qs1.setAttribute('style',"display: block; width: 570px; height:"+document.documentElement.clientHeight+"px; top: 0px; left:"+parseInt(document.documentElement.clientWidth / 4 + 149)+"px;overflow-x: hidden;overflow-y: scroll;padding:0; margin:0;");}
  61. if(qs4){replace2(qs4);}
  62. if(!getById("Price")){onlyOne=1;var a,b=document.querySelectorAll('div#modalContent tbody');for(a=0;a<b.length;a++){if(!a){b[a].style="display: none;";getById("overlay").onclick=show_hide;}b[a].setAttribute('id',"tbody"+a);}var new_id,i,x=document.querySelectorAll('tbody#tbody0 tr'),sel;for(i=0;i<x.length;i++){new_id=x[i].children[2].innerHTML.replace(/[,$]/g,'');if(i){new_id*=1;}x[i].setAttribute('id',new_id);if(x[i].children[0]){sel=x[i].children[0]; sel.innerHTML=i+" - "+sel.innerHTML;}}getById("input_price").value = getById("tbody0").children[1].children[2].innerHTML.replace(/[,$]/g,''); var el=getById("tbody0"); getById("input_limit").value= el.children[el.children.length -2].children[2].innerHTML.replace(/[,$]/g,'');
  63. getById("input_submit1").onclick=function(){var n;if(getById('number_of_lines').value){n=getById('number_of_lines').value; n*=1;number_of_lines=n;}if(!qs4){click_close();}};
  64. getById("input_submit2").onclick=function(){var price=getById("input_price").value,limit=getById("input_limit").value; run_total_sum_on(price,limit);};
  65. getById("brd3").onclick=function(){console.log("#brd3 has been clicked!");modal.close();};
  66. }
  67. }else{if(qs1.style.width=="570px"){qs1.setAttribute('style',"display: block; width: auto; height:auto; padding:0; margin:0;");} if(getBySel("tbody a[href$=\"shareholders/market.html\"]")){getBySel("tbody a[href$=\"shareholders/market.html\"]").onclick=rp_market; getBySel("tbody a[href$=\"shareholders/bids.html\"]").onclick=user_bids; getBySel("tbody a[href$=\"shareholders/bap_market.html\"]").onclick=bap_market;}}
  68. }handle=setInterval(for_modal,100);
  69.  
  70. window.refreshMarket= function refreshMarket(){//By default, this function defined in the script: mytrafficvalue.com/assets201601213/scripts/shares.js
  71. var timeout=2000,contentUrl=mtv.baseUrl+'shareholders/refreshTabs';$.ajax({
  72. url:contentUrl,dataType:'json',type:'get',
  73. success: function(data){$("#marketSell").html(data.marketSale);$("#marketBuy").html(data.marketBuy);$("#marketBapSale").html(data.marketBapSale);},
  74. complete:function(xhr, textStatus){setTimeout(refreshMarket,timeout);}
  75. });};
  76. // end of share market view
  77. }
  78. var script = document.createElement('script');script.setAttribute('id','mfnc0');
  79. script.appendChild(document.createTextNode('('+ main +')();'));
  80. var handle=setInterval(function(){if(document.readyState=="complete"){if(document.getElementById("main_content")){clearInterval(handle);handle=0;document.getElementById("main_content").appendChild(script);}}},500);
  81. // We cannot use the unsafeWindow Greasemonkey property in Tampermonkey: http://stackoverflow.com/questions/2303147/injecting-js-functions-into-the-page-from-a-greasemonkey-script-on-chrome
  82. // This script will be added to "main_content" with the id "mfnc0"
  83. // See also: http://stackoverflow.com/questions/588004/is-floating-point-math-broken
  84. // that means, if you set a start price with "0.0022" & a end price with "0.0017" on the user bids page, the script will calculate down to "0.0016" level! (+1 level to down)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement