ArticleZip > Get Subdomain And Load It To Url With Greasemonkey

Get Subdomain And Load It To Url With Greasemonkey

If you're looking to enhance your browsing experience and streamline the way you access certain websites, using Greasemonkey scripts can be a game-changer. Today, we'll delve into a clever script that allows you to automatically add a subdomain to specific URLs using Greasemonkey.

### What You'll Need:
- **Greasemonkey Extension:** Before diving into the script, make sure you have Greasemonkey installed on your browser. It's available for popular browsers like Chrome and Firefox.
- **Desired Subdomain:** Decide on the subdomain you'd like to append to specific URLs for quick access.

### The Script:
Below is the script that, when configured correctly, will automatically add the chosen subdomain to URLs you specify. Let's break it down step by step:

Javascript

// ==UserScript==
// @name         Add Subdomain to URLs
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Add a custom subdomain to specified URLs
// @author       Your Name
// @match        http://*/*    <-- Edit this line to specify the URLs
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    var desiredSubdomain = 'subdomain'; // Change 'subdomain' to your preferred subdomain

    var currentUrl = window.location.href;
    var newUrl = currentUrl.replace('http://', 'http://' + desiredSubdomain + '.');

    window.location.href = newUrl;
})();

### How to Use the Script:
1. **Script Setup:** Copy the script above and paste it into a new script in your Greasemonkey dashboard.
2. **Customization:** Replace `'subdomain'` with the subdomain you wish to add.
3. **URL Matching:** Update the `@match` line to define the URLs where you want the subdomain to be added.
4. **Save & Apply:** Save the script, and Greasemonkey will automatically apply it to the specified URLs.

### Script Explanation:
- The script begins with setting up the metadata for the user script.
- It then defines the desired subdomain and fetches the current URL.
- Next, it appends the specified subdomain to the URL.
- Finally, it redirects the browser to the new URL with the added subdomain.

### Benefits:
By using this script, you can save time and effort by skipping the manual process of typing the subdomain each time you visit your favorite sites. Whether it's for testing, accessing development environments, or any other purpose, this script can make your browsing experience more efficient.

### Conclusion:
With Greasemonkey's flexibility and the simple but effective script provided here, you can easily enhance your browsing workflow by automatically adding a subdomain to specific URLs. Take advantage of this powerful tool to customize your web experience and increase your productivity.

Give this script a try and enjoy the convenience of instant subdomain addition to your URLs!

×