惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Martin Fowler
Martin Fowler
Jina AI
Jina AI
J
Java Code Geeks
Microsoft Security Blog
Microsoft Security Blog
Recent Announcements
Recent Announcements
I
InfoQ
L
LangChain Blog
The Cloudflare Blog
IT之家
IT之家
博客园 - 叶小钗
Apple Machine Learning Research
Apple Machine Learning Research
B
Blog
A
About on SuperTechFans
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Last Week in AI
Last Week in AI
Blog — PlanetScale
Blog — PlanetScale
罗磊的独立博客
云风的 BLOG
云风的 BLOG
Microsoft Azure Blog
Microsoft Azure Blog
Engineering at Meta
Engineering at Meta
F
Fortinet All Blogs
博客园 - 聂微东
美团技术团队
博客园_首页

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
I Built a Safari Extension That Shows When Your YouTube V...
Fluphies · 2026-05-22 · via DEV Community

Ever put on a YouTube video and wondered if you'll finish it before you have to leave, go to sleep, or get back to work? I had that thought one too many times, so I built a small Safari extension to solve it.

It adds the end time directly inside YouTube's native time bubble:

0:20 / 7:23 · ends 11:44pm

That's it. Simple, but surprisingly useful.


How it works

The core logic is about three lines:

const remainingSec = (video.duration - video.currentTime) / video.playbackRate;
const endDate = new Date(Date.now() + remainingSec * 1000);

Enter fullscreen mode Exit fullscreen mode

Grab the remaining seconds, divide by the playback rate (so it works correctly at 0.5×, 1.5×, 2× etc.), add it to the current time. Done.

The trickier part was getting it to feel native.


Injecting into YouTube's player

YouTube's player controls are built with a bunch of class-named spans. The time bubble you see is a .ytp-time-display element containing:

  • .ytp-time-current — the current position
  • .ytp-time-separator — the /
  • .ytp-time-duration — the total length

I inject a new <span> directly after .ytp-time-duration, so the end time sits inside the same pill — inheriting YouTube's exact font, colour and sizing automatically without needing to hardcode any styles.

const duration = document.querySelector('.ytp-time-duration');
duration.insertAdjacentElement('afterend', mySpan);

Enter fullscreen mode Exit fullscreen mode


The YouTube SPA problem

YouTube is a single-page app, so navigating between videos doesn't trigger a full page reload. The player DOM gets rebuilt, which means my injected element disappears.

The fix is two-pronged:

1. Listen for YouTube's own navigation events:

['yt-navigate-finish', 'yt-page-data-updated', 'yt-player-updated'].forEach(evt => {
  document.addEventListener(evt, reinject);
});

Enter fullscreen mode Exit fullscreen mode

2. A MutationObserver as a fallback:

const obs = new MutationObserver(() => {
  if (!document.getElementById('yt-end-time-ext') 
      && document.querySelector('.ytp-time-duration')) {
    reinject();
  }
});
obs.observe(document.body, { childList: true, subtree: true });

Enter fullscreen mode Exit fullscreen mode

Between these two, re-injection is reliable across every navigation scenario I've tested.


Packaging for Safari

This is where it gets slightly annoying. Safari doesn't load unpacked extensions the way Chrome does — you need to wrap it in a macOS app using Xcode.

Apple provides a converter tool that does the heavy lifting:

xcrun safari-web-extension-converter ./youtube-end-time-extension

Enter fullscreen mode Exit fullscreen mode

This generates a full Xcode project with your extension embedded. You hit ⌘R, it builds a small launcher app, and then you enable the extension in Safari's settings. For open source projects this works fine — anyone can clone the repo and build it themselves in a couple of minutes.

The one gotcha: Safari requires you to re-enable Develop → Allow Unsigned Extensions every time you restart the browser. A minor annoyance, but not a dealbreaker for a personal tool.


What I'd add next

  • A subtle tooltip on hover showing the exact end time with seconds
  • Auto-hiding when a video is paused for a long time (since the end time becomes meaningless)
  • Firefox/Chrome support via the same manifest v3 codebase — it's already compatible, just needs packaging

Try it

The full source is on GitHub — it's about 100 lines of vanilla JS and works on any Mac with Xcode installed.

github.com/yourusername/youtube-end-time

If you build something on top of it or spot a bug, PRs are open. Would love to know if anyone finds this actually useful day-to-day.