-
-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. praise: This logic looks sound and simple. I like it! |
||
currentDate = new Date(); | ||
|
||
startDate = new Date(currentDate.getTime()); | ||
startDate.setHours(startTime.split(":")[0]); | ||
startDate.setMinutes(startTime.split(":")[1]); | ||
startDate.setSeconds(0); | ||
|
||
endDate = new Date(currentDate.getTime()); | ||
endDate.setHours(endTime.split(":")[0]); | ||
endDate.setMinutes(endTime.split(":")[1]); | ||
endDate.setSeconds(0); | ||
|
||
return currentDate > startDate && currentDate < endDate; | ||
} | ||
|
||
const updateElem = async () => { | ||
const options = await loadOptions() | ||
|
||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. must: I think we can move this logic into the
This significantly reduces code duplication and complexity. |
||
|
||
if(IsItWorkTime(options.workMode.startTime, options.workMode.endTime)){ | ||
elem.innerHTML = `/* Injected by the Hide YouTube Thumbnails extension */ | ||
${css[options.thumbnailMode]}` | ||
}else{ | ||
elem.innerHTML = `/* Injected by the Hide YouTube Thumbnails extension */ | ||
${css["normal"]}` | ||
} | ||
}else{ | ||
elem.innerHTML = `/* Injected by the Hide YouTube Thumbnails extension */ | ||
${css[isDisabled ? 'normal' : options.thumbnailMode]}` | ||
} | ||
|
||
} | ||
|
||
// Update when settings are changed | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. (update naming here if we're changing it to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. consider: Adding the strings to the |
||
<p data-i18n="options_work_mode_description">Only hide thumbnails during a set time of the day</p> | ||
<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 commentThe reason will be displayed to describe this comment to others. Learn more. praise: I like the use of the |
||
|
||
<label for="workModeEnd">End date:</label> | ||
<input type="time" id="workModeEnd" name="workModeEnd" > | ||
|
||
<p id="status">✅ <span data-i18n="options_loaded">Preferences loaded</span></p> | ||
</form> | ||
<script src="common.js"></script> | ||
|
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
ortimeBasedBlocking
, or similar. On first glance I don't think I'd know whatworkMode
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:
0900-1700,1800-1900
) or ISO8601-like format (e.g.09:00/17:00,18:00/19:00
)+
icon to add more ranges