ElBort / Endorsers

// ==UserScript==
// @name Endorsers
// @namespace https://www.erepublik.com/en/citizen/profile/2524994
// @version 2.0
// @description Calculate how much profit an article made by endorsers and more
// @author El Bort
// @require https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @run-at document-end
// @include http://*.erepublik.com/*/article/*
// @include https://*.erepublik.com/*/article/*
// @downloadURL https://openuserjs.org/install/ElBort/Endorsers.user.js
// @updateURL https://openuserjs.org/meta/ElBort/Endorsers.meta.js
// @copyright 2021, ElBort (https://openuserjs.org/users/ElBort)
// @license MIT
// ==/UserScript==

class e{static getId(){return $("#article_id").attr("value")}}class t{static init(){this.getEndorsers(),this.drawGoldenArticle(),this.drawRandomButton(),this.listen()}static drawGoldenArticle(){this.isPlatoEndorser()&&($(".post_content > h2 > a").css("color","#ffc200").css("font-weight",900),0==$(".post_endorse").length&&$(".post_info").after('<div class="post_endorse"><span class="endorse_title">Endorsed</span></div>'),$(".endorse_title").after(`<div class="endorses_wrapper notranslate endorsed_100" style="background-color: #ffc200;"><div><b style="opacity: 1;">${this.isPlatoEndorser()}</b><em style="opacity: 1;">GOLD</em><img src="//www.erepublik.net/images/modules/news/verified.png" style="opacity: 1; transform: matrix(1, 0, 0, 1, 0, 0);"></div></div>`))}static isPlatoEndorser(){return $('a:contains("Plato")').hasClass("end_10")?10:$('a:contains("Plato")').hasClass("end_25")?25:$('a:contains("Plato")').hasClass("end_50")?50:!!$('a:contains("Plato")').hasClass("end_100")&&100}static getEndorsers(){this.removeViewAll(),this.getAllEndorsers((e=>{this.drawEndorsers(e),this.getProfit()}))}static getAllEndorsers(t,a){$.ajax({url:"/en/main/article-allDonations",type:"POST",data:$.param({article_id:e.getId(),_token:s.getToken()}),success:e=>{t(e)},error:e=>{console.log("error",e),a()}})}static drawEndorsers(e){e.forEach((e=>{let t=`<a class="end_${e.amount}" href="/${s.getLanguage()}/citizen/profile/${e.citizen_id}" data-citizen-name="${e.name}">${e.name}</a>`;$(".endorsers_list").append(t)}))}static getProfit(){let e=100*$(".end_100").length+50*$(".end_50").length+25*$(".end_25").length+10*$(".end_10").length+5*$(".end_5").length;$(".endorsers_listing .endorsers_list").append(`<a class="plato" style="background-color:#C42D2D">${e} CC</a>`)}static removeViewAll(){$(".view_all").remove()}static drawRandomButton(){$(".post_content").prepend('<a class="std_global_btn noPadding tinySize blueColor" style="float:right;" id="randomEnd" original-title=""><span>Pick Random Endorser</span></a>')}static listen(){$("#randomEnd").on("click",(()=>this.randomEndorser()))}static randomEndorser(){let e=Math.floor(Math.random()*$("a[class*=end_]:not(.plato)").length),t=$("a[class*=end_]").eq(e);alert(`Here is a random endorser: \n${t.text()} ${t.attr("class").replace("end_","")} CC`),$(".endorsers_listing .endorsers_list").append(`<a class="plato" href="${t.attr("href")}" style="background-color:#1BC41B">${t.text()}</a>`)}}setTimeout((()=>{s.main()}),2e3);class s{static main(){console.log("eRepublik endorsers by El Bort"),t.init()}static getToken(){return SERVER_DATA.csrfToken}static getLanguage(){return erepublik.settings.culture}}