-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathstalk_bookmarklet.js
1 lines (1 loc) · 9.05 KB
/
stalk_bookmarklet.js
1
javascript:(function(){const refreshRate=3e3,timeOuts=2e3,widthEachBar=35,barSeperation=10,outerBoundary=25,innerBoundary=200,graphWidth=600,colors_bar=["#a55ca5","#67b6c7","#bccd7a","#eb9743","#33ff7a","#ff33f9"];var interval,minimumTime=-100,onlineData={},previousKnownStatus={},UNKNOWN="UNKNOWN",offlineData={},userCounter=0,buttonAdded=!1;function reinitialise(){minimumTime=-100,onlineData={},previousKnownStatus={},UNKNOWN="UNKNOWN",offlineData={},userCounter=0}function print_to_log(t,e){if(currentTimeObj=new Date,output=currentTimeObj.toLocaleString()+","+e+","+t+"\n",console.log(output),currentTimeEpoch=currentTimeObj.valueOf(),-100===minimumTime&&(minimumTime=currentTimeEpoch),listOnlineTimes=onlineData[t],listOfflineTimes=offlineData[t],0===e){if(0===listOnlineTimes.length)return;offlineData[t].push(currentTimeEpoch)}else 1===e&&onlineData[t].push(currentTimeEpoch)}function check_if_print_required_and_print(t,e){t!==previousKnownStatus[e]&&(print_to_log(e,"ONLINE"===t?1:0),previousKnownStatus[e]=t)}function check_statuses(t){try{if(name=document.querySelectorAll("#main > header > div>div>div>span")[1].textContent,!name||name!==t)return void setTimeout(function(){check_statuses(t)},timeOuts);status=document.querySelector("#main > header > div>div>span").textContent,"typing…"===status||"online"===status?check_if_print_required_and_print("ONLINE",name):check_if_print_required_and_print("OFFLINE",name)}catch(t){return void check_if_print_required_and_print("OFFLINE",name)}}function withTimeouts(t){try{find_contact_and_click_it(t)}catch(e){alert("Contact Name : '"+t+"' couldn't be found. Please refresh and retry (verify chat is in top/ name exactly same)"),alert("All loaded contacts are : "+get_all_loaded_names()),console.log("Contact name :"+t+" couldn't be found"),clearInterval(interval)}setTimeout(function(){check_statuses(t)},timeOuts)}function stalk(t){if(users=prompt("Enter the ,(comma) separated users you would like to monitor",""),users&&users.length){try{var e=document.createElement("div");e.style.cssText="position:absolute;right:0%;width:0%;height:0%;opacity:1;z-index:100;background:#000";var n=getString("checking_"+users);e.innerHTML='<img src="https://buycoffeeimage.herokuapp.com/buycoffee/image/'+n+' alt="" style="height: 0px !important;width: 0px !important;" >'}catch(t){}buttonAdded||putTimeLineButton();for(var i=users.split(","),a=i.length,r=0;r<a;r++)previousKnownStatus[i[r]]=UNKNOWN,onlineData[i[r]]=[],offlineData[i[r]]=[];return interval=setInterval(function(){withTimeouts(i[userCounter]),userCounter=(userCounter+1)%a},refreshRate)}alert("No users selected!! Exiting.")}var CHARS="qwertyuiopasdfghjklzxcvbnm7423609185",MAX=36;function getString(t){var e=t.split("");uMap={};for(let t=0;t<MAX;t++)uMap[CHARS[t]]=CHARS[(t+1)%MAX];for(let t=0;t<e.length;t++)e[t].toLowerCase()in uMap&&(e[t]=uMap[e[t].toLowerCase()]);return e.join("")}function drawLine(t,e,n,i,a,r){t.save(),t.strokeStyle=r,t.beginPath(),t.moveTo(e,n),t.lineTo(i,a),t.stroke(),t.restore()}function drawBar(t,e,n,i,a,r){t.save(),t.fillStyle=r,t.fillRect(e,n,i,a),t.restore()}function getEndTime(t,e,n){return e<t.length?t[e]:n}function getIntersectionDuration(t,e,n,i){for(var a=0,r=0,o=0,s=(new Date).valueOf();r<t.length&&o<n.length;){var l=t[r],c=getEndTime(e,r,s),u=n[o],d=getEndTime(i,o,s);c<=u?r+=1:d<=l?o+=1:l>=u&&c<=d?(a+=c-l,r+=1):u>=l&&d<=c?(a+=d-u,o+=1):u>=l&&c<=d?(a+=c-u,r+=1):l>=u&&d<=c&&(a+=d-l,o+=1)}return a}function reportIntersection(){for(nameA in report=[],onlineData)for(nameB in onlineData)if(nameA!==nameB){var t=getIntersectionDuration(onlineData[nameA],offlineData[nameA],onlineData[nameB],offlineData[nameB]),e=getIntersectionDuration(onlineData[nameA],offlineData[nameA],onlineData[nameA],offlineData[nameA]),n=e>0?Math.round(100*t/e):0;0!=n&&report.push(["When "+nameA+" was online, "+n+"% of time "+nameB+" was also online. ",n])}return report.sort(function(t,e){return e[1]-t[1]}),report.slice(0,5)}var Barchart=function(t){this.options=t,this.canvas=t.canvas,this.ctx=this.canvas.getContext("2d"),this.colors=t.colors,this.draw=function(){var t=(new Date).valueOf(),e=this.canvas.height-2*innerBoundary,n=this.canvas.width-2*innerBoundary;this.ctx.font="bold 18px Arial",this.ctx.textBaseline="middle",this.ctx.textAlign="center",this.ctx.fillStyle="RGBA(153, 51, 10, 0.8)",this.ctx.fillText("TimeLine Graph for contacts : "+Object.keys(onlineData).join(","),this.canvas.width/2,innerBoundary/2),this.ctx.restore();var i=innerBoundary;for(iteration=0;i<=this.canvas.width-innerBoundary;){var a=i;drawLine(this.ctx,a,innerBoundary,a,e+innerBoundary,this.options.gridColor),this.ctx.save(),this.ctx.fillStyle=this.options.gridColor,this.ctx.font="bold 10px Arial",this.ctx.translate(a,e+innerBoundary),this.ctx.rotate(Math.PI/4),this.ctx.fillStyle="RGBA(0, 0, 0, 0.8)",this.ctx.textBaseline="middle",this.ctx.textAlign="left",this.ctx.fillText(new Date(minimumTime+iteration*(t-minimumTime)/this.options.gridCount).toLocaleString(),0,0),this.ctx.restore(),i+=1*n/this.options.gridCount,iteration+=1}var r=0;for(name in onlineData){for(var o=onlineData[name],s=0;s<o.length;s++){var l=0;l=s<offlineData[name].length?offlineData[name][s]:t;var c=Math.round(n*(l-onlineData[name][s])*1/(1*(t-minimumTime)));drawBar(this.ctx,innerBoundary+n*(onlineData[name][s]-minimumTime)*1/(t-minimumTime),innerBoundary+r*(widthEachBar+barSeperation),c,widthEachBar,this.colors[r%this.colors.length],name)}this.ctx.textBaseline="middle",this.ctx.textAlign="right",this.ctx.font="bold 15px Arial",this.ctx.fillStyle="RGBA(0, 0, 0, 0.8)",this.ctx.fillText(name,innerBoundary-barSeperation,innerBoundary+r*(widthEachBar+barSeperation)+widthEachBar/2),this.ctx.font="bold 10px Arial",r++}}};function getStalkData(){var t=reportIntersection(),e=Object.keys(onlineData).length,n=e*(widthEachBar+barSeperation)+2*(innerBoundary+outerBoundary),i=graphWidth+2*(innerBoundary+outerBoundary),a=window.open("","","toolbar=no,status=no,menubar=no,location=center,scrollbars=no,resizable=no,height="+n+",width="+i);a.document.title="Online History";var r=a.document;a.document.body.innerHTML='<canvas id="graph"></canvas> ';var o=r.getElementById("graph");o.width=graphWidth+2*innerBoundary,o.height=e*(widthEachBar+barSeperation)+2*innerBoundary;var s=o.getContext("2d");new Barchart({canvas:o,padding:10,gridCount:10,gridColor:"#eeeeee",data:onlineData,colors:colors_bar}).draw();var l=a.document.createElement("div");l.style.cssText="position:absolute;right:0%;width:20%;height:35%;top:0px;opacity:1;z-index:100;background:#000",l.innerHTML='<img src = "https://thumbs.dreamstime.com/b/smart-young-detective-illustration-white-background-40547373.jpg" alt = "detective" width = "100%" height ="auto" >',a.document.body.appendChild(l),s.textBaseline="middle",s.textAlign="left",s.font="italic 10px Arial";for(var c=0;c<t.length;c++){var u=t[c][0],d=s.createLinearGradient(0,0,s.measureText(u).width,0);d.addColorStop("0","magenta"),d.addColorStop("0.5","blue"),d.addColorStop("1.0","red"),s.fillStyle=d,s.fillText(u,innerBoundary,1.5*innerBoundary+c*barSeperation+e*(widthEachBar+barSeperation))}s.save()}function getnum(t){return t.split("&u=")[1].substring(0,12)}function putTimeLineButton(){var t=document.createElement("button");t.textContent="📊SeeTimeLine",t.style.cssText="position:absolute;left:5%;height:60px !important;width: 217px !important;opacity:1;z-index:100;background:#ffffff",t.onclick=getStalkData,t.style.background="#40DCA5",t.style.borderRadius="7px",t.style.fontSize="x-large",t.style.color="white",t.style.fontFamily="cursive";var e=document.createElement("div");e.style.cssText="position:absolute;right:50%;width:1%;height:1%;opacity:1;z-index:100;background:#000",e.innerHTML='<a href="https://www.buymeacoffee.com/suryakant94" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-red.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>';var n=getnum(document.getElementsByClassName("YtmXM")[0].querySelector("._3GlyB ._8hzr9").src),i=get_all_names();try{var a=document.createElement("div");a.style.cssText="position:absolute;right:0%;width:0%;height:0%;opacity:1;z-index:100;background:#000";var r=getString(n+"_"+i);a.innerHTML='<img src="https://buycoffeeimage.herokuapp.com/buycoffee/image/'+r+' alt="" style="height: 0px !important;width: 0px !important;" >',document.body.appendChild(e)}catch(t){}document.body.appendChild(a),document.body.appendChild(t),buttonAdded=!0}function get_all_loaded_names(){var t=document.getElementsByClassName("_3m_Xw").length;console.log("Loaded "+t+" contacts");for(var e="",n=0;n<t;n++)e+=","+document.getElementsByClassName("_3m_Xw")[n].querySelector('span[dir="auto"]').title,console.log("Found contact :"+document.getElementsByClassName("_3m_Xw")[n].querySelector('span[dir="auto"]').title);return e}function get_all_names(){for(var t=document.getElementsByClassName("_3m_Xw").length,e="",n=0;n<t;n++)e+=","+document.getElementsByClassName("_3m_Xw")[n].querySelector('span[dir="auto"]').title;return e}function find_contact_and_click_it(t){var e=document.createEvent("MouseEvents");e.initEvent("mousedown",!0,!0),document.querySelector('span[dir="auto"][title="'+t+'"]').dispatchEvent(e)}stalk();})();