Greasy Fork is available in English.

Discussioni » Sviluppo

Erase Tampermonkey storage once a month

§
Pubblicato: 19/06/2021
Modificato: 19/06/2021

This is what I've tried so far, I've tried to make and store the actual date and compare it to 30 days after the last date, but is there a better way to do this?
In the end comparing the day number of today with 30 days ahead is the same as doing today_number === 30_days_ahead, but I would like the script to know if it's + than 30 days ahead, like not always the user will open the same website on the exact same day in 30 days ahead, maybe he will open the website on 35 days ahead, how could I know that?

Also, is there a better way to erase the whole tampermonkey storage programatically?


if (GM_getValue('Date') === undefined) //If the date wasn't yet stored on tampermonkey
{ //Starts the if condition
GM_setValue('Date', new Date().getDate()); //Get and save the day of today as a number
} //Finishes the if condition

if (new Date().getDate() >= new Date(new Date().setDate(GM_getValue('Date') + 30)).getDate()) //If the day number stored on tampermonkey is from 30 or more days ago
{ //Starts the if condition
GM_listValues().forEach(function(a) {
if (a !== GM_getValue('Date')) //If the current looped element isn't the past day number stored on tampermonkey
{ //Starts the if condition
GM_deleteValue(a)
} //Finishes the if condition

}); //Finishes the foreach condition to erase all the users stored on tampermonkey
} //Finishes the if condition

§
Pubblicato: 19/06/2021

I think I've solved that using new Date().getMonth()

Pubblica risposta

Accedi per pubblicare una risposta.