-
-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Only hide thumbnails during set timeframe #22
base: master
Are you sure you want to change the base?
Conversation
Added "work mode" ability to only hide thumbnails during a set timeframe.
Question: Should this be part of the extension? tldr: Yes. It's in keeping with a key use case, and the downsides are not too great. For:
Against:
Alternatives:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good! A few changes requested, but concept is sound and most code good.
If you're busy, am happy to make the edits myself in the next couple of days.
@@ -28,6 +28,11 @@ const defaultOptions = { | |||
everywhere: false, | |||
}, | |||
thumbnailMode: 'hidden', | |||
workMode: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should: call this scheduledBlocking
or timeBasedBlocking
, or similar. On first glance I don't think I'd know what workMode
means.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
must: Update the typedef on lines 9-18 to match (GitHub won't let me comment there). This ensures intellisense works as expected, and in future if we convert to TypeScript / run linters they'll pass.
You probably will want to merge in the master branch first, because I think there may be a few merge conflicts otherwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider: store this as an array of enabled times. This would allow users to set multiple periods where the extension is enabled, for example if they have a break in their work day or similar.
We don't actually have to accept more than one to start with, but I think it'd be good to design this so that if we do want to accept more than one in future people don't lose their settings. The options page would either:
- have an input as just a text field, where people can enter comma-separated ranges - format could be like LeechBlock (e.g.
0900-1700,1800-1900
) or ISO8601-like format (e.g.09:00/17:00,18:00/19:00
) - have pairs of time inputs, and users could click a
+
icon to add more ranges
@@ -56,8 +72,20 @@ const updateElem = async () => { | |||
|| (options.disabledOnPages.watch && window.location.pathname === '/watch') | |||
|| (options.disabledOnPages.subscriptions && window.location.pathname === '/feed/subscriptions'); | |||
|
|||
elem.innerHTML = `/* Injected by the Hide YouTube Thumbnails extension */ | |||
${css[isDisabled ? 'normal' : options.thumbnailMode]}` | |||
if(options.workMode.enabled){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
must: I think we can move this logic into the isDisabled
check. For example, adding a condition like:
|| (options.workMode.enabled && !IsItWorkTime(options.workMode.startTime, options.workMode.endTime))
This significantly reduces code duplication and complexity.
@@ -47,6 +47,22 @@ ytd-playlist-video-renderer:not(:hover) ytd-thumbnail, | |||
const elem = document.createElement("style"); | |||
document.documentElement.appendChild(elem); | |||
|
|||
const IsItWorkTime = (startTime, endTime)=>{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: use camel case for JS functions. Align naming with options if we're renaming to scheduledBlocking
.
@@ -47,6 +47,22 @@ ytd-playlist-video-renderer:not(:hover) ytd-thumbnail, | |||
const elem = document.createElement("style"); | |||
document.documentElement.appendChild(elem); | |||
|
|||
const IsItWorkTime = (startTime, endTime)=>{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
praise: This logic looks sound and simple. I like it!
<input type="checkbox" name="enableWorkMode" id="enableWorkMode"> | ||
<label for="enableWorkMode" data-i18n="options_enable_work_mode">Enabled</label><br /> | ||
<label for="workModeStart">Start date:</label> | ||
<input type="time" id="workModeStart" name="workModeStart" > |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
praise: I like the use of the type="time"
input!
@@ -36,6 +36,16 @@ | |||
<label for="disableEverywhere" data-i18n="options_disable_extension_everywhere">Everywhere</label><br /> | |||
<br /> | |||
|
|||
<p data-i18n="options_work_mode">Work Mode</p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(update naming here if we're changing it to scheduledBlocking
or similar)
@@ -36,6 +36,16 @@ | |||
<label for="disableEverywhere" data-i18n="options_disable_extension_everywhere">Everywhere</label><br /> | |||
<br /> | |||
|
|||
<p data-i18n="options_work_mode">Work Mode</p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider: Adding the strings to the en
and es
translation files in _locales
. This makes things easier to translate in future.
If work mode is enabled:
if work mode is disabled:
Added "work mode" ability to only hide thumbnails during a set timeframe. Disabled by default, default time frame from 9am-5pm.
Please check the updateElem function, because I overrode the main functionality and would be open to a better way.