Skip to content

Instantly share code, notes, and snippets.

@sergiks
Created February 8, 2017 08:44
Show Gist options
  • Select an option

  • Save sergiks/d47c4810faecb36691aed3ed47c76cd5 to your computer and use it in GitHub Desktop.

Select an option

Save sergiks/d47c4810faecb36691aed3ed47c76cd5 to your computer and use it in GitHub Desktop.
Букмарклет для подсчёта выплат за месяц на AppsCentrum (несжатый код)
/**
* Bookmarklet for my.appscentrum.com
* to display agregated payouts by month
* for the last 3 months.
*
* Minify with command:
*
* uglifyjs -m -c negate-iife=false apps-centrum-sum.js
*
* by Sergei Sokolov [email protected]
* Moscow, February 2017.
*/
(function(n){
var tbl = $('table')
,sums = {}
,d = new Date
,m
,y
,i
,out = ''
;
// are we on a relevant page?
if( window.location.hostname != 'my.appscentrum.com' || tbl.length < 4) return;
// get dates
d.setDate(1);
for(i=0; i<n; i++) {
m = ('0' + (parseInt(d.getMonth())+1)).substr(-2)
y = '' + d.getFullYear()
sums[''+m+'.'+y] = 0;
d.setMonth(d.getMonth() - 1);
}
tbl = tbl[3];
$('tr',tbl).each( function(i,tr) {
var s, key, dt = $('td:nth-child(5)', this).text().split(/[\ \.]/);
if( dt.length >= 2) {
key = '' + dt[1] + '.' + dt[2];
if( sums.hasOwnProperty(key)) {
s = $('td:nth-child(3)', this).text();
if( (s = s.replace( /[^0-9\.]+/g, '')).length) {
sums[key] += parseFloat(s);
}
}
}
});
for(key in sums) {
out += '' + Math.round(100*sums[key])/100 + ' руб. за ' + key + "\r\n";
}
alert( out);
return void(0);
})(5)
@sergiks
Copy link
Copy Markdown
Author

sergiks commented Feb 8, 2017

Минифицированная версия тут.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment