User:Robertsky/edit-check-optin.js

Source: Wikipedia, the free encyclopedia.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
$('a[href*="veaction=edit"]:not([href*="veaction=editsource"])').each(function() {
    var href = $(this).attr('href');

    // Check if the URL is in the article namespace (doesn't start with "Special:", "User:", etc.)
    if (href.match(/\/w\/index\.php\?title=[^:]*&veaction=edit/)) {
        if (href.indexOf('?') !== -1) {
            // If the link already has a query string, append the parameter with '&'
            href += '&ecenable=1';
        } else {
            // If the link doesn't have a query string, append the parameter with '?'
            href += '?ecenable=1';
        }
        $(this).attr('href', href);
    }
});