Userscript to redirect insecure pages to HTTPS
Overview


Pass global variables as parameters to IIFE to make your code more independent and clear
Use addEventListener method to follow recommended way of attaching event listeners
Do you really need to execute redirection code, only when everything is loaded? 
I would use regex to replace protocol to make solution robust
Try to not duplicate constant values (in this case protocol)


Suggested solution

(function (w) {
    'use strict';

    var secureProtocol = 'https';

    if ( !w.location.protocol.startsWith(secureProtocol) ) {
        w.location.href = w.location.href.replace(/^[^:]+/, secureProtocol);
    }
})(window);