来个 js 的,好像还有点问题
```js
// ==UserScript==
// @
name New Userscript
// @
namespace http://tampermonkey.net/// @
version 0.1
// @
description try to take over the world!
// @
author You
// @
match https://v2ex.com/*// @
icon https://www.google.com/s2/favicons?sz=64&domain=v2ex.com// @
grant GM_xmlhttpRequest
// ==/UserScript==
(function () {
"use strict";
let avatar = document.getElementsByClassName("avatar");
for (let index = 0; index < avatar.length; index++) {
let item = avatar[index];
GM_xmlhttpRequest({
method: "GET",
responseType: "blob",
url: item.src,
onload: function (response) {
if (response.status === 200) {
new Promise((resolve, reject) => {
let reader = new FileReader();
reader.addEventListener("load", () => {
let img = new Image();
img.setAttribute("crossOrigin", "anonymous");
img.src = reader.result;
img.addEventListener("load", () => resolve(img));
});
reader.readAsDataURL(response.response);
}).then((img) => getImageData(item, img));
}
},
});
}
function getImageData(item, img) {
let canvas = document.createElement("canvas");
canvas.setAttribute("width", `${item.width}px`);
canvas.setAttribute("height", `${item.height}px`);
var ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0, item.width, item.height);
let imgData = ctx.getImageData(
item.width / 4,
item.height / 4,
item.width / 2,
item.height / 2
);
let map = new Map();
for (let i = 0; i < imgData.data.length; i += 4) {
let r = imgData.data[i];
let g = imgData.data[i + 1];
let b = imgData.data[i + 2];
// let a
let rgb = `${r},${g},${b}`;
if (!map.has(rgb)) {
map.set(rgb, 1);
} else {
map.set(rgb, map.get(rgb) + 1);
}
}
// 寻找最大值
let maxValue = 0;
let color = "";
map.forEach((value, key) => {
if (value > maxValue) {
maxValue = value;
color = key;
}
});
if (color == "255,201,169") {
console.log("隐藏丑丑头像!");
item.style.display = "none";
}
}
})();
```