This Chrome extension shortens URLs when copied and provides a simple interface to manually shorten the current tab's URL.
my-url-shortener-extension/
├── manifest.json
├── background.js
├── content.js
├── redirect.html
├── redirect.js
├── popup.html
├── popup.js
├── options.html
└── options.js
-
Clone or download the repository to your local machine.
-
Open Google Chrome and go to
chrome://extensions/
. -
Enable "Developer mode" by toggling the switch in the top right corner.
-
Click on "Load unpacked" and select the directory containing the extension files (
my-url-shortener-extension
). -
The extension should now appear in your list of extensions.
-
Copy Event Handling: The content script (
content.js
) listens for copy events. If the copied text is a URL, it sends a message to the background script to shorten the URL and replaces the clipboard content with the shortened URL. -
Interception and Storage: The background script (
background.js
) listens for URL shortening requests, generates a short URL key using a counter, and stores the mapping between the short URL and the original URL in Chrome's local storage. -
Redirection Handling: The redirection page (
redirect.html
andredirect.js
) handles the redirection from the shortened URL to the original URL by reading thekey
parameter from the URL and looking up the original URL in Chrome's local storage.
The popup interface (popup.html
and popup.js
) provides a simple button to manually shorten the URL of the current tab. The shortened URL is displayed in the popup.
Defines the extension's metadata and permissions.
Handles URL shortening requests and stores the mappings between shortened URLs and original URLs in Chrome's local storage.
Listens for copy events and sends messages to the background script to shorten URLs.
Displays a message while redirecting to the original URL.
Handles the redirection from the shortened URL to the original URL by looking up the key in Chrome's local storage.
Defines the HTML for the extension's popup interface.
Provides functionality for the popup interface to shorten the URL of the current tab and display the shortened URL.
Currently, these files provide a basic structure for the options page but have no additional options to configure.
- Enhance the URL shortening algorithm to handle collisions and ensure uniqueness.
- Add configurable options for users to customize the extension's behavior.
- Implement error handling and user feedback for cases where URL shortening or redirection fails.
Contributions are welcome! Feel free to submit issues or pull requests to improve the extension.
This project is licensed under the MIT License.