Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name MTV Statistical Data For Tampermonkey & Greasemonkey
- // @namespace MTV_statistical_data
- // @include /^https?://(www\.)?mytrafficvalue\.com/shareholders\.html(\#marketplace)?$/
- // @author facebook.com/igor39
- // @version 7.5
- // @grant none
- // @description Improving the user experience & provide more of statistics on the page www.mytrafficvalue.com/shareholders.html
- // ==/UserScript==
- function main(){
- 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>',
- 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>',
- 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}',
- prefix ='//'+window.location.hostname+'/shareholders/fullMarketList/', re=new RegExp('(\\d)(?=(\\d\\d\\d)+([^\\d]|$))', 'g'), current_number_of_lines=50,number_of_lines=50;
- // share market view
- 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;}}}
- function getById(id){return document.getElementById(id);}
- function getBySel(sel){return document.querySelector(sel);}
- 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);}
- 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\"]");}}
- 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;}}
- function rp_market(){getById("modal").setAttribute("is","rp_market");market="RP's Market:"; price_sign="$";console.log("rp_market");}
- function user_bids(){getById("modal").setAttribute("is","user_bids");market="User Bids:"; price_sign="$";console.log("user_bids");}
- function bap_market(){getById("modal").setAttribute("is","bap_market");market="BAP Market:";price_sign ="";console.log("bap_market");}
- function replace2(el){ var style, newDiv, elem, new_attr;
- if(!getById('myform')){newDiv=document.createElement('div'); newDiv.innerHTML =my_form_code; getById('modalContent').appendChild(newDiv);
- getById("brd3").innerHTML=number_of_lines+' (Click to Close) ';
- style=document.createElement('style'); style.appendChild(document.createTextNode(style_of_table)); elem=getById("modalContent"); elem.insertBefore(style, elem.childNodes[0]);
- } 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();}
- }
- 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+'"]');
- // we will also add the results of previous calculation to the next:
- 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;}} }
- 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;}}
- 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++;
- }}
- var prev_price=[ [],[],[] ],//rp_market, user_bids, bap_market.
- min_price= [999999,0,999999],
- counter2= [0,0,0];
- 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)
- 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;}
- 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.
- 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.
- 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;
- var start1 =new Date(),end1,a;
- 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;}}
- else if(getById("modal").getAttribute('is')=="bap_market"){while(price <= limit){total_sum_on(price);price+=1;}}
- getById("tbody1").innerHTML=tbody1_headers; getById("TheMarketID").innerHTML=market;
- for(a=0;a<arr.length;a++){if(arr[a]){getById("tbody1").innerHTML+=arr[a];arr[a]='';}}
- var i,x=document.querySelectorAll('tbody#tbody1 tr'),RPs_value=0,RPs_amount=0,text;
- 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 ');
- 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);
- }}
- function for_modal(){//for processing of a modal window
- 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;}}
- 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;");}
- if(qs4){replace2(qs4);}
- 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,'');
- 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();}};
- getById("input_submit2").onclick=function(){var price=getById("input_price").value,limit=getById("input_limit").value; run_total_sum_on(price,limit);};
- getById("brd3").onclick=function(){console.log("#brd3 has been clicked!");modal.close();};
- }
- }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;}}
- }handle=setInterval(for_modal,100);
- window.refreshMarket= function refreshMarket(){//By default, this function defined in the script: mytrafficvalue.com/assets201601213/scripts/shares.js
- var timeout=2000,contentUrl=mtv.baseUrl+'shareholders/refreshTabs';$.ajax({
- url:contentUrl,dataType:'json',type:'get',
- success: function(data){$("#marketSell").html(data.marketSale);$("#marketBuy").html(data.marketBuy);$("#marketBapSale").html(data.marketBapSale);},
- complete:function(xhr, textStatus){setTimeout(refreshMarket,timeout);}
- });};
- // end of share market view
- }
- var script = document.createElement('script');script.setAttribute('id','mfnc0');
- script.appendChild(document.createTextNode('('+ main +')();'));
- var handle=setInterval(function(){if(document.readyState=="complete"){if(document.getElementById("main_content")){clearInterval(handle);handle=0;document.getElementById("main_content").appendChild(script);}}},500);
- // 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
- // This script will be added to "main_content" with the id "mfnc0"
- // See also: http://stackoverflow.com/questions/588004/is-floating-point-math-broken
- // 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