MCPcopy Index your code
hub / github.com/zxlie/FeHelper / _addOptForItem

Function _addOptForItem

apps/json-format/format-lib.js:890–962  ·  view source on GitHub ↗
(el, show)

Source from the content-addressed store, hash-verified

888
889 // 给某个节点增加操作项
890 let _addOptForItem = function (el, show) {
891 if (!statusBarEnabled) {
892 show = false;
893 }
894
895 // 下载json片段
896 let fnDownload = function (event) {
897 event.stopPropagation();
898
899 let txt = getJsonText(el);
900 // 下载片段
901 let dt = (new Date()).format('yyyyMMddHHmmss');
902 let blob = new Blob([txt], {type: 'application/octet-stream'});
903
904 if (typeof chrome === 'undefined' || !chrome.permissions) {
905 // 下载JSON的简单形式
906 $(this).attr('download', 'FeHelper-' + dt + '.json').attr('href', URL.createObjectURL(blob));
907 } else {
908 // 请求权限
909 chrome.permissions.request({
910 permissions: ['downloads']
911 }, (granted) => {
912 if (granted) {
913 chrome.downloads.download({
914 url: URL.createObjectURL(blob),
915 saveAs: true,
916 conflictAction: 'overwrite',
917 filename: 'FeHelper-' + dt + '.json'
918 });
919 } else {
920 toast('必须接受授权,才能正常下载!');
921 }
922 });
923 }
924
925 };
926
927 // 复制json片段
928 let fnCopy = function (event) {
929 event.stopPropagation();
930 _copyToClipboard(getJsonText(el));
931 };
932
933 // 删除json片段
934 let fnDel = function (event) {
935 event.stopPropagation();
936 if (el.parent().is('#formattedJson')) {
937 toast('如果连最外层的Json也删掉的话,就没啥意义了哦!');
938 return false;
939 }
940 toast('节点已删除成功!');
941 el.remove();
942 jfStatusBar && jfStatusBar.hide();
943 };
944
945 $('.boxOpt').hide();
946 if (show) {
947 let jfOptEl = el.children('.boxOpt');

Callers 2

_selectJsonElementFunction · 0.85
_addEventsFunction · 0.85

Calls 3

hideMethod · 0.80
showMethod · 0.80
$Function · 0.50

Tested by

no test coverage detected