()
| 1103 | }; |
| 1104 | |
| 1105 | let _didFormat = function () { |
| 1106 | let source = formatOptions.originalSource; |
| 1107 | |
| 1108 | if (formatOptions.sortType !== 0) { |
| 1109 | let parsed = _parseJsonLike(formatOptions.originalSource); |
| 1110 | let jsonObj = JsonABC.sortObj(parsed.value, parseInt(formatOptions.sortType), true); |
| 1111 | source = _stringifyJsonForFormatter(jsonObj); |
| 1112 | } |
| 1113 | |
| 1114 | let elBody = $('body'); |
| 1115 | |
| 1116 | let theme = _getResolvedTheme(); |
| 1117 | Object.values(SKIN_THEME).forEach(th => elBody.removeClass(th)); |
| 1118 | elBody.addClass(theme); |
| 1119 | _applyUiMode(); |
| 1120 | _applyCompactMode(); |
| 1121 | |
| 1122 | // 控制引号 |
| 1123 | if (formatOptions.KEEP_KEY_VALUE_DBL_QUOTE) { |
| 1124 | elBody.removeClass('remove-quote'); |
| 1125 | } else { |
| 1126 | elBody.addClass('remove-quote'); |
| 1127 | } |
| 1128 | |
| 1129 | // 控制底部状态栏 |
| 1130 | _syncFormatterStatusBarState(); |
| 1131 | |
| 1132 | // 检查是否在受限域名,直接使用同步模式 |
| 1133 | const currentUrl = window.location.href; |
| 1134 | const restrictedDomains = ['gitee.com', 'github.com', 'raw.githubusercontent.com']; |
| 1135 | const isRestrictedDomain = restrictedDomains.some(domain => currentUrl.includes(domain)); |
| 1136 | |
| 1137 | if (isRestrictedDomain) { |
| 1138 | console.log('检测到受限域名,直接使用同步模式'); |
| 1139 | (async () => { |
| 1140 | source = await _prepareSourceForFormatter(source); |
| 1141 | Formatter.formatSync(source, theme, formatOptions.NESTED_ESCAPE_PARSE); |
| 1142 | _syncFormatterStatusBarState(); |
| 1143 | $('#jfToolbar').show(); |
| 1144 | })(); |
| 1145 | } else { |
| 1146 | (async () => { |
| 1147 | source = await _prepareSourceForFormatter(source); |
| 1148 | // 格式化 |
| 1149 | try { |
| 1150 | await Formatter.format(source, theme, formatOptions.NESTED_ESCAPE_PARSE); |
| 1151 | } catch (e) { |
| 1152 | console.warn('异步格式化失败,使用同步模式:', e); |
| 1153 | Formatter.formatSync(source, theme, formatOptions.NESTED_ESCAPE_PARSE); |
| 1154 | } |
| 1155 | _syncFormatterStatusBarState(); |
| 1156 | $('#jfToolbar').show(); |
| 1157 | })(); |
| 1158 | } |
| 1159 | |
| 1160 | |
| 1161 | // 如果是JSONP格式的,需要把方法名也显示出来 |
| 1162 | if (funcName != null) { |
no test coverage detected