查看微博编辑记录比对上下文修改
// ==UserScript==
// @name 微博编辑记录对比
// @version 1.1.3
// @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) {
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);
};
})();