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

Code before:
                    // but some room is required for longer sharing device names.
                    params.body = [
                        title,
                        deviceID.replace(/-/g, ''),
                        footer
                    ].join('\n\n');
                    break;
                default:
            }
            $scope.shareDeviceParams = params;
            $('#share-device-confirmation').modal('show');
        };

        $scope.shareDevice = function () {
            switch ($scope.shareDeviceParams.type) {
                case 'email':
                    location.href = 'mailto:?subject=' + encodeURIComponent($scope.shareDeviceParams.subject) + '&body=' + encodeURIComponent($scope.shareDeviceParams.body);
                    break;
                case 'sms':
                    location.href = 'sms://;?&body=' + encodeURIComponent($scope.shareDeviceParams.body);
                    break;
                default:
            }
        }

        $scope.showTooltip = function (newTooltip) {
            var e = event.currentTarget;
            var oldTooltip = e.getAttribute('data-original-title');

            e.setAttribute('data-original-title', newTooltip);
            $(e).tooltip('show');
            if (oldTooltip) {
                e.setAttribute('data-original-title', oldTooltip);
            } else {
                e.removeAttribute('data-original-title');
            }
        };

        $scope.copyToClipboard = function (content) {
            var success = $translate.instant("Copied to clipboard!");
            var failure = $translate.instant("Failed to copy to clipboard!");
            var message = success;

            if (navigator.clipboard && navigator.clipboard.writeText) {
                // Default for modern browsers on localhost or HTTPS.
                navigator.clipboard.writeText(content);
            } else if (window.clipboardData && window.clipboardData.setData) {
                // Fallback for Internet Explorer.
                window.clipboardData.setData('Text', content);
            } else if (document.queryCommandSupported) {
                // Fallback for modern browsers on HTTP and non-IE old browsers.

Review comment (suggestion):
This deserves a comment what it does and why a simple `alert()` won't do it.  I had to research a bit, didn't know that it's a no-op on Android WebView for example.

Code after:
            }
            return translation;
        };

        $scope.modalLoaded = function () {
            // once all modal elements have been processed
            if ($('modal').length === 0) {
                // pseudo main. called on all definitions assigned
                initController();
            }
        };

        $scope.toggleUnits = function () {
            $scope.metricRates = !$scope.metricRates;
            try {
                window.localStorage["metricRates"] = $scope.metricRates;
            } catch (exception) { }
        };

        $scope.sizeOf = function (dict) {
            if (dict === undefined) {
                return 0;
            }
            return Object.keys(dict).length;
        };

        $scope.has = function (array, element) {
            return array.indexOf(element) >= 0;
        };

        $scope.dismissNotification = function (id) {
            var idx = $scope.config.options.unackedNotificationIDs.indexOf(id);
            if (idx > -1) {
                $scope.config.options.unackedNotificationIDs.splice(idx, 1);
                $scope.saveConfig();
            }
        };

        $scope.abbreviatedError = function (addr) {
            var status = $scope.system.lastDialStatus[addr];
            if (!status || !status.error) {
                return null;
            }
            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();