Greasy Fork is available in English.

Redirect .org to .com

Automatically redirects .org websites to their .com version if available

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Redirect .org to .com
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Automatically redirects .org websites to their .com version if available
// @author       Your Name
// @match        *://*.org/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // List of .org sites you don't want to redirect
    const exceptions = [
        'wikipedia.org',
        'archive.org',
        'mozilla.org'
    ];

    // Function to check if a site is an exception
    function isException(hostname) {
        return exceptions.some(exception => hostname.endsWith(exception));
    }

    // Function to log redirection details
    function logRedirection(from, to) {
        console.log(`Redirecting from ${from} to ${to}`);
    }

    // Get the current hostname (e.g., 'example.org')
    const currentHost = window.location.hostname;

    // Check if it's an exception or already on .com
    if (currentHost.endsWith('.org') && !isException(currentHost)) {
        // Replace .org with .com
        const newHost = currentHost.replace('.org', '.com');

        // Log redirection details
        logRedirection(currentHost, newHost);

        // Redirect to the new .com domain
        window.location.href = window.location.href.replace(currentHost, newHost);
    } else {
        // Log when no redirection occurs
        console.log(`No redirection for ${currentHost}`);
    }
})();