// ==UserScript==
// @name Algorithm game
// @namespace http://tampermonkey.net/
// @version 2024-08-28
// @description try to take over the world!
// @author You
// @match https://forum.agoraroad.com/index.php?threads/game-the-algorithm-the-game.*
// @icon https://www.google.com/s2/favicons?sz=64&domain=agoraroad.com
// @grant none
// ==/UserScript==
(function() {
let c = document.createElement("canvas");
let ctx = c.getContext("2d");
let imgs = document.querySelectorAll(".message-body img.bbImage");
function Calc_Rating(img_id){
let img = imgs[img_id];
let running_total;
if (img.src.includes("forum.agoraroad") ){
c.width = img.width;
c.height = img.height;
ctx.drawImage(img,0,0);
let data = ctx.getImageData(0,0,c.width,c.height);
data = data.data;
let pixel_count = 0;
running_total = 0;
for (let i = 0; i < data.length; i+=4){
let R = data[i];
let G = data[i+1];
let B = data[i+2];
let total = 0;
total = R+G+B;
if ( total > 0 ){
total = R / total*100;
}else{
total = 0;
}
running_total += total;
pixel_count++;
}
running_total = running_total / pixel_count;
}else{
running_total = "error - CORS";
}
let outputSpan = document.createElement("SPAN");
outputSpan.innerText = running_total;
img.insertAdjacentElement("beforebegin",outputSpan);
}
for ( let i = 0; i < imgs.length; i++ ){
imgs[i].addEventListener("load", function(){
Calc_Rating(i);
});
}
})();