Ver código fonte

fix: add video time threshold to reloadTab time param

Sv443 4 meses atrás
pai
commit
723fe9a1e8
1 arquivos alterados com 8 adições e 4 exclusões
  1. 8 4
      src/utils/misc.ts

+ 8 - 4
src/utils/misc.ts

@@ -222,6 +222,9 @@ export function formatNumber(num: number, notation?: NumberLengthFormat): string
   );
 }
 
+/** add `time_continue` param only if current video time is greater than this value */
+const reloadTabVideoTimeThreshold = 3;
+
 /** Reloads the tab. If a video is currently playing, its time and volume will be preserved through the URL parameter `time_continue` and `bytm-reload-tab-volume` in GM storage */
 export async function reloadTab() {
   const win = getUnsafeWindow();
@@ -229,12 +232,12 @@ export async function reloadTab() {
     enableDiscardBeforeUnload();
 
     if((getVideoElement()?.readyState ?? 0) > 0) {
-      const time = (await getVideoTime() ?? 0) - 0.25;
+      const time = await getVideoTime(0) ?? 0;
       const volume = Math.round(getVideoElement()!.volume * 100);
 
       const url = new URL(win.location.href);
 
-      if(!isNaN(time) && time > 0)
+      if(!isNaN(time) && time > reloadTabVideoTimeThreshold)
         url.searchParams.set("time_continue", String(time));
       if(!isNaN(volume) && volume > 0)
         await GM.setValue("bytm-reload-tab-volume", String(volume));
@@ -255,7 +258,8 @@ export async function reloadTab() {
 /**
  * Returns the blob-URL of a resource by its name, as defined in `assets/resources.json`, from GM resource cache - [see GM.getResourceUrl docs](https://wiki.greasespot.net/GM.getResourceUrl)  
  * Falls back to a `raw.githubusercontent.com` URL or base64-encoded data URI if the resource is not available in the GM resource cache  
- * @param uncached Set to true to fetch from the `raw.githubusercontent.com` URL instead of the GM resource cache
+ * @param name The name / key of the resource as defined in `assets/resources.json` - you can use `as "_"` to make TypeScript shut up if the name can not be typed as `ResourceKey`
+ * @param uncached Set to true to always fetch from the `raw.githubusercontent.com` URL instead of the GM resource cache
  */
 export async function getResourceUrl(name: ResourceKey | "_", uncached = false) {
   let url = !uncached && await GM.getResourceUrl(name);
@@ -275,7 +279,7 @@ export async function getResourceUrl(name: ResourceKey | "_", uncached = false)
         return `https://raw.githubusercontent.com/${repo}/${ghRef}/assets/${pathName}`;
     }
 
-    warn(`Couldn't get blob URL nor external URL for @resource '${name}', trying to use base64-encoded fallback`);
+    warn(`Couldn't get blob URL nor external URL for @resource '${name}', attempting to use base64-encoded fallback`);
     // @ts-ignore
     url = await GM.getResourceUrl(name, false);
   }