燕谷坊来店易API去除result后面的双引号

去除JSON字符串Result标签后的双引号包裹

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         燕谷坊来店易API去除result后面的双引号
// @namespace    http://tampermonkey.net/
// @version      0.2.2
// @description  去除JSON字符串Result标签后的双引号包裹
// @author       djzhao
// @match        *://*.hulianjun.com/*
// @match        http://127.0.0.1/*
// @create       2019-05-31
// @grant        none
// @icon         https://avatars1.githubusercontent.com/u/10238070?s=460&v=4
// @run-at       document-end
// ==/UserScript==

(function() {// {"Code":"000","Message":"操作成功!","Result":{"promotionCount":1}}
    'use strict';
    var tag = document.getElementsByTagName('pre')[0];
    if (tag == null)
        return;
    var _html = tag.innerText;
    // 确定是JSON数据
    if (_html.lenght != 0 && _html.indexOf('{"Code":"') == 0) {
        // 去除 "
        _html = _html.replace('"Result":"{','"Result":{');
        // 去除 "
        _html = _html.replace(/}"}$/,'}}');
        // \" 转为 "
        _html = _html.replace(new RegExp('\\\\"',"gm"),'"');
        // 保留转移字符 \\ 转为 \
        _html = _html.replace(new RegExp('\\\\\\\\',"gm"),'\\');
    }
    tag.innerText = _html;
})();