penge/block-site

Add option to pick Count period

Closed this issue ยท 20 comments

olfek commented

Agreed to add option to pick period for counter: All time, This month, This week, Today

Note: Previous discussion started on how to reset the count (counter) but that won't be necessary.


Should counter persist between browsing sessions?

Especially considering there is no way to reset the counter.

๐Ÿค”

penge commented

Hi @olfek

Counter is reset for a specific rule (let's say youtube.com) when you remove the rule from the blocked list AND then at any time after visit any website (let it be blocked or allowed). The reason for this implementation is that any changes in Options, including changes in blocked list, are saved automatically, and so counter shouldn't be reset immediately as you type the rules, otherwise even a slight change like removing a letter from youtube.com and then adding it back, would cause a reset of its counter.

But to be honest, I was a bit hesitant to add the Counter feature as it introduces a bit of gamification and replaces one addiction (of visiting a website) with another (how many blocked I have today?). I think Counter is not an essential information and doesn't change the fact I tried to access something I shouldn't. Doesn't matter if it was 10x or 100x. Maybe better if I don't know this information. Shall we remove the feature?

olfek commented

I would suggest adding a setting to enable/disable the counter rather than removing it completely. Someone might find it to be useful.

If an enable/disable setting is added, I'd recommend having it enabled by default so new users can see the extension in all its glory.

olfek commented

Counter is reset for a specific rule (let's say youtube.com) when you remove the rule from the blocked list AND then at any time after visit any website (let it be blocked or allowed). The reason for this implementation is that any changes in Options, including changes in blocked list, are saved automatically, and so counter shouldn't be reset immediately as you type the rules, otherwise even a slight change like removing a letter from youtube.com and then adding it back, would cause a reset of its counter.

Yep this makes a lot of sense honestly, a counter since the rule was added. Besides, the counter would be even more useless if it reset on every new session, as it would be hiding our level of procrastination and unproductivity ๐Ÿ˜

I could start a new session several times in one day so the counter wouldn't be very useful then.

olfek commented

But, consider this example.

Suppose its been 2 months since I added a block rule.

The first month, I was visiting the blocked site a lot. Then the second month I wasn't visiting it very much.

It would be nice for the counter to show this improvement in a time range of my choice.

penge commented

...would be hiding our level of procrastination and unproductivity ๐Ÿ˜

Exactly ๐Ÿ˜„

It would be nice for the counter to show this improvement in a time range of my choice.

We already save counter information as timestamps, so it's ready to show chart over time ๐Ÿ˜…

Maybe we could even add a highscore ๐Ÿคฃ

If an enable/disable setting is added, I'd recommend having it enabled by default so new users can see the extension in all its glory.

This is quite easy to add. I was thinking about it. Probably best way to satisfy both parties?

olfek commented

This is quite easy to add. I was thinking about it. Probably best way to satisfy both parties?

Sounds good but the enable/disable setting for the counter would be a new issue.

This issue is about when/if and under what circumstances the counter should be reset.

We already save counter information as timestamps, so it's ready to show chart over time ๐Ÿ˜…

Maybe we could even add a highscore ๐Ÿคฃ

lol, to begin with, I think we should keep it simple. For me personally, I would want the counter to reset daily, but someone else might want the counter to reset weekly or monthly or never.

penge commented

Sounds good but the enable/disable setting for the counter would be a new issue.

Agreed.

lol, to begin with, I think we should keep it simple.

I think the same. I actually think no counter is needed at all. It doesn't bring me value to know my blocked stats. It's not a game.

olfek commented

For me it has actually been useful, I can sometimes waste a lot of time on YouTube, the other day I involuntarily visited YouTube and saw the blocked screen with a block count of 30+, it made me re-evaluate my life choices haha ๐Ÿ˜…

Seeing the number so high reaffirmed my commitment to avoiding YouTube.

The counter makes the user feel guilty, makes them realise they have a problem, this is the counters purpose. Therefore this counter feature makes this extension more effective at combating procrastination, unproductivity and website addictions (YouTube in my case ๐Ÿ˜…)

penge commented

Tell me about it ๐Ÿ˜„ I don't want to see my YouTube counter because that number is just horrible ๐Ÿ˜„

Soooo. I think we can agree how resetting of counter works is as we need it to be. And can create a new issue to add option to enable show counter, by default shown or not shown?

olfek commented

create a new issue to add option to enable show counter, by default shown or not shown?

by default - shown (allow new users to taste all the features)

and yep, create a new issue ๐Ÿ‘

I think we can agree how resetting of counter works is as we need it to be.

Not for me unfortunately, I would like a daily reset.

penge commented

We don't need to reset anything ๐Ÿ˜‰

We can just add a new dropdown to Options, where you would pick the era (filter, a view) for the displayed count: All time, This month, This week, Today.

How that sounds? If you agree, feel free to create a new issue.

olfek commented

Yep that sounds perfect. Lets just use this issue.

olfek commented

What would the performance implications be though, if I've been using the extension for 365 days, and I only want the count for today, the code will need to process all blocks that have occurred in the last 365 days to find the block count for today.

olfek commented

pseudocode

FOR EACH block IN blockHistory
    IF block.date == today
        blockCount++

would it look something like this?

olfek commented

This has the potential to become slower over time if implemented poorly.

penge commented

What would the performance implications be though, if I've been using the extension for 365 days, and I only want the count for today, the code will need to process all blocks that have occurred in the last 365 days to find the block count for today.

If you would let's say open youtube.com which is blocked, 1 000 000 times over the past 365 days, it would take, to get that information for today, even in an unoptimized way of going over every record, roughly 35 milliseconds. In other words, 1/30 of a second. Woudn't notice a slowdown.

It could be optimized in many ways, for sure. Not saying it is needed, but for example, you don't have to go over everything to find records for Today. You could start at the end and go backwards until you find something else as Today (which would be Yesterday). With this simple optimization, you'd go over only 1/365 (just an example, only valid when you'd have same counts for every day) of all records only and make it thus as fast as 0,1 millisecond. In other words, 1/10000 of a second.

I wound't worry about the performance really. But glad you asked. If curious, you can try this by yourself.

/**
 * Repeats 10-times:
 * Creates an array of "length" with random numbers in range <0, 1)
 * and filters numbers down to numbers that are >0.5.
 * 
 * And prints:
 * - each run duration in ms
 * - average run duration in ms
*/
const test = (length) => {
  const durations = [];
  for (let r = 1; r <= 10; r++) {
    const arr = Array(length).fill().map(() => Math.random());
    const startTime = performance.now();
    const filtered = arr.filter((item) => item > 0.5);
    const endTime = performance.now();
    const duration = endTime - startTime;
    durations.push(duration);
    console.log(`run ${r} duration: ${duration} ms`);
  }
  const averageDuration = durations.reduce((p, c) => p + c, 0) / durations.length;
  console.log(`average run duration: ${averageDuration} ms`);
};


test(1_000_000); // try a different length
olfek commented

You could start at the end and go backwards until you find something else as Today (which would be Yesterday).

This is assuming that the counter data retrieved from storage is in the correct order, is that the case?

Is the correct order guaranteed?

penge commented

Every blocking is always added to the end. The order is guaranteed.

penge commented

@olfek

This feature is now implemented. Here's a preview:

count-period.mov

When you change option to "Show Blocked info page", it would show additional and related options in that area, to show how many times blocked [Yes/No], and blocked period [All Time, This Month, This Week, Today].

Blocked info page message would then depend on the selected period:

youtube.com was blocked 42x.

youtube.com was blocked 38x this month.

youtube.com was blocked 12x this week.

youtube.com was blocked 5x today.

As you can see, any other than "All Time" period is included in the message.

Other changes:

  • I have replaced checkboxes with more descriptive Yes/No and gave options the same work & feel - just dropdowns.
  • All changes saved automatically as before. And now, all changes also synced across other Options pages (not related to sync storage), in case Options are open multiple times (same window, other windows), any changes in options will be applied elsewhere.

What do you think?

olfek commented

@penge looks good to me ๐Ÿ‘