### Dictionary Thread Navigation Enhancement - JavaScript Source: https://context7.com/masteralice3104/nico_downloader/llms.txt Enhances Niconico Dictionary (dic.nicovideo.jp) pages with features for loading more comments and bookmarking. It fetches and appends new comment threads, allows setting/removing bookmarks for specific comments, and provides navigation to bookmarked comments. This script is auto-initialized on dictionary pages. ```javascript // Auto-initialized on dictionary pages window.onload = function() { Start_Dic(); }; // Load next 30 comments function next_30load() { document.getElementById("next_30").setAttribute("disabled", true); let kijiURL = kiji_URL_get(); // Get article URL let DL_URL = kijiURL + "/" + Number(end_res + 1) + "-"; fetch(DL_URL, { method: "GET" }) .then(response => response.text()) .then(data => { const parser = new DOMParser(); const doc = parser.parseFromString(data, "text/html"); let res_head = doc.getElementsByClassName("st-bbs_reshead"); let res_body = doc.getElementsByClassName("st-bbs_resbody"); // Append elements to page for (let i = 0; i < res_body.length; i++) { let add_element = createElementFromHTML(res_head[i].outerHTML); document.getElementsByClassName("st-bbs_resbody")[document.getElementsByClassName("st-bbs_resbody").length - 1].after(add_element); add_element = createElementFromHTML(res_body[i].outerHTML); document.getElementsByClassName("st-bbs_reshead")[document.getElementsByClassName("st-bbs_reshead").length - 1].after(add_element); } refresh_resNo(); resnumhead_plus(); }); } // Bookmark specific comment function pin_dome(e) { let res_no = e.currentTarget.getAttribute("name"); let kiji_URL = kiji_URL_get(); if (e.currentTarget.innerText === "■") { // Remove bookmark Option_setWriting(kiji_URL, "0"); } else { // Set bookmark Option_setWriting(kiji_URL, res_no); } resnumhead_plus(); } // Jump to bookmarked comment function threadpin_move() { let kiji_URL = kiji_URL_get(); let id = Number(setOption(kiji_URL)); if (id === 0) { location.href = kiji_URL + "/1-"; return; } // Calculate page containing the comment let page = Math.floor(id / 30) * 30 + 1; let pageURL = kiji_URL + "/" + page; if (start_res > id || end_res < id) { location.href = pageURL + "#" + id.toString(); } else { location.hash = id.toString(); } } ``` -------------------------------- ### Manage User Settings with Chrome Storage and localStorage Source: https://context7.com/masteralice3104/nico_downloader/llms.txt This section details the handling of persistent user preferences using Chrome's storage API and localStorage. It includes functions for writing and reading various settings such as video download mode, HLS save behavior, debug logging, language preferences, and file format. It also covers initializing default settings and loading them on page load. Debug printing is conditional on the debug mode being enabled. ```javascript // Write option to storage Option_setWriting("video_downloading", "2"); // 0:smID, 1:title, 2:smID_title, 3:title_smID Option_setWriting("video_hlssave", "1"); // 0:initial, 1:enabled Option_setWriting("debug", "1"); // Enable debug logging Option_setWriting("language_setting", "en"); // ja or en Option_setWriting("downFile_setting", "mp4"); // mp4 or aac // Read option from storage const downloadMode = setOption("video_downloading"); const saveMode = setOption("video_hlssave"); const isDebug = setOption("debug"); const language = setOption("language_setting"); const fileFormat = setOption("downFile_setting"); // Debug printing (only outputs if debug mode enabled) DebugPrint("Current download mode: " + downloadMode); // Initialize default settings defalt_dataWrite(); // Load options on page load Options_onload(); ``` -------------------------------- ### Manage Download Button UI in Niconico Player Source: https://context7.com/masteralice3104/nico_downloader/llms.txt This snippet demonstrates how to create and update the download button interface within the Niconico video player. It covers initializing the downloader, updating button text with localization, creating a save button with event handlers, directly manipulating HTML content, and automatically opening system message dialogs. It relies on the NicoDownloaderClass. ```javascript const downloader = new NicoDownloaderClass(); // Create initial button element downloader.ButtonFirstMake(); // Update button text with localization downloader.ButtonTextWrite("処理開始"); // "Processing start" downloader.ButtonTextWrite("処理中"); // "Processing" downloader.ButtonTextWrite("保存完了"); // "Save complete" // Create save button with click handler downloader.SaveButtonMake("sm12345_VideoTitle.mp4"); // Direct HTML update const customHTML = ''; downloader.ButtonInnerHTMLWrite(customHTML); // Auto-open system message dialog const autoOpenJS = downloader.SystemMessageAutoOpenToText(); // Returns properly escaped JavaScript for onclick attribute ``` -------------------------------- ### Manage Video Download State and Progress Source: https://context7.com/masteralice3104/nico_downloader/llms.txt This snippet focuses on managing the state of video downloads to prevent concurrent operations and track loaded videos. It includes methods to check if a download is already in progress, set and reset the downloading state, verify if a video has already been processed, mark videos as loaded, track download progress percentage, and manage download failure counts. It utilizes the NicoDownloaderClass and logs output to the console. ```javascript const downloader = new NicoDownloaderClass(); // Check if already downloading if (downloader.VideoDownloadingCheck()) { console.log("Download in progress, exiting"); return false; } // Start download process downloader.VideoDownloadingSet(); // Sets downloading = true // Check if video already loaded const videoSM = "sm12345"; if (downloader.VideoLoadedCheck(videoSM)) { console.log("Video already processed"); } else { // Mark as loaded downloader.VideoLoadedSMIDSet(videoSM); // Perform download operations... // Reset when complete downloader.VideoDownloadingReset(); // Sets downloading = false } // Track download progress downloader.DownloadPercentageSet(45); // Set to 45% console.log("Progress:", downloader.DownloadPercentageGet() + "% "); // Track download failures downloader.DownloadFaultNumAdd(); // Increment failure count if (downloader.DownloadFaultNumCheck() > 5) { console.error("Too many failures"); downloader.DownloadFaultNumReset(); } ``` -------------------------------- ### Automatic Video Download Workflow - JavaScript Source: https://context7.com/masteralice3104/nico_downloader/llms.txt Implements a periodic workflow to detect and download Niconico videos. It checks for valid URLs, prevents concurrent downloads, retrieves video metadata, generates filenames, and initiates the download process. Dependencies include Chrome Storage API and potentially other Niconico-related classes. ```javascript // Main download function async function VideoDown() { const NicoDownloader = new NicoDownloaderClass(); const Nicovideo = new NicovideoClass(); // Verify URL matches if (!Nicovideo.CheckNicovideoWatchURL()) return false; // Prevent concurrent downloads if (NicoDownloader.VideoDownloadingCheck()) return false; // Get video ID and metadata Nicovideo.video_sm = Nicovideo.VideoSmGet(NicoDownloader.MatchingSMIDArray); await Nicovideo.SetAllFromVideoSm(Nicovideo.video_sm); if (Nicovideo.video_sm === "" || Nicovideo.video_title === "") { throw new Error("video_sm or video_title is null"); } // Generate filename let downFile_setting = await new Promise((resolve, reject) => { chrome.storage.local.get("downFile_setting", function(value) { if (chrome.runtime.lastError) { reject(chrome.runtime.lastError); } else { resolve(value.downFile_setting); } }); }); let video_name = NicoDownloader.VideoDownloadNameMake( Nicovideo.video_sm, Nicovideo.video_title, downFile_setting ); Nicovideo.video_name = video_name; // Create UI button if not already loaded if (!NicoDownloader.VideoLoadedCheck(Nicovideo.video_sm)) { NicoDownloader.ButtonFirstMake(); NicoDownloader.ButtonTextWrite("処理開始"); NicoDownloader.SaveButtonMake(Nicovideo.video_name); if (!NicoDownloader.CheckBeforeDownload()) { throw new Error("CheckBeforeDownload ERROR"); } // Extract master URL and download const masterURL = NicoDownloader.MasterURLGet(); if (masterURL && masterURL.indexOf("delivery.domand.nicovideo.jp") !== -1) { await MovieDownload_domand(Nicovideo, NicoDownloader); NicoDownloader.VideoDownloadingReset(); NicoDownloader.VideoLoadedSMIDSet(Nicovideo.video_sm); } } return true; } // Run every 2 seconds let intervalId = setInterval(() => { try { VideoDown(); } catch (e) { console.log(e); } }, 2000); ``` -------------------------------- ### NicoDownloaderClass: Orchestrate Video Download Workflow Source: https://context7.com/masteralice3104/nico_downloader/llms.txt The `NicoDownloaderClass` handles the core download logic, including button creation, video metadata fetching, HLS playlist processing, and segment extraction. It requires instances of `NicovideoClass` and `NicovideoM3u8` for full functionality. The output is a processed video file. ```javascript const NicoDownloader = new NicoDownloaderClass(); const Nicovideo = new NicovideoClass(); // Check if URL matches Niconico watch page if (Nicovideo.CheckNicovideoWatchURL()) { // Get video SM ID from URL Nicovideo.video_sm = Nicovideo.VideoSmGet(NicoDownloader.MatchingSMIDArray); // Fetch all video metadata await Nicovideo.SetAllFromVideoSm(Nicovideo.video_sm); // Create download filename let downFile_setting = "mp4"; // or "aac" let video_name = NicoDownloader.VideoDownloadNameMake( Nicovideo.video_sm, Nicovideo.video_title, downFile_setting ); // Extract master M3U8 URL from system messages const masterURL = NicoDownloader.MasterURLGet(); // Process M3U8 playlists await NicoDownloader.URLToM3u8Set("First", masterURL); NicoDownloader.M3u8ToAudioAndVideoUrlSet(); await NicoDownloader.URLToM3u8Set("Audio", NicoDownloader.M3u8.AudioM3u8URL); await NicoDownloader.URLToM3u8Set("Video", NicoDownloader.M3u8.VideoM3u8URL); // Extract TS segment URLs NicoDownloader.TSURLs = NicoDownloader.M3u8Class.MakeURLListToTSURLs(NicoDownloader); NicoDownloader.TSFilenames = NicoDownloader.M3u8Class.MakeTSFileNameListtoArray(NicoDownloader); // Update UI NicoDownloader.ButtonTextWrite("処理中"); } ``` -------------------------------- ### M3U8 Parsing and TS Segment URL Extraction Source: https://context7.com/masteralice3104/nico_downloader/llms.txt This snippet demonstrates how to parse M3U8 playlist content into a structured format and extract individual transport stream (TS) segment URLs. It involves using `NicoDownloaderClass` for parsing and `NicovideoM3u8` for generating TS filenames and URL lists. This is crucial for downloading fragmented video streams. ```javascript const downloader = new NicoDownloaderClass(); // Parse M3U8 text to JSON structure const m3u8Text = `#EXTM3U #EXT-X-STREAM-INF:BANDWIDTH=1280000 https://example.com/video.m3u8 #EXT-X-MEDIA:URI="https://example.com/audio.m3u8"`; const parsed = downloader.Parsem3u8(m3u8Text); console.log(parsed); // Returns: { "EXT-X-STREAM-INF": [...], "EXT-X-MEDIA": [...] } // Download M3U8 with cookies const m3u8Content = await downloader.DownloadTextWithCookie("https://delivery.domand.nicovideo.jp/hls/xxx/master.m3u8"); // Extract TS filenames from URLs const m3u8Class = new NicovideoM3u8(); const filename = m3u8Class.MakeTSFilename("https://asset.domand.nicovideo.jp/video/segment001.ts?ht2_nicovideo=xxx"); console.log(filename); // "segment001.ts" // Generate complete TS URL list const tsUrls = m3u8Class.MakeURLListToTSURLs(downloader); // Returns array: [audioMapURL, audioKeyURL, ...audioSegments, videoMapURL, videoKeyURL, ...videoSegments] ``` -------------------------------- ### NicovideoClass: Fetch and Parse Niconico Video Metadata Source: https://context7.com/masteralice3104/nico_downloader/llms.txt The `NicovideoClass` is responsible for fetching detailed video metadata from Niconico's API endpoints. It allows retrieval of information such as title, view counts, comments, likes, and descriptions. This class can parse JSON data directly or be fed parsed JSON for processing. ```javascript // Create instance and fetch video data const nicovideo = new NicovideoClass(); // Fetch all metadata for a video await nicovideo.SetAllFromVideoSm('sm9'); // Access video properties console.log("Title:", nicovideo.video_title); console.log("Views:", nicovideo.view_count); console.log("Comments:", nicovideo.comment_count); console.log("Mylists:", nicovideo.mylist_count); console.log("Likes:", nicovideo.like_count); console.log("Owner:", nicovideo.video_owner); console.log("Registered:", nicovideo.video_registeredAt); console.log("Description:", nicovideo.video_description); console.log("Tags:", nicovideo.video_tags); console.log("Genre:", nicovideo.video_genre); console.log("Series:", nicovideo.video_series); // Manual JSON download and parsing const json = await nicovideo.DownloadJson('sm12345'); nicovideo.SetJson(json); nicovideo.SetAll(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.