Repository: syncthing/syncthing
File: gui/default/syncthing/core/syncthingController.js (JavaScript)

Code before:
            var time = $filter('date')(status.when, "HH:mm:ss")
            var err = status.error.replace(/.+: /, '');
            return err + " (" + time + ")";
        };

        $scope.setCrashReportingEnabled = function (enabled) {
            $scope.config.options.crashReportingEnabled = enabled;
            $scope.saveConfig();
        };

        $scope.isUnixAddress = function (address) {
            return address != null &&
                (address.indexOf('/') == 0 ||
                    address.indexOf('unix://') == 0 ||
                    address.indexOf('unixs://') == 0);
        };

        $scope.copyToClipboard = function (event, text) {
            console.log(text);
            var success = $translate.instant("Copied to clipboard!");
            var failure = $translate.instant("Copy to clipboard failed!");

            if (navigator.clipboard && navigator.clipboard.writeText) {
                // Default for modern browsers on localhost or HTTPS.
                navigator.clipboard.writeText(text);
                return alert(success);
            } else if (window.clipboardData && window.clipboardData.setData) {
                // Fallback for Internet Explorer.
                window.clipboardData.setData('Text', text);
                return alert(success);
            } else if (document.queryCommandSupported) {
                // Fallback for modern browsers on HTTP and non-IE old browsers.
                // Check for document.queryCommandSupported("copy") support is
                // omitted on purpose, as old Chrome versions reported "false"
                // despite supporting the feature.
                var textarea = document.createElement("textarea");
                event.currentTarget.appendChild(textarea);
                textarea.style.position = "fixed";
                textarea.style.opacity = "0";
                textarea.textContent = text;
                textarea.select();
                try {
                    document.execCommand("copy");
                    return alert(success);
                }
                catch (ex) {
                    return alert(failure);
                }
                finally {
                    event.currentTarget.removeChild(textarea);
                }

Review comment (bug):
`alert()` doesn't have a return value.  You can get rid of all the `return` statements altogether by moving the final `alert(failure);` to another `else` branch.

In fact, since you call `alert()` in any case, I'd recommend setting a `var msg = success;` once at the top and calling `alert(msg);` once before leaving the function.  Then only in the failure cases you overwrite it with `msg = failure;`.  That should shave off a few lines in total.

Code after:
            if (!$scope.version.version) {
                return '';
            }
            var version = $scope.version.version;
            var pos = version.indexOf('-');
            if (pos > 0) {
                version = version.slice(0, pos);
            }
            return version;
        };

        $scope.docsURL = function (path) {
            var url = 'https://docs.syncthing.net';
            if (!path) {
                // Undefined or null should become a valid string.
                path = '';
            }
            var hash = path.indexOf('#');
            if (hash != -1) {
                url += '/' + path.slice(0, hash);
                url += '?version=' + $scope.versionBase();
                url += path.slice(hash);
            } else {
                url += '/' + path;
                url += '?version=' + $scope.versionBase();
            }
            return url;
        };

        $scope.inputTypeFor = function (key, value) {
            if (key.substr(0, 1) === '_') {
                return 'skip';
            }
            if (value === null) {
                return 'null';
            }
            if (typeof value === 'number') {
                return 'number';
            }
            if (typeof value === 'boolean') {
                return 'checkbox';
            }
            if (value instanceof Array) {
                return 'list';
            }
            if (typeof value === 'object') {
                return 'skip';
            }
            return 'text';
        };