微博编辑记录对比

查看微博编辑记录比对上下文修改

目前为 2023-09-04 提交的版本。查看 最新版本

// ==UserScript==
// @name         微博编辑记录对比
// @version      1.1.2
// @match        https://weibo.com/*
// @namespace    weibo-diff
// @run-at       document-start
// @description  查看微博编辑记录比对上下文修改
// @author       C-racker
// @grant        unsafeWindow
// @require      https://cdn.bootcdn.net/ajax/libs/jsdiff/5.1.0/diff.min.js
// @license MIT
// ==/UserScript==

(function () {
  const originOpen = XMLHttpRequest.prototype.open;
  XMLHttpRequest.prototype.open = function (_, url) {
    if (/\/ajax\/statuses\/editHistory/.test(url)) {
      const xhr = this;
      const getter = Object.getOwnPropertyDescriptor(
        XMLHttpRequest.prototype,
        "response"
      ).get;
      Object.defineProperty(xhr, "responseText", {
        get: () => {
          let result = getter.call(xhr);
          try {
            const _res = JSON.parse(result);
            const res = JSON.parse(result);
            for (let i = _res.statuses.length - 1; i >= 0; i--) {
              if (i === 0 || !_res.statuses[i].cardid) {
                break;
              }
              let text = "";
              const diff = Diff.diffChars(
                _res.statuses[i].text,
                _res.statuses[i - 1].text
              );
              diff.forEach((part) => {
                text += part.added
                  ? `<span style="color:green">${part.value}</span>`
                  : part.removed
                  ? `<span style="color:red">${part.value}</span>`
                  : part.value;
              });
              res.statuses[i - 1].text = text;
            }
            return JSON.stringify(res);
          } catch (e) {
            return result;
          }
        },
      });
    }
    originOpen.apply(this, arguments);
  };
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址