Skip to content

Instantly share code, notes, and snippets.

@py-ranoid
Created November 13, 2020 15:43
Show Gist options
  • Save py-ranoid/2878e90709d796ba8ba2254ae0a4637d to your computer and use it in GitHub Desktop.
Save py-ranoid/2878e90709d796ba8ba2254ae0a4637d to your computer and use it in GitHub Desktop.
Upstox P/L Notifier
// ==UserScript==
// @name Upstox Notifier
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://pro.upstox.com/trading
// @grant none
// ==/UserScript==
document.addEventListener('DOMContentLoaded', function() {
if (!Notification) {
alert('Desktop notifications not available in your browser. Try Chromium.');
return;
}
if (Notification.permission !== 'granted'){Notification.requestPermission()};
});
function notifyMe(title, message) {
if (Notification.permission !== 'granted'){
Notification.requestPermission();
}
else {
var notification = new Notification(title, {
icon: 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxMTEhUSExIVFhUXFhUVFhYVFxUVFxUWFRIWFhUVFRUYHSggGBolGxUVITEhJSkrLi4uFx8zODMtNygtLisBCgoKDg0OGhAQGCsdHR0rLS0rLS0rKystLS0tLS0tLSstLSstLS0tLS0tNzcrLSstLS0tKy0tKystLSsrLSsrLf/AABEIAOEA4QMBIgACEQEDEQH/xAAbAAABBQEBAAAAAAAAAAAAAAAFAAIDBAYHAf/EAEIQAAEDAgMFBQQHBgUFAQAAAAEAAgMEEQUhMQYSQVFhEyJxgZEyobHBBxQjQlJi0RUkM3KC8FOSorLhNENzg9IW/8QAGQEAAwEBAQAAAAAAAAAAAAAAAAECAwQF/8QAIxEAAgICAQUBAQEBAAAAAAAAAAECEQMhEgQTMUFRImEyQv/aAAwDAQACEQMRAD8AwGyYu4joEzGGWmcPA/6QpNl4iJbHiPgVPtNHab+kfBXFbMp+DKz+0tHs4zMLPTM7yPYG4gt65IkC8F/aGDMeBUeAxXkHQKxtG72fAqTZtntO5BN+BeyDFDd7+lh6Be4Az7TyXlt4uPMn4qfB22mCF4H7IsebaU+AVOjHeRHaYW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I9k5eB9leRLhlpnrY/0rHNIVpltbKs9q0Wymz7pyJH3ETf9ZHLos1FyZU5qCLOyWy/bPFRKO403Yw/etxPRdCk3RbLTl81FG4NG63K2g4AJRSXK7scOKPJy5ObCLgLC3JV56ljR3ntHiQg+1G8YmWJbYkGxIuCFlBFnn71ZKibuOtY+5ad63JC6zHDmGtt1Jv7l5gLe47zQ6pbZxQFF7A5O8jcxWcwp1nrQPOSQmRkp8QUbnJsk1hlxQIsSzcAmvfZjifwuP8ApKrRFOr37sUh5Md/tKmQ4+TkH1s8mrxDO0KS5jejbt7rs8lbqBcXQ589xZwv8fVQfXAzibcjmu5mQSoRlZT1E/3B5ofSVXdL7a6JlLLck80AkGGPUjXKpG5TtKaJaJg5PJUTU4lMBykjaorqxTpMRG2PNPhkLHbw04jorLIE2SnKkd2Zvb6kF46hujrsd46i/wAFku0sujYth5mp5IuNt5mX325tHnmEN2W2SLbS1Auct1h4ci79FzZIcpHbhzqMaZW2Y2ZMlpJhaPUN4v8AHkFvomgANaLAZABMB4KGrr2R+04eGpPktYQUUc2TK5st7uRVOOrDSbmwCDVmPSP7sY3RpfVx8eSsU9PaPPUnMlUZ8aJa2vMvdHs3vn0VGentmrtPGLqxURgsKYCwQ5FDq494q1hb7FUcSd3ygCXDT3kfe/JZvDDn5o5I/JDGe7ygL7m6gnlv3R5qRpUhRZhdmq+1c25STHmwt/zZfNT04zWZ+lGu3adsYOb3j0br8lMvA4LZzS6Sh3ncklhR0UbWRUqzQeK8SXazAIP0/pCbS6pJJDQSjVliSSpEsnak5eJJiQ5uiswJJJMTCdNonVCSSklD4ND/AH90qw7h4H4JJKP+gfgrnTyWMqP4rkkk/RovJaofmj7/AGAkkgciOJWH+wUkkEA+j9oqniPtFJJMCXC9fNFpfmkkhjRRj9pytRJJKRlyl181z/6X/ag/9nwYkklLwEf9GFSSSWB0H//Z',
body: message,
});
notification.onclick = function() {
window.open('https://pro.upstox.com/trading');
};
}
};
function getVals(){
var curr_arr = Array.prototype.slice.call(document.getElementsByClassName("_currentValueCellHoldings_410df"));
curr_arr.forEach(function(item, index, array){curr_arr[index] = parseFloat(item.textContent.replace(/,/g, ''));});
var pl_arr = Array.prototype.slice.call(document.getElementsByClassName("_dailyPnLCellHoldings_410df"))
pl_arr.forEach(function(item, index, array){pl_arr[index] = parseFloat(item.textContent.replace(/,/g, ''));});
var today_pl = pl_arr.reduce(function(a, b){return a + b;}, 0);
var overall_pl = parseFloat(document.getElementsByClassName('_tablePnl_ee8f1')[1].getElementsByTagName('span')[0].textContent.replace(/,/g, ''))
var today_val = curr_arr.reduce(function(a, b){return a + b;}, 0);
var nifty = document.getElementsByClassName('_ltpChange_8bb7a')[0].textContent.replace(/ /g, '')
var overall_pl_perc = Math.round(10000*overall_pl/(today_val-overall_pl))/100
var today_pl_perc = Math.round(10000*today_pl/(today_val-overall_pl))/100
var title = "P/L : "+today_pl+" ("+today_pl_perc+"%/"+nifty+")"
var message = '\nOverall : '+ overall_pl +" ("+overall_pl_perc+"%)"
return [title, message]
}
function reloader(){location.reload();}
function repeat(){
var message = getVals();
notifyMe(message[0],message[1]);
}
var i = setInterval(repeat,60*1000);
var j = setInterval(reloader,300*1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment