### Initialize Environment and Implement Back Navigation - JavaScript Source: https://github.com/librespark/libretv/blob/main/player.html This snippet initializes global variables for the application, including saving a reference to the original `sha256` function and setting up an environment object potentially populated by the server. It also provides a robust `goBack` function that attempts multiple strategies to navigate the user to the previous page, prioritizing URL parameters, localStorage, referrer, and parent window communication before falling back to `history.back()` or the homepage. ```JavaScript // 保存原始 js‑sha256 实现,避免被 password.js 覆盖 window._jsSha256 = window.sha256; // 创建全局环境变量对象 window.__ENV__ = window.__ENV__ || {}; // 注入服务器端环境变量 (将由服务器端替换) // PASSWORD 变量将在这里被服务器端注入 window.__ENV__.PASSWORD = "{{PASSWORD}}"; // 改进返回上一页功能 function goBack(event) { // 防止默认链接行为 if (event) event.preventDefault(); // 1. 优先检查URL参数中的returnUrl const urlParams = new URLSearchParams(window.location.search); const returnUrl = urlParams.get('returnUrl'); if (returnUrl) { // 如果URL中有returnUrl参数,优先使用 window.location.href = decodeURIComponent(returnUrl); return; } // 2. 检查localStorage中保存的lastPageUrl const lastPageUrl = localStorage.getItem('lastPageUrl'); if (lastPageUrl && lastPageUrl !== window.location.href) { window.location.href = lastPageUrl; return; } // 3. 检查是否是从搜索页面进入的播放器 const referrer = document.referrer; // 检查 referrer 是否包含搜索参数 if (referrer && (referrer.includes('/s=') || referrer.includes('?s='))) { // 如果是从搜索页面来的,返回到搜索页面 window.location.href = referrer; return; } // 4. 如果是在iframe中打开的,尝试关闭iframe if (window.self !== window.top) { try { // 尝试调用父窗口的关闭播放器函数 window.parent.closeVideoPlayer && window.parent.closeVideoPlayer(); return; } catch (e) { console.error('调用父窗口closeVideoPlayer失败:', e); } } // 5. 无法确定上一页,则返回首页 if (!referrer || referrer === '') { window.location.href = '/'; return; } // 6. 以上都不满足,使用默认行为:返回上一页 window.history.back(); } ``` -------------------------------- ### Initialize Global Environment Variables (JavaScript) Source: https://github.com/librespark/libretv/blob/main/index.html Saves the original js-sha256 implementation to prevent conflicts and initializes a global environment variable object `__ENV__`, injecting a placeholder `{{PASSWORD}}` intended to be replaced by the server. ```JavaScript // 保存原始 js‑sha256 实现,避免被 password.js 覆盖 window._jsSha256 = window.sha256; // 创建全局环境变量对象 window.__ENV__ = window.__ENV__ || {}; // 注入服务器端环境变量 (将由服务器端替换) // PASSWORD 变量将在这里被服务器端注入 window.__ENV__.PASSWORD = "{{PASSWORD}}"; ``` -------------------------------- ### Schema.org WebSite Markup (JSON-LD) Source: https://github.com/librespark/libretv/blob/main/index.html Defines the website using Schema.org's WebSite type, providing name, URL, description, and a potential search action for search engines to understand the site's structure and search capabilities. ```JSON-LD { "@context": "https://schema.org", "@type": "WebSite", "name": "LibreTV", "url": "https://libretv.is-an.org/", "description": "免费在线视频搜索与观看平台", "potentialAction": { "@type": "SearchAction", "target": "https://libretv.is-an.org/?s={search\_term\_string}", "query-input": "required name=search\_term\_string" } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.