微博编辑记录对比

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

目前為 2023-09-04 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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);
  };
})();