@ -21,14 +21,14 @@ function redirect(url, new_tab) {
}
function numberFormat ( nStr ) {
// Thx to http://www.mredkj.com/javascript/numberFormat.html
// http://www.mredkj.com/javascript/numberFormat.html
nStr += '' ;
var x = nStr . split ( '.' ) ;
var x1 = x [ 0 ] ;
var x2 = x . length > 1 ? '.' + x [ 1 ] : '' ;
var rgx = /(\d+)(\d{3})/ ;
var x = nStr . split ( '.' ) ,
x1 = x [ 0 ] ,
x2 = x . length > 1 ? '.' + x [ 1 ] : '' ,
rgx = /(\d+)(\d{3})/ ;
while ( rgx . test ( x1 ) ) {
x1 = x1 . replace ( rgx , '$1' + " " + '$2' ) ;
x1 = x1 . replace ( rgx , '$1' + ' ' + '$2' ) ;
}
return x1 + x2 ;
}
@ -42,7 +42,7 @@ function incUnreadsFeed(article, feed_id, nb) {
//Update unread: feed
var elem = $ ( '#' + feed _id + '>.feed' ) . get ( 0 ) ,
feed _unreads = elem ? ( parseInt ( elem . getAttribute ( 'data-unread' ) . replace ( ' ' , '' ) , 10 ) || 0 ) : 0 ,
feed _unreads = elem ? ( parseInt ( elem . getAttribute ( 'data-unread' ) . replace ( ' ' , '' ) , 10 ) || 0 ) : 0 ,
feed _priority = elem ? ( parseInt ( elem . getAttribute ( 'data-priority' ) , 10 ) || 0 ) : 0 ;
if ( elem ) {
elem . setAttribute ( 'data-unread' , numberFormat ( Math . max ( 0 , feed _unreads + nb ) ) ) ;
@ -50,7 +50,7 @@ function incUnreadsFeed(article, feed_id, nb) {
//Update unread: category
elem = $ ( '#' + feed _id ) . parent ( ) . prevAll ( '.category' ) . children ( ':first' ) . get ( 0 ) ;
feed _unreads = elem ? ( parseInt ( elem . getAttribute ( 'data-unread' ) . replace ( ' ' , '' ) , 10 ) || 0 ) : 0 ;
feed _unreads = elem ? ( parseInt ( elem . getAttribute ( 'data-unread' ) . replace ( ' ' , '' ) , 10 ) || 0 ) : 0 ;
if ( elem ) {
elem . setAttribute ( 'data-unread' , numberFormat ( Math . max ( 0 , feed _unreads + nb ) ) ) ;
}
@ -59,7 +59,7 @@ function incUnreadsFeed(article, feed_id, nb) {
if ( feed _priority > 0 ) {
elem = $ ( '#aside_flux .all' ) . children ( ':first' ) . get ( 0 ) ;
if ( elem ) {
feed _unreads = elem ? ( parseInt ( elem . getAttribute ( 'data-unread' ) . replace ( ' ' , '' ) , 10 ) || 0 ) : 0 ;
feed _unreads = elem ? ( parseInt ( elem . getAttribute ( 'data-unread' ) . replace ( ' ' , '' ) , 10 ) || 0 ) : 0 ;
elem . setAttribute ( 'data-unread' , numberFormat ( Math . max ( 0 , feed _unreads + nb ) ) ) ;
}
}
@ -68,22 +68,28 @@ function incUnreadsFeed(article, feed_id, nb) {
if ( article && article . closest ( 'div' ) . hasClass ( 'favorite' ) ) {
elem = $ ( '#aside_flux .favorites' ) . children ( ':first' ) . get ( 0 ) ;
if ( elem ) {
feed _unreads = elem ? ( parseInt ( elem . getAttribute ( 'data-unread' ) . replace ( ' ' , '' ) , 10 ) || 0 ) : 0 ;
feed _unreads = elem ? ( parseInt ( elem . getAttribute ( 'data-unread' ) . replace ( ' ' , '' ) , 10 ) || 0 ) : 0 ;
elem . setAttribute ( 'data-unread' , numberFormat ( Math . max ( 0 , feed _unreads + nb ) ) ) ;
}
}
var isCurrentView = false ;
//Update unread: title
document . title = document . title . replace ( /((?: \(\d+\))?)( · .*?)((?: \(\d +\))?)$/ , function ( m , p1 , p2 , p3 ) {
document . title = document . title . replace ( /^([^\(]*)((?: \([0-9 ]+\))?)( · .*?)((?: \([0-9 ] +\))?)$/ , function ( m , p1 , p2 , p3 , p4 ) {
var $feed = $ ( '#' + feed _id ) ;
if ( article || ( $feed . closest ( '.active' ) . length > 0 && $feed . siblings ( '.active' ) . length === 0 ) ) {
p2 = p2 . replace ( / /g , '' ) ;
p4 = p4 . replace ( / /g , '' ) ;
if ( $ ( '.category.all > .active' ) . length == 0 && $ ( '.category.favorites > .active' ) . length == 0 ) { // If the current page is not the home page or the favorites page
isCurrentView = true ;
return incLabel ( p1 , nb ) + p2 + incLabel ( p3 , feed _priority > 0 ? nb : 0 ) ;
return p1 + incLabel ( p2 , nb ) + p3 + incLabel ( p4 , feed _priority > 0 ? nb : 0 ) ;
} else {
return p1 + p2 + incLabel ( p3 , feed _priority > 0 ? nb : 0 ) ;
return p1 + p3 + incLabel ( p4 , feed _priority > 0 ? nb : 0 ) ;
}
} ) ;
return isCurrentView ;
}
@ -157,7 +163,7 @@ function mark_favorite(active) {
if ( active . closest ( 'div' ) . hasClass ( 'not_read' ) ) {
var elem = $ ( '#aside_flux .favorites' ) . children ( ':first' ) . get ( 0 ) ,
feed _unreads = elem ? ( parseInt ( elem . getAttribute ( 'data-unread' ) . replace ( ' ' , '' ) , 10 ) || 0 ) : 0 ;
feed _unreads = elem ? ( parseInt ( elem . getAttribute ( 'data-unread' ) . replace ( ' ' , '' ) , 10 ) || 0 ) : 0 ;
if ( elem ) {
elem . setAttribute ( 'data-unread' , numberFormat ( Math . max ( 0 , feed _unreads + inc ) ) ) ;
}
@ -544,7 +550,7 @@ function refreshUnreads() {
$ . each ( data , function ( feed _id , nbUnreads ) {
feed _id = 'f_' + feed _id ;
var elem = $ ( '#' + feed _id + '>.feed' ) . get ( 0 ) ,
feed _unreads = elem ? ( parseInt ( elem . getAttribute ( 'data-unread' ) . replace ( ' ' , '' ) , 10 ) || 0 ) : 0 ;
feed _unreads = elem ? ( parseInt ( elem . getAttribute ( 'data-unread' ) . replace ( ' ' , '' ) , 10 ) || 0 ) : 0 ;
if ( ( incUnreadsFeed ( null , feed _id , nbUnreads - feed _unreads ) || isAll ) && //Update of current view?
( nbUnreads - feed _unreads > 0 ) ) {
$ ( '#new-article' ) . show ( ) ;
@ -649,9 +655,9 @@ function init_loginForm() {
c = dcodeIO . bcrypt . hashSync ( data . nonce + s , strong ? 4 : poormanSalt ( ) ) ;
$ ( '#challenge' ) . val ( c ) ;
if ( s == '' || c == '' ) {
alert ( 'Crypto error!' ) ;
alert ( 'Crypto error!' ) ;
} else {
success = true ;
success = true ;
}
} catch ( e ) {
alert ( 'Crypto exception! ' + e ) ;
@ -755,34 +761,6 @@ function init_print_action() {
} ) ;
}
function init _number _formats ( ) {
// Init global counter
var elem = $ ( '#aside_flux .categories li .all a' ) ;
elem . attr ( 'data-unread' , numberFormat ( elem . attr ( 'data-unread' ) ) ) ;
// Init favorites counters
elem = $ ( '#aside_flux .categories li .favorites a' ) ;
elem . attr ( 'data-unread' , numberFormat ( elem . attr ( 'data-unread' ) ) ) ;
var numFavorites = elem . text ( ) . replace ( /((?: \(\d+\))?\s*)$/ , function ( m , p1 ) {
return numberFormat ( p1 )
} ) ;
elem . text ( numFavorites ) ;
// Init feeds counters
$ ( '#aside_flux .categories li .stick' ) . each ( function ( ) {
// Category-level counter
elem = $ ( this ) . find ( 'a' ) ;
elem . attr ( 'data-unread' , numberFormat ( elem . attr ( 'data-unread' ) ) ) ;
// Feeds counters
$ ( this ) . parent ( ) . find ( 'ul.feeds li.item' ) . each ( function ( ) {
elem = $ ( this ) . find ( 'a.feed' ) ; // There are two links here. a.feed is the title.
elem . attr ( 'data-unread' , numberFormat ( elem . attr ( 'data-unread' ) ) ) ;
} ) ;
} ) ;
}
function init _all ( ) {
if ( ! ( window . $ && window . url _freshrss && ( ( ! full _lazyload ) || $ . fn . lazyload ) ) ) {
if ( window . console ) {
@ -813,7 +791,7 @@ function init_all() {
init _print _action ( ) ;
window . setInterval ( refreshUnreads , 120000 ) ;
}
init _number _formats ( ) ;
if ( window . console ) {
console . log ( 'FreshRSS init done.' ) ;
}