Free tools (no login), linked from nav and footer via /tools: - /youtube-transcript-generator: reads the captions a video already has on YouTube (free_tools.py, yt-dlp over the flat-rate static proxies only, never the per-GB proxy, never the GPU). Per-IP limits, global daily cap, 24 h cache, honest "no captions" answer with a CTA to the clip generator. Copy / TXT / SRT export in the browser. - /youtube-tag-generator: tags, 10 titles or a description from a brief, one Gemini text call, rules taken from YouTube's own docs (sourced on the page). - /video-aspect-ratio-converter: 16:9 to 9:16 in the browser with mediabunny and WebCodecs (blur / crop / bars), nothing uploaded. Tool pages keep the form in the static HTML; the behaviour is a Vite entry (dashboard/tools) that vite-plugin-seo resolves by name. New pages /auto-clip and /youtube-automation with real, blurred screenshots of the Autopilot tab and the connect-an-agent card, Autopilot rules from cloud/autopilot.py, plan prices from the billing API and aggregate usage from the ledger (dated). SEO fixes: titles/metas for /how-openshorts-works, /podcast-to-shorts, /mcp and /free-ai-clip-generator (brand queries at pos 1-2 with <1% CTR); a free AI clipper / free clipping website section and FAQ, and contextual "free AI clip generator" anchors from sibling pages and the homepage. Attribution: static pages now write the same first-touch os_attrib key the app writes, so the signup is credited to the page the visit started on (7,481 of 7,481 signups in 30 days said "/"). Signup, CheckoutStarted and Subscribed carry landing_path / referrer_host / utm props in OpenPanel. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
95 lines
3.5 KiB
JavaScript
95 lines
3.5 KiB
JavaScript
/* Shared helpers for the free tool pages.
|
|
*
|
|
* These pages are static HTML emitted by vite-plugin-seo.js; the markup of
|
|
* each tool is already in the document (so crawlers and no-JS clients see the
|
|
* form), and these modules only wire it up. No React, no framework: the
|
|
* biggest of them is the video converter, and that weight is mediabunny.
|
|
*/
|
|
|
|
// Same variable the app uses. Empty means same-origin (self-host behind one host).
|
|
export const API_URL = (import.meta.env.VITE_API_URL || '').replace(/\/$/, '')
|
|
|
|
/* OpenPanel events. window.op is the queueing stub the page head defines; it
|
|
* only ever flushes when the analytics init passed its host/placeholder guard,
|
|
* so on localhost, a fork or a preview build this records nothing. */
|
|
export function track(event, props) {
|
|
try {
|
|
if (typeof window.op === 'function') window.op('track', event, props || {})
|
|
} catch (_) { /* analytics must never break a tool */ }
|
|
}
|
|
|
|
export const $ = (id) => document.getElementById(id)
|
|
|
|
export function el(tag, attrs, ...children) {
|
|
const node = document.createElement(tag)
|
|
for (const [k, v] of Object.entries(attrs || {})) {
|
|
if (v === undefined || v === null || v === false) continue
|
|
if (k === 'class') node.className = v
|
|
else if (k === 'text') node.textContent = v
|
|
else if (k.startsWith('on')) node.addEventListener(k.slice(2), v)
|
|
else node.setAttribute(k, v === true ? '' : v)
|
|
}
|
|
for (const c of children) {
|
|
if (c === null || c === undefined || c === false) continue
|
|
node.append(c instanceof Node ? c : document.createTextNode(String(c)))
|
|
}
|
|
return node
|
|
}
|
|
|
|
export function setStatus(node, text, kind) {
|
|
node.textContent = text || ''
|
|
node.dataset.kind = kind || ''
|
|
node.hidden = !text
|
|
}
|
|
|
|
export async function copyText(text, button) {
|
|
try {
|
|
await navigator.clipboard.writeText(text)
|
|
} catch (_) {
|
|
// Older browsers / insecure contexts: a hidden textarea still works.
|
|
const ta = el('textarea', { style: 'position:fixed;opacity:0' })
|
|
ta.value = text
|
|
document.body.append(ta)
|
|
ta.select()
|
|
try { document.execCommand('copy') } catch (_) { /* nothing else to try */ }
|
|
ta.remove()
|
|
}
|
|
if (button) {
|
|
const old = button.textContent
|
|
button.textContent = 'Copied'
|
|
setTimeout(() => { button.textContent = old }, 1400)
|
|
}
|
|
}
|
|
|
|
export function downloadBlob(blob, filename) {
|
|
const url = URL.createObjectURL(blob)
|
|
const a = el('a', { href: url, download: filename })
|
|
document.body.append(a)
|
|
a.click()
|
|
a.remove()
|
|
setTimeout(() => URL.revokeObjectURL(url), 10000)
|
|
}
|
|
|
|
export function safeFilename(s, fallback) {
|
|
const out = String(s || '').replace(/[\\/:*?"<>|]+/g, ' ').replace(/\s+/g, ' ').trim().slice(0, 80)
|
|
return out || fallback
|
|
}
|
|
|
|
/* Error text from our API's {detail: {code, message}} shape, or a generic line. */
|
|
export async function apiError(res) {
|
|
try {
|
|
const data = await res.json()
|
|
const d = data && data.detail
|
|
if (d && typeof d === 'object') return { code: d.code || '', message: d.message || '' }
|
|
if (typeof d === 'string') return { code: '', message: d }
|
|
} catch (_) { /* not JSON */ }
|
|
return { code: String(res.status), message: 'Something went wrong. Try again in a moment.' }
|
|
}
|
|
|
|
/* Hand a YouTube link to the app: MediaInput reads os_pending_url on mount,
|
|
* so the visitor lands in the clip generator with their video already in. */
|
|
export function openInApp(url, tool) {
|
|
track('tool_cta_click', { tool })
|
|
try { if (url) localStorage.setItem('os_pending_url', url) } catch (_) { /* private mode */ }
|
|
window.location.href = '/#app'
|
|
}
|