(source)
| 1413 | * @returns |
| 1414 | */ |
| 1415 | let _formatTheSource = function (source) { |
| 1416 | let jsonObj = _getJsonObject(source); |
| 1417 | |
| 1418 | // 是json格式,可以进行JSON自动格式化 |
| 1419 | if (jsonObj != null && typeof jsonObj === "object") { |
| 1420 | |
| 1421 | // 提前注入css |
| 1422 | _injectContentCss(); |
| 1423 | |
| 1424 | // JSON的所有key不能超过预设的值,比如 10000 个,要不然自动格式化会比较卡 |
| 1425 | if (formatOptions['MAX_JSON_KEYS_NUMBER']) { |
| 1426 | let keysCount = _getAllKeysCount(jsonObj); |
| 1427 | if (keysCount > formatOptions['MAX_JSON_KEYS_NUMBER']) { |
| 1428 | let msg = '当前JSON共 <b style="color:red">' + keysCount + '</b> 个Key,大于预设值' + formatOptions['MAX_JSON_KEYS_NUMBER'] + ',已取消自动格式化;可在FeHelper设置页的「JSON 自动格式化 Key 数上限」中调整此配置!'; |
| 1429 | return toast(msg); |
| 1430 | } |
| 1431 | } |
| 1432 | |
| 1433 | document.documentElement.classList.add('fh-jf'); |
| 1434 | _mountFormatterShell(); |
| 1435 | |
| 1436 | formatOptions.originalSource = _stringifyJsonForFormatter(jsonObj); |
| 1437 | |
| 1438 | // 确保从storage加载最新设置 |
| 1439 | _getAllOptions(options => { |
| 1440 | _extendsOptions(options); |
| 1441 | _bindDarkModePreferenceListener(); |
| 1442 | _initToolbar(); |
| 1443 | _didFormat(); |
| 1444 | }); |
| 1445 | } |
| 1446 | }; |
| 1447 | |
| 1448 | /** |
| 1449 | * 执行format操作 |
no test coverage detected