### Download Extension File (Bash Example) Source: https://github.com/explosion-scratch/to-userscript/blob/main/README.md Shows how to download a browser extension file (e.g., .xpi) from a given URL using the 'to-userscript download' command. This is useful for obtaining extension files for local conversion or analysis. The example uses 'bunx' to execute the command. ```bash bunx to-userscript download "https://chromewebstore.google.com/detail/material-icons-for-github/bggfcpfjbdkhfhfmkjpbhnkhnpjjeomc/" -o ublock-origin.xpi ``` -------------------------------- ### Install and Run Extension to Userscript CLI Source: https://github.com/explosion-scratch/to-userscript/blob/main/CLI_README.md Commands to install the tool globally via npm or execute it directly using npx. ```bash npm install -g extension-to-userscript npx extension-to-userscript ``` -------------------------------- ### Install to-userscript Globally with npm Source: https://github.com/explosion-scratch/to-userscript/blob/main/README.md Installs the to-userscript package globally using npm. This command requires Node.js and npm to be installed on your system. After installation, the `to-userscript` command will be available in your terminal. ```bash npm install -g to-userscript ``` -------------------------------- ### Install to-userscript Globally with pnpm Source: https://github.com/explosion-scratch/to-userscript/blob/main/README.md Installs the to-userscript package globally using pnpm. This method is an alternative to npm and requires pnpm to be installed. It ensures the `to-userscript` command is accessible system-wide. ```bash pnpm add -g to-userscript ``` -------------------------------- ### Install to-userscript Globally with bun Source: https://github.com/explosion-scratch/to-userscript/blob/main/README.md Installs the to-userscript package globally using bun. This command leverages the bun runtime for package management. Similar to npm and pnpm, it makes the `to-userscript` command available in your environment. ```bash bun install -g to-userscript ``` -------------------------------- ### Convert Extensions to Userscripts Source: https://github.com/explosion-scratch/to-userscript/blob/main/CLI_README.md Examples of converting extensions from various sources like web stores, local folders, or archive files into userscripts or vanilla JS. ```bash # Convert from Chrome Web Store ext2us convert https://chrome.google.com/webstore/detail/extension-id # Convert local extension folder ext2us convert ./my-extension/ # Convert CRX/XPI/ZIP file ext2us convert extension.crx -o my-script.user.js # Convert Chrome extension with custom output ext2us convert "https://chrome.google.com/webstore/detail/name/abcd..." -o my-script.user.js # Convert Firefox addon ext2us convert ublock-origin -s firefox --verbose # Convert local extension without minification ext2us convert ./extension-folder/ --no-minify # Convert to vanilla JS target ext2us convert extension.crx -t vanilla -o extension.js ``` -------------------------------- ### Install and Use to-userscript CLI Tool Source: https://github.com/explosion-scratch/to-userscript/blob/main/docs/article.md This snippet demonstrates how to install the 'to-userscript' command-line interface globally using Bun and then use it to convert a Chrome Web Store extension URL or download a Firefox Add-on URL into a userscript file. The conversion can include minification. ```bash # Install the tool bun i -g to-userscript # or pnpx/npx to-userscript # Convert your favorite extension from the Chrome Store to-userscript convert "https://chrome.google.com/webstore/detail/..." --minify -o my-script.user.js # Or download an addon from Mozilla to-userscript download "https://addons.mozilla.org/en-US/firefox/addon/..." ``` -------------------------------- ### Convert Extension to Userscript (Bash Examples) Source: https://github.com/explosion-scratch/to-userscript/blob/main/README.md Demonstrates converting browser extensions to userscripts using various methods and options. Supports Chrome Web Store URLs, local directories, and local archive files. Options include output file specification, build target (userscript or vanilla JS), minification, beautification, locale selection, asset ignoring, force overwriting, and keeping temporary files. ```bash to-userscript convert "https://chromewebstore.google.com/detail/modern-for-wikipedia/emdkdnnopdnajipoapepbeeiemahbjcn?hl=en" -o modern-wikipedia.user.js --minify ``` ```bash to-userscript convert ./my-unpacked-extension/ -o my-script.user.js --locale fr ``` ```bash pnpm dlx to-userscript convert ./my-addon.xpi --target vanilla -o my-addon.js ``` -------------------------------- ### Generate @require Metadata (Bash Example) Source: https://github.com/explosion-scratch/to-userscript/blob/main/README.md Illustrates generating a metadata block for a userscript that uses the `@require` directive to include another local userscript. The output can be piped to the clipboard using 'pbcopy' for easy integration into a main userscript file. ```bash to-userscript require ./material-design-fileicons.user.js | pbcopy ``` -------------------------------- ### Run to-userscript without Global Installation Source: https://github.com/explosion-scratch/to-userscript/blob/main/README.md Executes the to-userscript command directly without a global installation, using package manager dlx commands. This is useful for running the tool once or in environments where global installations are not desired. It automatically downloads and runs the latest version. ```bash npx to-userscript pnpm dlx to-userscript bunx to-userscript ``` -------------------------------- ### Advanced CLI Options Source: https://github.com/explosion-scratch/to-userscript/blob/main/CLI_README.md Examples of using advanced CLI features such as verbose logging, custom temporary directories, and batch processing. ```bash # Verbose mode ext2us convert extension.crx -v # Custom temporary directory ext2us convert extension.crx --temp-dir /custom/temp --keep-temp # Batch processing ext2us convert ext1.crx -o script1.user.js ext2us convert ext2.crx -o script2.user.js ``` -------------------------------- ### Manage Chrome Cookies with chrome.cookies API Source: https://context7.com/explosion-scratch/to-userscript/llms.txt Demonstrates how to get, set, and remove cookies using the chrome.cookies API. It also shows how to listen for cookie change events. This API is essential for managing site-specific data. ```javascript // Get a specific cookie const cookie = await chrome.cookies.get({ url: 'https://example.com', name: 'session_id' }); if (cookie) { console.log('Cookie value:', cookie.value); console.log('Expires:', new Date(cookie.expirationDate * 1000)); } // Get all cookies for a URL const cookies = await chrome.cookies.getAll({ url: 'https://example.com' }); cookies.forEach(c => console.log(`${c.name}=${c.value}`)); // Set a cookie const newCookie = await chrome.cookies.set({ url: 'https://example.com', name: 'preference', value: 'dark_mode', expirationDate: Math.floor(Date.now() / 1000) + 86400 * 30 // 30 days }); // Remove a cookie await chrome.cookies.remove({ url: 'https://example.com', name: 'old_cookie' }); // Listen for cookie changes chrome.cookies.onChanged.addListener((changeInfo) => { console.log(`Cookie ${changeInfo.cookie.name} was ${changeInfo.removed ? 'removed' : 'set'}`); console.log('Cause:', changeInfo.cause); }); ``` -------------------------------- ### CLI Command: download Source: https://github.com/explosion-scratch/to-userscript/blob/main/README.md Downloads a browser extension file from a store URL to a local destination. ```APIDOC ## COMMAND: download ### Description Downloads an extension file from a Chrome Web Store or Firefox Add-ons URL. ### Syntax `to-userscript download ` ### Parameters #### Arguments - **source** (string) - Required - The URL of the extension. ### Request Example `to-userscript download "https://chromewebstore.google.com/detail/example" -o extension.crx` ``` -------------------------------- ### CLI Entry Point for Extension Conversion (JavaScript) Source: https://github.com/explosion-scratch/to-userscript/blob/main/CLI_README.md Illustrates the main command-line interface entry point for the `ext2us` tool, written in JavaScript. This file orchestrates the conversion process, likely involving input validation, downloading, extraction, and the core conversion logic. ```javascript src/cli/index.js # Main CLI entry point ``` -------------------------------- ### Download Extensions from Web Stores Source: https://github.com/explosion-scratch/to-userscript/blob/main/CLI_README.md Commands to download extension files directly from Chrome or Firefox web stores without performing a conversion. ```bash # Download only (no conversion) ext2us download extension-id -s chrome # Download Chrome extension ext2us download extension-id # Download Firefox addon ext2us download addon-name -s firefox -o addon.xpi # Download from URL ext2us download "https://addons.mozilla.org/addon/name/" ``` -------------------------------- ### CLI Command: download Source: https://github.com/explosion-scratch/to-userscript/blob/main/CLI_README.md Downloads an extension package directly from a web store without performing any conversion. ```APIDOC ## CLI COMMAND: download ### Description Downloads an extension from a web store (Chrome or Firefox) and saves it locally. ### Method CLI Command ### Endpoint ext2us download ### Parameters #### Path Parameters - **url** (string) - Required - The web store URL or extension ID. #### Options - **-o, --output** (string) - Optional - Output file path. - **-s, --store** (string) - Optional - Web store type: 'chrome' or 'firefox' (default: 'chrome') ### Request Example `ext2us download extension-id -s chrome -o extension.crx` ### Response #### Success Response - **status** (string) - Download completion status - **file_path** (string) - Path to the downloaded extension file ``` -------------------------------- ### CLI Command: require Source: https://github.com/explosion-scratch/to-userscript/blob/main/README.md Generates a metadata block to @require a local userscript. ```APIDOC ## COMMAND: require ### Description Generates the necessary metadata block to include another local userscript via the @require directive. ### Syntax `to-userscript require ` ### Parameters #### Arguments - **path-to-userscript** (string) - Required - Path to the target userscript file. ### Request Example `to-userscript require ./my-script.user.js` ``` -------------------------------- ### CLI Command: convert Source: https://github.com/explosion-scratch/to-userscript/blob/main/README.md The primary command used to transform a browser extension into a userscript file. ```APIDOC ## COMMAND: convert ### Description Converts a browser extension (from URL, local directory, or archive) into a .user.js userscript. ### Syntax `to-userscript convert [options]` ### Parameters #### Arguments - **source** (string) - Required - The URL, local path to directory, or path to .crx/.xpi/.zip file. #### Options - **--output, -o** (string) - Optional - Path to the output .user.js file. - **--target, -t** (string) - Optional - Build target: 'userscript' (default) or 'vanilla'. - **--minify** (boolean) - Optional - Minify output using terser. - **--beautify** (boolean) - Optional - Beautify output using prettier. - **--locale, -l** (string) - Optional - Preferred locale for metadata (e.g., 'en', 'fr'). - **--ignore-assets** (string) - Optional - Comma-separated list of extensions to ignore. - **--force, -f** (boolean) - Optional - Overwrite existing output file. ### Request Example `to-userscript convert "https://example.com/extension" -o script.user.js --minify` ``` -------------------------------- ### CLI Command: convert Source: https://github.com/explosion-scratch/to-userscript/blob/main/CLI_README.md Converts a browser extension from a web store, local archive, or directory into a userscript or vanilla JavaScript file. ```APIDOC ## CLI COMMAND: convert ### Description Converts an extension to a userscript from various sources including Web Store URLs, Extension IDs, local archives (.crx, .xpi, .zip), or local directories. ### Method CLI Command ### Endpoint ext2us convert ### Parameters #### Path Parameters - **source** (string) - Required - The source of the extension (URL, ID, file path, or directory path). #### Options - **-o, --output** (string) - Optional - Output file path (default: extension.user.js) - **-s, --store** (string) - Optional - Web store type: 'chrome' or 'firefox' (default: 'chrome') - **-t, --target** (string) - Optional - Build target: 'userscript' or 'vanilla' (default: 'userscript') - **-m, --minify** (boolean) - Optional - Minify output (default: true) - **--no-minify** (boolean) - Optional - Disable minification - **--temp-dir** (string) - Optional - Custom temporary directory - **--keep-temp** (boolean) - Optional - Keep temporary files after conversion - **-v, --verbose** (boolean) - Optional - Verbose output with detailed information ### Request Example `ext2us convert https://chrome.google.com/webstore/detail/extension-id -o my-script.user.js -m` ### Response #### Success Response - **status** (string) - Conversion completion status - **output_path** (string) - Path to the generated file ``` -------------------------------- ### Web Store Download Functionality (JavaScript) Source: https://github.com/explosion-scratch/to-userscript/blob/main/CLI_README.md Describes the JavaScript module responsible for downloading extensions from web stores for the `ext2us` project. This handles fetching extension files based on provided URLs or IDs. ```javascript src/cli/storeDownloader.js # Web store download functionality ``` -------------------------------- ### Implement Internationalization Source: https://context7.com/explosion-scratch/to-userscript/llms.txt Enables retrieval of localized strings from the _locales directory and detection of the current UI language. Supports message substitution for dynamic content. ```javascript const greeting = chrome.i18n.getMessage('greeting'); const welcome = chrome.i18n.getMessage('welcome_user', ['John']); const lang = chrome.i18n.getUILanguage(); ``` -------------------------------- ### Generated Userscript Format for Extension Porting Source: https://context7.com/explosion-scratch/to-userscript/llms.txt Illustrates the standard format of a userscript generated by the to-userscript tool. It includes essential userscript metadata and an IIFE containing polyfills and execution logic for porting browser extensions. ```javascript // ==UserScript== // @name Extension Name // @version 1.0.0 // @description Extension description from manifest // @namespace extension-id // @author Converter Script // @match *://*.example.com/* // @match *://example.org/* // @grant GM_getValue // @grant GM_setValue // @grant GM_xmlhttpRequest // @grant GM_openInTab // @grant GM_registerMenuCommand // @icon data:image/png;base64,... // @run-at document-start // ==/UserScript== (function() { 'use strict'; // 1. UNIFIED POLYFILL // - Messaging system (createEventBus, createRuntime) // - Abstraction layer (_storageSet, _storageGet, _fetch, _openTab) // - Asset management (EXTENSION_ASSETS_MAP, _createAssetUrl) // - Chrome API polyfill (chrome.*, browser.*) // 2. BACKGROUND SCRIPT ENVIRONMENT // - Executes background scripts immediately // - Maintains persistent state // 3. ORCHESTRATION LOGIC // - URL matching against content_scripts patterns // - Phased execution: document-start, document-end, document-idle // - CSS injection // - Options/Popup page modals (iframe-based) // - GM_registerMenuCommand for UI access })(); ``` -------------------------------- ### Workspace Management for Temporary Files (JavaScript) Source: https://github.com/explosion-scratch/to-userscript/blob/main/CLI_README.md Details the JavaScript module for managing temporary directories and files used during the extension conversion process in `ext2us`. This includes creation and cleanup of temporary workspaces. ```javascript src/cli/workspaceManager.js # Temporary directory management ``` -------------------------------- ### Extension Conversion Orchestration (JavaScript) Source: https://github.com/explosion-scratch/to-userscript/blob/main/CLI_README.md Explains the core JavaScript module that orchestrates the entire extension to userscript conversion process within the `ext2us` tool. It coordinates the various stages from input to output. ```javascript src/cli/extensionConverter.js # Conversion orchestration ``` -------------------------------- ### Download Extensions from Web Stores Source: https://context7.com/explosion-scratch/to-userscript/llms.txt Automates the retrieval of extension archives from the Chrome Web Store or Firefox Add-ons. Provides utilities to resolve direct download URLs and save the resulting files locally. ```javascript const { downloadExtension, getDownloadableUrl } = require('to-userscript/src/cli/download'); async function downloadFromStore() { const chromeSource = { type: 'chrome-store', url: 'https://chromewebstore.google.com/detail/json-formatter/bcjindcccaagfpapjjmafapmmgkkhgoa' }; try { const downloadUrl = await getDownloadableUrl(chromeSource); const downloadedPath = await downloadExtension(chromeSource, './downloads'); console.log('Downloaded to:', downloadedPath); return downloadedPath; } catch (error) { console.error('Download failed:', error.message); throw error; } } downloadFromStore(); ``` -------------------------------- ### Debug Extension Conversion (Bash) Source: https://github.com/explosion-scratch/to-userscript/blob/main/CLI_README.md Provides bash commands for debugging the extension to userscript conversion process. The `-v` flag enables maximum verbosity for detailed logging, and `--keep-temp` preserves temporary files for inspection. The `ls` command lists these temporary files. ```bash # Maximum verbosity ext2us convert extension.crx -v --keep-temp # Check temporary files ls /tmp/ext2us-* ``` -------------------------------- ### Userscript Structure and Execution Flow (JavaScript) Source: https://github.com/explosion-scratch/to-userscript/blob/main/README.md This JavaScript code snippet illustrates the typical structure of a userscript. It includes a metadata block, an Immediately Invoked Function Expression (IIFE) for scope isolation, and comments explaining the different sections: the unified polyfill, the background script environment, and the orchestration logic for content scripts. The orchestration logic handles script injection based on URL patterns and registers menu commands for options pages. ```javascript // ==UserScript== // ... Metadata Block ... // ==/UserScript== (function () { // IIFE for scope isolation "use strict"; // 1. UNIFIED POLYFILL is defined here // - messaging.template.js -> createEventBus, createRuntime // - abstractionLayer.*.template.js -> _storageSet, _fetch, etc. // - assetsGenerator code -> EXTENSION_ASSETS_MAP, _createAssetUrl // - polyfill.template.js -> buildPolyfill() which creates chrome.* // 2. BACKGROUND SCRIPT ENVIRONMENT is defined and executed // - Runs all background scripts inside the polyfill's scope. // - This happens immediately on script start. // 3. ORCHESTRATION LOGIC is defined and executed // - Checks if location.href matches a content_script pattern. // - If it matches: // - Calls `executeAllScripts()`. // - This function injects CSS and runs JS in phases: // - document-start // - document-end // - document-idle // - Registers GM_registerMenuCommand for options/popup pages. // - Options/Popup pages are rendered in a modal with an iframe. // - The iframe's content is populated with the inlined HTML and // a specialized 'postmessage' version of the polyfill. })(); ``` -------------------------------- ### Register Context Menu Commands Source: https://context7.com/explosion-scratch/to-userscript/llms.txt Emulates the chrome.contextMenus API using userscript manager features like GM_registerMenuCommand. Allows developers to create, update, and remove context-sensitive menu items. ```javascript const menuId = chrome.contextMenus.create({ id: 'my-menu-item', title: 'Process Selected Text', contexts: ['selection'], onclick: (info, tab) => console.log(info.selectionText) }); chrome.contextMenus.update('my-menu-item', { title: 'Process Text (Updated)' }); chrome.contextMenus.removeAll(); ``` -------------------------------- ### Convert Extension to Userscript Source: https://context7.com/explosion-scratch/to-userscript/llms.txt The convertExtension function programmatically transforms an unpacked browser extension directory into a userscript file. It accepts a configuration object for paths and settings, returning detailed conversion statistics and metadata. ```javascript const { convertExtension } = require('to-userscript/src/convert'); const path = require('path'); async function convertMyExtension() { try { const result = await convertExtension({ inputDir: path.resolve('./my-extension'), outputFile: path.resolve('./output/my-script.user.js'), target: 'userscript', locale: 'en', ignoredAssets: 'mp4,webm,ttf,woff2' }); console.log('Conversion successful!'); console.log(`Extension: ${result.extension.name} v${result.extension.version}`); return result; } catch (error) { console.error('Conversion failed:', error.message); throw error; } } convertMyExtension(); ``` -------------------------------- ### Generated Userscript Architecture Template Source: https://github.com/explosion-scratch/to-userscript/blob/main/docs/architecture.md The structural blueprint for the final userscript output. It demonstrates the IIFE scope isolation, the integration of polyfills, the background script environment, and the orchestration logic for phased script execution. ```javascript // ==UserScript== // ... Metadata Block ... // ==/UserScript== (function() { // IIFE for scope isolation 'use strict'; // 1. UNIFIED POLYFILL is defined here // - messaging.template.js -> createEventBus, createRuntime // - abstractionLayer.*.template.js -> _storageSet, _fetch, etc. // - assetsGenerator code -> EXTENSION_ASSETS_MAP, _createAssetUrl // - polyfill.template.js -> buildPolyfill() which creates chrome.* // 2. BACKGROUND SCRIPT ENVIRONMENT is defined and executed // - Runs all background scripts inside the polyfill's scope. // - This happens immediately on script start. // 3. ORCHESTRATION LOGIC is defined and executed // - Checks if location.href matches a content_script pattern. // - If it matches: // - Calls `executeAllScripts()`. // - This function injects CSS and runs JS in phases: // - document-start // - document-end // - document-idle // - Registers GM_registerMenuCommand for options/popup pages. // - Options/Popup pages are rendered in a modal with an iframe. // - The iframe's content is populated with the inlined HTML and // a specialized 'postmessage' version of the polyfill. })(); ``` -------------------------------- ### Advanced Polyfilling with Proxy and 'with' Statement (JavaScript) Source: https://github.com/explosion-scratch/to-userscript/blob/main/docs/article.md This JavaScript snippet illustrates a more advanced technique for polyfilling browser APIs using a Proxy object and the 'with' statement. The Proxy intercepts property access and assignments, directing them to a custom storage object. The 'with' statement then allows the enclosed code to execute within this polyfilled scope, enabling assignments like 'ExtPay = {}' to work correctly. ```javascript let customStorage = { chrome: /* ... */, browser: /* ... */, }; new Proxy(target, { set(target, prop, value) { customStorage[prop] = value; return Reflect.set(target, prop, value); }, get(target, prop) { return customStorage[prop] || Reflect.get(target, prop); } }); /* Now code can run in the polyfilled scope: */ with (polyfill) { /* // Yay it works!! ExtPay = {} */ } ``` -------------------------------- ### Initial Attempt: Polyfilling Chrome API in a Function Scope (JavaScript) Source: https://github.com/explosion-scratch/to-userscript/blob/main/docs/article.md This JavaScript code represents an early attempt to polyfill browser-specific APIs like 'chrome' and 'browser' within a function scope. While it allows access to these variables, it does not correctly support assigning new properties to them, such as 'ExtPay = {}', as the assignments remain local to the function. ```javascript function runAllTheCode({chrome, browser, window, this, self, ...etc}){ /* Code that goes here can now access the various things I may want to polyfill, but if there's a library like the following, it won't work: ExtPay = { } -> Now that assignment is still only local to this function */ } ``` -------------------------------- ### Manage Extension Runtime and Messaging Source: https://context7.com/explosion-scratch/to-userscript/llms.txt Provides access to manifest data, asset URL resolution, and cross-context messaging. It supports asynchronous communication between background scripts and content scripts using the chrome.runtime API. ```javascript const manifest = chrome.runtime.getManifest(); console.log(`Running ${manifest.name} v${manifest.version}`); const iconUrl = chrome.runtime.getURL('icons/icon48.png'); chrome.runtime.sendMessage({ action: 'getData', key: 'user' }, (response) => { if (chrome.runtime.lastError) return; console.log('Received:', response); }); chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { if (message.action === 'getData') { fetchData(message.key).then(data => sendResponse({ data })); return true; } sendResponse({ status: 'ok' }); }); ``` -------------------------------- ### Create Browser Notifications Source: https://context7.com/explosion-scratch/to-userscript/llms.txt Wraps the Web Notifications API to provide a consistent interface for creating, managing, and clearing browser notifications. Includes permission level checking. ```javascript const notificationId = await chrome.notifications.create({ type: 'basic', iconUrl: chrome.runtime.getURL('icons/notification.png'), title: 'Update Available', message: 'A new version is ready to install.' }); await chrome.notifications.clear('custom-id'); ``` -------------------------------- ### Input Validation for Extension Conversion (JavaScript) Source: https://github.com/explosion-scratch/to-userscript/blob/main/CLI_README.md Details the input validation module for the `ext2us` tool, written in JavaScript. This component is responsible for detecting and validating the type of input provided for extension conversion. ```javascript src/cli/inputValidator.js # Input type detection and validation ``` -------------------------------- ### Polyfilled chrome.storage API Source: https://context7.com/explosion-scratch/to-userscript/llms.txt Provides a persistent storage interface compatible with userscript environments. It maps storage operations to GM_* functions or IndexedDB, supporting both asynchronous Promise patterns and event listeners. ```javascript await chrome.storage.local.set({ settings: { darkMode: true }, lastUpdated: Date.now() }); const result = await chrome.storage.local.get({ settings: { darkMode: false } }); chrome.storage.onChanged.addListener((changes, areaName) => { console.log(`Storage area "${areaName}" changed:`, changes); }); await chrome.storage.sync.set({ syncedPref: 'value' }); ``` -------------------------------- ### Archive Extraction for Extensions (JavaScript) Source: https://github.com/explosion-scratch/to-userscript/blob/main/CLI_README.md Highlights the JavaScript module dedicated to extracting extension archives (CRX, XPI, ZIP) within the `ext2us` project. This is a crucial step before the conversion process can begin. ```javascript src/cli/archiveExtractor.js # Archive extraction (CRX/XPI/ZIP) ``` -------------------------------- ### CRX URL Generation for Downloads (JavaScript) Source: https://github.com/explosion-scratch/to-userscript/blob/main/CLI_README.md Describes the JavaScript module responsible for generating the correct URLs for downloading CRX files in the `ext2us` project. This is essential for fetching extensions from sources that provide CRX packages. ```javascript src/cli/downloadExt.js # CRX URL generation ``` -------------------------------- ### Manage Browser Tabs Source: https://context7.com/explosion-scratch/to-userscript/llms.txt Facilitates basic tab operations such as creating new tabs, querying active tab information, and sending messages to specific tabs. This implementation is constrained by the limitations of the userscript environment. ```javascript const newTab = await chrome.tabs.create({ url: 'https://example.com', active: true }); const tabs = await chrome.tabs.query({ active: true, currentWindow: true }); await chrome.tabs.sendMessage(tabs[0].id, { action: 'highlight' }); ``` -------------------------------- ### Generate Userscript @require Metadata Source: https://context7.com/explosion-scratch/to-userscript/llms.txt Generates a standard userscript metadata block containing a @require directive. This is useful for linking external userscript files as dependencies. ```javascript const { generateRequireBlock } = require('to-userscript/src/cli/require'); async function createRequireBlock() { try { const metadataBlock = await generateRequireBlock('./my-library.user.js'); console.log(metadataBlock); return metadataBlock; } catch (error) { console.error('Error generating metadata:', error.message); throw error; } } createRequireBlock(); ``` -------------------------------- ### chrome.cookies API Source: https://context7.com/explosion-scratch/to-userscript/llms.txt Endpoints and methods for interacting with browser cookies, including retrieval, modification, and event listening. ```APIDOC ## chrome.cookies.get ### Description Retrieves a single cookie by name for a specific URL. ### Method GET ### Parameters #### Request Body - **url** (string) - Required - The URL with which the cookie to be retrieved is associated. - **name** (string) - Required - The name of the cookie to get. ### Response #### Success Response (200) - **cookie** (object) - The cookie object containing value, domain, path, and expirationDate. --- ## chrome.cookies.getAll ### Description Retrieves all cookies for a given URL. ### Method GET ### Parameters #### Request Body - **url** (string) - Required - The URL to retrieve cookies for. ### Response #### Success Response (200) - **cookies** (array) - A list of cookie objects. --- ## chrome.cookies.set ### Description Sets a cookie with the specified parameters. ### Method POST ### Parameters #### Request Body - **url** (string) - Required - The URL to associate the cookie with. - **name** (string) - Required - The name of the cookie. - **value** (string) - Required - The value of the cookie. - **expirationDate** (number) - Optional - The expiration date in seconds since the epoch. --- ## chrome.cookies.remove ### Description Deletes a cookie by name. ### Method DELETE ### Parameters #### Request Body - **url** (string) - Required - The URL associated with the cookie. - **name** (string) - Required - The name of the cookie to remove. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.