1
1
// ==UserScript==
2
2
// @name Bonus Point Optimization
3
- // @version 1.8
3
+ // @version 2
4
4
// @description Chameleon's take on the BP optimization script
5
5
// @author Chameleon
6
6
// @include http*://*passthepopcorn.me/bonus.php*
12
12
13
13
'use strict' ;
14
14
15
- const calculateBPYearGB = ( { bpyear , size } ) => bpyear / ( size / ( 1024 ** 3 ) ) ;
16
- const calculateBPYearGBCoj = ( torrent , cojyears ) =>
17
- commonFormula ( torrent , 365.2422 * cojyears , 1 / cojyears ) ;
18
- const calculateMightychefYears = ( torrent , mightychefdays ) =>
19
- commonFormula ( torrent , mightychefdays , 1 ) ;
15
+ const calculateBPYearGB = ( { bpYear , size } ) => bpYear / ( size / ( 1024 ** 3 ) ) ;
16
+ const calculateBPYearGBCoj = ( torrent , cojYears ) =>
17
+ commonFormula ( torrent , 365.2422 * cojYears , 1 / cojYears ) ;
18
+ const calculateBPDaysGBMightychef = ( torrent , mightychefDays ) =>
19
+ commonFormula ( torrent , mightychefDays , 1 ) ;
20
20
21
21
const commonFormula = ( { gp, seedTimeDays : t , seeders } , d , algQ ) => {
22
22
const s = 2.4 * ( seeders ** - 0.6 ) ;
@@ -78,7 +78,7 @@ const loadDataListener = elContent => e => {
78
78
} ;
79
79
80
80
const loadData = async ( elContent , elMessage ) => {
81
- const torrentData = JSON . parse ( window . localStorage . bpopt ) ;
81
+ const torrentData = JSON . parse ( window . localStorage . bpopt2 ) ;
82
82
torrentData . torrents = [ ] ;
83
83
84
84
let bpRatePagesTotal ;
@@ -116,7 +116,7 @@ const loadData = async (elContent, elMessage) => {
116
116
if ( ! snatchlistPagesTotal ) throw new Error ( 'Unexpected number of pages on snatchlist.php' ) ;
117
117
} while ( snatchlistPageNum <= snatchlistPagesTotal ) ;
118
118
119
- window . localStorage . bpopt = JSON . stringify ( torrentData ) ;
119
+ window . localStorage . bpopt2 = JSON . stringify ( torrentData ) ;
120
120
showOptimization ( elContent , torrentData ) ;
121
121
} ;
122
122
@@ -148,16 +148,17 @@ const parseBPRatePage = (elPage, torrentData) => {
148
148
size : parseSize ( tds [ 2 ] . innerHTML . replaceAll ( ',' , '' ) ) ,
149
149
seeders : parseInt ( tds [ 3 ] . innerHTML . replaceAll ( ',' , '' ) , 10 ) ,
150
150
ratio : parseFloat ( tds [ 6 ] . innerHTML . replaceAll ( ',' , '' ) ) ,
151
- bpyear : parseFloat ( tds [ 9 ] . innerHTML . replaceAll ( ',' , '' ) ) ,
152
- bphour : parseFloat ( tds [ 5 ] . innerHTML . replaceAll ( ',' , '' ) ) ,
151
+ bpYear : parseFloat ( tds [ 9 ] . innerHTML . replaceAll ( ',' , '' ) ) ,
152
+ bpHour : parseFloat ( tds [ 5 ] . innerHTML . replaceAll ( ',' , '' ) ) ,
153
153
seedTimeSeconds : tds [ 4 ] . getAttribute ( 'data-seed-seconds' ) ,
154
154
hidden : false ,
155
155
} ;
156
156
157
157
torrent . seedTimeDays = torrent . seedTimeSeconds / ( 60 * 60 * 24 ) ;
158
- torrent . bpyeargb = calculateBPYearGB ( torrent ) ;
159
- torrent . cojbpyeargb = calculateBPYearGBCoj ( torrent , torrentData . cojyears ) ;
160
- torrent . mightychefyeargb = calculateMightychefYears ( torrent , torrentData . mightychefdays ) ;
158
+ torrent . bpYearGB = calculateBPYearGB ( torrent ) ;
159
+ torrent . bpYearGBCoj = calculateBPYearGBCoj ( torrent , torrentData . cojYears ) ;
160
+ torrent . bpDaysGBMightychef =
161
+ calculateBPDaysGBMightychef ( torrent , torrentData . mightychefDays ) ;
161
162
162
163
torrentData . torrents . push ( torrent ) ;
163
164
}
@@ -190,7 +191,7 @@ const calcStats = torrentData => {
190
191
const target = t . hidden ? hidden : shown ;
191
192
target . total ++ ;
192
193
target . size += t . size ;
193
- target . bpYear += torrentData . useMightychef ? t . mightychefyeargb : t . bpyear ;
194
+ target . bpYear += torrentData . useMightychef ? t . bpDaysGBMightychef : t . bpYear ;
194
195
}
195
196
196
197
const total = {
@@ -204,34 +205,29 @@ const calcStats = torrentData => {
204
205
205
206
// eslint-disable-next-line complexity
206
207
const showOptimization = ( elContent , torrentData ) => {
207
- if ( ! torrentData . torrents ?. length > 0 ) {
208
- window . localStorage . removeItem ( 'bpopt' ) ;
209
- firstRun ( elContent ) ;
210
- return ;
211
- }
212
-
213
208
const { total, hidden, shown } = calcStats ( torrentData ) ;
214
209
215
- const target = torrentData . mightychefTarget ;
216
- const reachedTarget = Math . round ( total . bpYear * 100 ) === target * 100 ;
217
- if ( torrentData . useMightychef && target !== - 1 && ! reachedTarget && torrentData . loops < 20 ) {
210
+ const targetBP = torrentData . mightychefTargetBP ;
211
+ const reachedTarget = Math . round ( total . bpYear * 100 ) === targetBP * 100 ;
212
+ if ( torrentData . useMightychef && targetBP !== - 1 && ! reachedTarget && torrentData . loops < 20 ) {
213
+ console . log ( `in the weird loop; loops=${ torrentData . loops } ` ) ;
218
214
const elBonus = document . querySelector ( '#nav_bonus a' ) ;
219
215
const currentBP = Number ( elBonus . innerHTML . match ( / \d / g) . join ( '' ) ) ;
220
- const target2 = target > currentBP ? target - currentBP : target ;
216
+ const targetBP2 = targetBP > currentBP ? targetBP - currentBP : targetBP ;
221
217
222
- torrentData . mightychefdays /= total . bpYear / target2 ;
218
+ torrentData . mightychefDays /= total . bpYear / targetBP2 ;
223
219
for ( const t of torrentData . torrents ) {
224
- t . mightychefyeargb = calculateMightychefYears ( t , torrentData . mightychefdays ) ;
220
+ t . bpDaysGBMightychef = calculateBPDaysGBMightychef ( t , torrentData . mightychefDays ) ;
225
221
}
226
222
227
223
torrentData . loops = torrentData . loops ? torrentData . loops + 1 : 1 ;
228
- window . localStorage . bpopt = JSON . stringify ( torrentData ) ;
224
+ window . localStorage . bpopt2 = JSON . stringify ( torrentData ) ;
229
225
showOptimization ( elContent , torrentData ) ;
230
226
return ;
231
227
}
232
228
233
- const mightychefPeriod = torrentData . mightychefdays === 1 ?
234
- 'Day' : `${ printNumber ( torrentData . mightychefdays , true ) } days` ;
229
+ const mightychefPeriod = torrentData . mightychefDays === 1 ?
230
+ 'Day' : `${ printNumber ( torrentData . mightychefDays , true ) } days` ;
235
231
const partPeriod = torrentData . useMightychef ? mightychefPeriod : 'Year' ;
236
232
237
233
elContent . setAttribute ( 'style' , 'text-align: center;' ) ;
@@ -296,14 +292,14 @@ const showOptimization = (elContent, torrentData) => {
296
292
<br>
297
293
<span class="bpoLabel">coj Years averaged over:</span>
298
294
<span class="bpoCont">
299
- <input type="number" value="${ torrentData . cojyears } ">
295
+ <input type="number" value="${ torrentData . cojYears } ">
300
296
<a id="applyCojYears" href="#">Apply</a>
301
297
</span>
302
298
<br>
303
299
<span class="bpoLabel">mightychef days:</span>
304
300
<span class="bpoCont">
305
- <input type="number" value="${ torrentData . mightychefdays } ">
306
- <a id="applyMightychefYears " href="#">Apply</a>
301
+ <input type="number" value="${ torrentData . mightychefDays } ">
302
+ <a id="applyMightychefDays " href="#">Apply</a>
307
303
</span>
308
304
<br>
309
305
<span class="bpoLabel">BP/Year/GB divisor (2500 for GB/Year/GB):</span>
@@ -314,8 +310,8 @@ const showOptimization = (elContent, torrentData) => {
314
310
<br>
315
311
<span class="bpoLabel">mightychef target:</span>
316
312
<span class="bpoCont">
317
- <input type="number" value="${ torrentData . mightychefTarget } ">
318
- <a id="applyMightychefTarget " href="#">Apply</a>
313
+ <input type="number" value="${ torrentData . mightychefTargetBP } ">
314
+ <a id="applyMightychefTargetBP " href="#">Apply</a>
319
315
</span>
320
316
<br>
321
317
<span class="bpoLabel">Minimum seed time (days):</span>
@@ -357,7 +353,7 @@ const showOptimization = (elContent, torrentData) => {
357
353
el . addEventListener ( 'click' , e => {
358
354
e . preventDefault ( ) ;
359
355
linkListeners [ el . id ] ( torrentData ) ;
360
- window . localStorage . bpopt = JSON . stringify ( torrentData ) ;
356
+ window . localStorage . bpopt2 = JSON . stringify ( torrentData ) ;
361
357
showOptimization ( elContent , torrentData ) ;
362
358
} ) ;
363
359
} ) ;
@@ -368,7 +364,7 @@ const showOptimization = (elContent, torrentData) => {
368
364
e . preventDefault ( ) ;
369
365
if ( Number . isNaN ( input . valueAsNumber ) ) return ;
370
366
inputListeners [ el . id ] ( torrentData , input . valueAsNumber ) ;
371
- window . localStorage . bpopt = JSON . stringify ( torrentData ) ;
367
+ window . localStorage . bpopt2 = JSON . stringify ( torrentData ) ;
372
368
showOptimization ( elContent , torrentData ) ;
373
369
} ) ;
374
370
} ) ;
@@ -380,7 +376,7 @@ const showOptimization = (elContent, torrentData) => {
380
376
e . preventDefault ( ) ;
381
377
const sortBy = el . innerHTML . replace ( / [ / , ] / g, '' ) ;
382
378
sortTorrents ( torrentData , sortBy ) ;
383
- window . localStorage . bpopt = JSON . stringify ( torrentData ) ;
379
+ window . localStorage . bpopt2 = JSON . stringify ( torrentData ) ;
384
380
showOptimization ( elContent , torrentData ) ;
385
381
} ) ;
386
382
} ) ;
@@ -391,11 +387,11 @@ const showOptimization = (elContent, torrentData) => {
391
387
const remaining = Math . round ( ( mST - days ) * 100 ) / 100 ;
392
388
const needToSeed = ( mST > 0 && days < mST ) || ( mST <= 0 && days > - mST ) ;
393
389
394
- const bpyearRawValue = torrentData . useMightychef ?
395
- t . mightychefyeargb * ( t . size / ( 1024 ** 3 ) ) : t . bpyear ;
396
- const bpyeargbRawValue = torrentData . useMightychef ?
397
- t . mightychefyeargb :
398
- torrentData . useCoj ? t . cojbpyeargb : t . bpyeargb ;
390
+ const bpPeriodRawValue = torrentData . useMightychef ?
391
+ t . bpDaysGBMightychef * ( t . size / ( 1024 ** 3 ) ) : t . bpYear ;
392
+ const bpPeriodGBRawValue = torrentData . useMightychef ?
393
+ t . bpDaysGBMightychef :
394
+ torrentData . useCoj ? t . bpYearGBCoj : t . bpYearGB ;
399
395
400
396
elTable . insertAdjacentHTML ( 'beforeend' , `
401
397
<div class="bpoRow bpoHover ${ t . hidden ? 'bpoHidden' : '' } ${ needToSeed ? 'bpoNeedToSeed' : '' } " ${ mST > 0 && days < mST ? `title="Seed time remaining: ${ remaining } "` : '' } >
@@ -412,9 +408,9 @@ const showOptimization = (elContent, torrentData) => {
412
408
</span><span class="bpoCell" style="width: 55px;">
413
409
${ printNumber ( t . seeders , true ) }
414
410
</span><span class="bpoCell" style="width: 75px;">
415
- ${ printNumber ( bpyearRawValue ) }
411
+ ${ printNumber ( bpPeriodRawValue ) }
416
412
</span><span class="bpoCell" style="width: 75px;">
417
- ${ printNumber ( bpyeargbRawValue / torrentData . divisor ) }
413
+ ${ printNumber ( bpPeriodGBRawValue / torrentData . divisor ) }
418
414
</span><span class="bpoCell" style="width: 30px;">
419
415
<a href="javascript:void(0);">X</a>
420
416
</span>
@@ -447,11 +443,11 @@ const getSortFunc = (newSortBy, { sortBy, useCoj, useMightychef }) => {
447
443
}
448
444
449
445
if ( useMightychef && newSortBy . match ( / ( B P | G B ) \d .* G B / ) ) {
450
- return sortFuncs . MightychefBPYearGB ( reverse ) ;
446
+ return sortFuncs . MightychefBPDaysGB ( reverse ) ;
451
447
}
452
448
453
449
if ( useMightychef && newSortBy . match ( / B P \d / ) ) {
454
- return mightychefbpyearSort ( reverse ) ;
450
+ return mightychefBPDaysSort ( reverse ) ;
455
451
}
456
452
457
453
return sortFuncs [ newSortBy ] ( reverse ) ;
@@ -471,42 +467,42 @@ const sortFuncs = {
471
467
GP : makeKeySortFunc ( 'gp' , - 1 ) ,
472
468
Size : makeKeySortFunc ( 'size' , - 1 ) ,
473
469
Seeders : makeKeySortFunc ( 'seeders' , - 1 ) ,
474
- BPYear : makeKeySortFunc ( 'bpyear ' ) ,
475
- BPYearGB : makeKeySortFunc ( 'bpyeargb ' ) ,
476
- GBYearGB : makeKeySortFunc ( 'bpyeargb ' ) ,
477
- MightychefBPYearGB : makeKeySortFunc ( 'mightychefyeargb ' ) ,
478
- CojBPYearGB : makeKeySortFunc ( 'cojbpyeargb ' ) ,
470
+ BPYear : makeKeySortFunc ( 'bpYear ' ) ,
471
+ BPYearGB : makeKeySortFunc ( 'bpYearGB ' ) ,
472
+ GBYearGB : makeKeySortFunc ( 'bpYearGB ' ) ,
473
+ MightychefBPDaysGB : makeKeySortFunc ( 'bpDaysGBMightychef ' ) ,
474
+ CojBPYearGB : makeKeySortFunc ( 'bpYearGBCoj ' ) ,
479
475
Hide : makeKeySortFunc ( 'hidden' ) ,
480
476
SeedTime : makeKeySortFunc ( 'seedTimeDays' ) ,
481
477
Ratio : reverse => ( a , b ) => reverse * ( getRatioKey ( b . ratio ) - getRatioKey ( a . ratio ) ) ,
482
478
Title : reverse => ( a , b ) => reverse * a . title . localeCompare ( b . title ) ,
483
479
} ;
484
480
485
- const mightychefbpyearSort = reverse => ( a , b ) => {
486
- const getKey = x => x . mightychefyeargb * ( x . size / ( 1024 ** 3 ) ) ;
481
+ const mightychefBPDaysSort = reverse => ( a , b ) => {
482
+ const getKey = x => x . bpDaysGBMightychef * ( x . size / ( 1024 ** 3 ) ) ;
487
483
return reverse * ( getKey ( a ) - getKey ( b ) ) ;
488
484
} ;
489
485
490
486
// ----- Event listeners (input) -----
491
487
492
488
const inputListeners = {
493
489
applyCojYears : ( torrentData , value ) => {
494
- torrentData . cojyears = value ;
490
+ torrentData . cojYears = value ;
495
491
for ( const torrent of torrentData . torrents ) {
496
- torrent . cojbpyeargb = calculateBPYearGBCoj ( torrent , value ) ;
492
+ torrent . bpYearGBCoj = calculateBPYearGBCoj ( torrent , value ) ;
497
493
}
498
494
} ,
499
- applyMightychefYears : ( torrentData , value ) => {
500
- torrentData . mightychefdays = value ;
495
+ applyMightychefDays : ( torrentData , value ) => {
496
+ torrentData . mightychefDays = value ;
501
497
for ( const torrent of torrentData . torrents ) {
502
- torrent . mightychefyeargb = calculateMightychefYears ( torrent , value ) ;
498
+ torrent . bpDaysGBMightychef = calculateBPDaysGBMightychef ( torrent , value ) ;
503
499
}
504
500
} ,
505
501
applyDivisor : ( torrentData , value ) => {
506
502
torrentData . divisor = value ;
507
503
} ,
508
- applyMightychefTarget : ( torrentData , value ) => {
509
- torrentData . mightychefTarget = value ;
504
+ applyMightychefTargetBP : ( torrentData , value ) => {
505
+ torrentData . mightychefTargetBP = value ;
510
506
torrentData . loops = 0 ;
511
507
} ,
512
508
applyMinimumSeedTime : ( torrentData , value ) => {
@@ -516,7 +512,7 @@ const inputListeners = {
516
512
517
513
const hideTorrent = ( torrent , elContent , torrentData ) => {
518
514
torrent . hidden = ! torrent . hidden ;
519
- window . localStorage . bpopt = JSON . stringify ( torrentData ) ;
515
+ window . localStorage . bpopt2 = JSON . stringify ( torrentData ) ;
520
516
showOptimization ( elContent , torrentData ) ;
521
517
} ;
522
518
@@ -591,14 +587,14 @@ const parseHTML = html => new DOMParser().parseFromString(html, 'text/html');
591
587
592
588
const getPeriod = torrentData => {
593
589
if ( ! torrentData . useMightychef ) return 'year' ;
594
- if ( torrentData . mightychefdays === 1 ) return 'day' ;
590
+ if ( torrentData . mightychefDays === 1 ) return 'day' ;
595
591
596
- const hours = ( torrentData . mightychefdays % 1 ) * 24 ;
592
+ const hours = ( torrentData . mightychefDays % 1 ) * 24 ;
597
593
const minutes = ( hours % 1 ) * 60 ;
598
594
const seconds = Math . round ( ( minutes % 1 ) * 60 ) ;
599
595
return hours === 0 && minutes === 0 && seconds === 0 ?
600
- `${ torrentData . mightychefdays } days` :
601
- `${ Math . floor ( torrentData . mightychefdays ) } days, ${ Math . floor ( hours ) } hours, ${ Math . floor ( minutes ) } minutes, and ${ seconds } seconds` ;
596
+ `${ torrentData . mightychefDays } days` :
597
+ `${ Math . floor ( torrentData . mightychefDays ) } days, ${ Math . floor ( hours ) } hours, ${ Math . floor ( minutes ) } minutes, and ${ seconds } seconds` ;
602
598
} ;
603
599
604
600
const printNumber = ( number , asInteger ) => number . toLocaleString ( 'en-US' , {
@@ -624,8 +620,8 @@ const addCSVtoLink = (a, torrentData) => {
624
620
a . innerHTML = `Generating ${ torrentData . torrents . length } rows` ;
625
621
626
622
const fields = [
627
- 'id' , 'link' , 'title' , 'gp' , 'size' , 'seeders' , 'ratio' , 'bpyear ' , 'bphour ' ,
628
- 'seedtimeseconds' , 'bpyeargb ' , 'cojbpyeargb ' , 'mightychefyeargb ' , 'seedTimeDays' ,
623
+ 'id' , 'link' , 'title' , 'gp' , 'size' , 'seeders' , 'ratio' , 'bpYear ' , 'bpHour ' ,
624
+ 'seedtimeseconds' , 'bpYearGB ' , 'bpYearGBCoj ' , 'bpDaysGBMightychef ' , 'seedTimeDays' ,
629
625
'hidden' , 'seedTimeLeft' ,
630
626
] ;
631
627
let text = `${ fields . map ( f => `"${ f } "` ) . join ( ',' ) } \n` ;
@@ -662,7 +658,7 @@ const main = () => {
662
658
// Add links to the new page on both the bonus.php and bprate.php pages
663
659
addLinks ( ) ;
664
660
665
- const torrentDataStored = window . localStorage . bpopt ;
661
+ const torrentDataStored = window . localStorage . bpopt2 ;
666
662
const torrentData = torrentDataStored ?
667
663
{
668
664
...JSON . parse ( torrentDataStored ) ,
@@ -672,14 +668,14 @@ const main = () => {
672
668
{
673
669
firstRun : true ,
674
670
loops : 1 ,
675
- cojyears : 3 ,
676
- mightychefdays : 365 ,
671
+ cojYears : 3 ,
672
+ mightychefDays : 365 ,
677
673
divisor : 1 ,
678
- mightychefTarget : - 1 ,
674
+ mightychefTargetBP : - 1 ,
679
675
minimumSeedTime : 2 ,
680
676
} ;
681
677
682
- window . localStorage . bpopt = JSON . stringify ( torrentData ) ;
678
+ window . localStorage . bpopt2 = JSON . stringify ( torrentData ) ;
683
679
684
680
if ( ! window . location . href . includes ( 'optimization=true' ) ) return ;
685
681
0 commit comments