+/**
+ * Default all URL inputs to https if scheme not specified,
+ * and set a flag if that happened.
+ * From https://aaronparecki.com/2019/05/13/2/https
+ */
+function indieAuthURLTrySecureFirstScript(ctx, options) {
+ const showIndieAuthForm = options.authnEnabled.includes('indieAuth');
+ return showIndieAuthForm ? `
+<script>
+document.addEventListener('DOMContentLoaded', function() {
+ function addDefaultScheme(target) {
+ if (target.value.match(/^(?!https?:).+\\..+/)) {
+ const autoSchemeField = document.querySelector('input[name=' + target.getAttribute('name') + '_auto_scheme]');
+ let scheme;
+ if (autoSchemeField) {
+ scheme = 'https://';
+ autoSchemeField.value = '1';
+ } else {
+ scheme = 'http://';
+ }
+ target.value = scheme + target.value;
+ }
+ }
+ const elements = document.querySelectorAll('input[type=url]');
+ Array.prototype.forEach.call(elements, function (el, i) {
+ el.addEventListener('blur', function(e) {
+ addDefaultScheme(e.target);
+ });
+ el.addEventListener('keydown', function(e) {
+ if (e.keyCode === 13) {
+ addDefaultScheme(e.target);
+ }
+ });
+ });
+});
+</script>` : '';
+}
+