Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
metager-webextension
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open-source
metager-webextension
Commits
79644864
Commit
79644864
authored
1 year ago
by
Phil Höfer
Browse files
Options
Downloads
Patches
Plain Diff
update refillTokenStash function
parent
bc1e09fd
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
background.js
+12
-6
12 additions, 6 deletions
background.js
with
12 additions
and
6 deletions
background.js
+
12
−
6
View file @
79644864
...
...
@@ -45,8 +45,13 @@ function updateStorageFromCookies() {sites.forEach((site) => {
// TODO: Collect token if unused
function
refillTokenStash
(
count
)
{
// get count (max 10) tokens and store them in the stash
//console.log("refilling tokens");
/**
* Get count (max 10) tokens and store them in the stash
* @param {number} count
* @returns {boolean} True if successfull, false otherwise.
*/
function
refillTokenStash
(
count
)
{
// TODO: handle count >10
console
.
log
(
"
refilling tokens
"
);
let
tokensToBlind
=
[];
for
(
let
i
=
0
;
i
<=
Math
.
min
(
count
,
9
);
i
++
)
{
tokensToBlind
.
push
(
uuidv4
());
...
...
@@ -131,7 +136,7 @@ async function getTokensPerSearch() {
* Returns the refill threshold size based on the currently saved tokensPerSearch value
* @returns {number}
*/
async
function
getRefillThresholdSize
()
{
function
getRefillThresholdSize
()
{
return
getTokensPerSearch
().
then
((
x
)
=>
x
*
3
);
}
...
...
@@ -139,7 +144,7 @@ async function getRefillThresholdSize() {
* Returns the target stash size based on the currently saved tokensPerSearch value
* @returns {number}
*/
async
function
getTargetStashSize
()
{
function
getTargetStashSize
()
{
return
getTokensPerSearch
().
then
((
x
)
=>
x
*
7
);
}
...
...
@@ -162,11 +167,12 @@ async function checkTokenStash() {
console
.
log
(
activeKey
);
let
refillThresholdSize
=
getRefillThresholdSize
();
let
targetStashSize
=
getTargetStashSize
();
console
.
log
(
refillThresholdSize
);
if
(
currentStash
>
refillThresholdSize
)
{
return
true
;
}
else
if
(
activeKey
)
{
return
await
refillTokenStash
(
targetStashSize
-
currentStash
.
length
);
}
else
{
return
refillTokenStash
(
targetStashSize
-
currentStash
.
length
)
;
return
false
;
}
}
setTimeout
(
checkTokenStash
,
10000
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment