// ==UserScript== // @name Rice's AOTY Add-ons // @namespace https://albumoftheyear.org // @version 0.4 // @description A few different AOTY extensions I made compiled together. // @author Rice // @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js // @require https://openuserjs.org/src/libs/sizzle/GM_config.js // @match https://www.albumoftheyear.org/* // @icon https://www.google.com/s2/favicons?sz=64&domain=albumoftheyear.org // @grant GM_getValue // @grant GM.xmlHttpRequest // @grant GM_openInTab // @grant GM_setValue // @grant GM_getValue // @downloadURL none // ==/UserScript== (function () { let settingsButton; GM_config.init({ id: "AOTY-Addons", title: "AOTY Add-ons", fields: { RScoreEnable: { section: [ GM_config.create("Unround Scores"), "Script to show full (unrounded) album/single scores.", ], options: ["On", "Off"], label: "Toggle Score Unrounder", type: "radio", default: "On", }, RScoreRound: { label: "Decimals to show on main album pages.", type: "float", default: 1, }, RScoreFont: { label: "Font size to show on main album pages.", type: "float", default: 39, }, RScoreRound2: { label: "Decimals to show on small album previews.", type: "float", default: 2, }, RScoreFont2: { label: "Font size to show on small album previews.", type: "float", default: 18, }, HScoreEnable: { section: [ GM_config.create("Hide Scores"), "Script to hide album/single ratings", ], options: ["On", "Off"], label: "Toggle Score Hider", type: "radio", default: "Off", }, HScoreDisableIfRated: { options: ["On", "Off"], label: "Show Score If Already Rated", type: "radio", default: "On", }, HScoreHideCriticReviews: { options: ["Hide", "Show"], label: "Hide/Show Critic Reviews", type: "radio", default: "Show", }, HScoreReplacementText: { label: "Score Replacement Text", type: "text", default: "N/A", }, THEnable: { section: [ GM_config.create("Best Tracks Highlighter"), "Script to hide album/single ratings", ], options: ["On", "Off"], label: "Toggle Score Hider", type: "radio", default: "On", }, THMinScore: { label: "Minimum score a track must have in order to be bolded.", type: "float", default: 90, }, THMinRatings: { label: "Minimum amount of ratings a track must have in order to be bolded.", type: "float", default: 25, }, RAEnable: { section: [ GM_config.create("Rated Album Shuffle"), "Script to pick a random rated album from you (or anyone's) rated albums page. \nFull guide: \nhttps://pastebin.com/raw/PehxkCSw", ], options: ["On", "Off"], label: "Toggle Rated Album Shuffle", type: "radio", default: "On", }, RAKeyBind: { label: "Enter key code for keybind", type: "float", default: 220, }, AARating: { section: [ GM_config.create("Artist Rating Viewer"), "Script that automatically calculates a user or critics average rating of an artist when viewed.", ], options: ["On", "Off"], label: "Toggle Artist Rating Viewer", type: "radio", default: "On", }, }, css: "#AOTY-Addons { height: 200px; width: 500px }", }); //#content let svg = document.createElementNS("http://www.w3.org/2000/svg", "svg"); svg.setAttribute("width", "20"); svg.setAttribute("height", "20"); svg.innerHTML = ' \ \ \ \ \ \ '; svg.style.postition = "absolute"; svg.style.left = "75%"; svg.style.top = "75%"; svg.style.transform = "translateX(55%) translateY(25%)"; settingsButton = document.createElement("a"); settingsButton.className = "settingsButton"; settingsButton.style.width = "25px"; settingsButton.style.height = "25px"; settingsButton.style.postition = "absolute"; settingsButton.style.left = "50%"; settingsButton.style.transform = "translateX(-50%)"; settingsButton.style.webkittransform = "translateX(-50%)"; settingsButton.appendChild(svg); settingsButton.onclick = () => { GM_config.open(); let settingsarea = document.querySelector("#AOTY-Addons"); settingsarea.style.width = "530px"; settingsarea.style.height = "540px"; }; setInterval(function () { if (document.querySelector("#AOTY-Addons")) { var iframe = document.getElementById("AOTY-Addons"); var innerDoc = iframe.contentDocument || iframe.contentWindow.document; if (innerDoc.getElementById('AOTY-Addons_section_desc_3')) { if (!innerDoc.getElementById('AOTY-Addons_section_desc_3').innerHTML.includes('href="https://pastebin.com/raw/PehxkCSw')) { innerDoc.getElementById('AOTY-Addons_section_desc_3').innerHTML = `Script to pick a random rated album from you (or anyone's) rated albums page.` + `

Full guide: ` + `https://pastebin.com/raw/PehxkCSw` } } if (innerDoc.getElementsByClassName("saveclose_buttons")[0]) { innerDoc.getElementById("AOTY-Addons_saveBtn").addEventListener( "click", function () { location.reload(); }, false ); } } }, 200); let topbar = document.querySelectorAll("#content")[1]; topbar.appendChild(settingsButton); let onuserpage = "False"; let onalbum = "False"; let oncharts = "False"; let onartist = "False"; let url = document.URL; if (url.startsWith("https://www.albumoftheyear.org/user/")) { onuserpage = "True"; } if (url.startsWith("https://www.albumoftheyear.org/album/")) { onalbum = "True"; } if (url.startsWith("https://www.albumoftheyear.org/artist/")) { onartist = "True"; } if (url.startsWith("https://www.albumoftheyear.org/ratings/")) { oncharts = "True"; } var styleElem = document.head.appendChild(document.createElement("style")); let ratingcolorsred = document.getElementsByClassName("red"); let ratingcolorsyellow = document.getElementsByClassName("yellow"); let ratingcolorsgreen = document.getElementsByClassName("green"); let ratings = ""; let HSreplacetext = GM_config.get("HScoreReplacementText"); let HSenabled = GM_config.get("HScoreEnable"); let RSenabled = GM_config.get("RScoreEnable"); let RSFontSize1 = GM_config.get("RScoreFont") let RSFontSize2 = GM_config.get("RScoreFont2") let RSRound1 = GM_config.get("RScoreRound") let RSRound2 = GM_config.get("RScoreRound2") let ifrated = GM_config.get("HScoreDisableIfRated"); let criticreviews = GM_config.get("HScoreHideCriticReviews"); let TBEnabled = GM_config.get("THEnable") let TBMinScore = GM_config.get("THMinScore") let TBMinRatings = GM_config.get("THMinRatings") let RAEnabled = GM_config.get("RAEnable") let AARating = GM_config.get("AARating") let RAKeyBind = GM_config.get("RAKeyBind") if (TBEnabled == "On") { if (url.startsWith("https://www.albumoftheyear.org/album/")) { if (document.getElementsByClassName("trackRating").length > 0) { let tracklist = document.getElementsByClassName("trackRating"); for (let i = 0; tracklist.length > i; i++) { let rating = tracklist[i].children[0].textContent; let ratingcount = tracklist[i].children[0] .getAttribute("title") .split("Ratings")[0]; if (rating >= TBMinScore && ratingcount >= TBMinRatings) { let track = document.getElementsByClassName("trackTitle")[i].children[0]; track.style.fontWeight = "bold"; } } } } } if ( document.getElementsByClassName("ratingBlock yourOwn")[0] && ifrated == "On" ) { onuserpage = "True"; } if (onuserpage == "False" && HSenabled == "On") { if (oncharts == "True") { styleElem.innerHTML = ".albumListCover.mustHear::before {border-right: 0px solid rgba(98,188,250,.85);}"; ratings = document.getElementsByClassName("scoreValue"); } if (oncharts == "False") { styleElem.innerHTML = ".image.mustHear::before {border-right: 0px solid rgba(98,188,250,.85);}"; ratings = document.getElementsByClassName("rating"); } let musthear2 = document.getElementsByClassName("fas fa-star"); for (let i = 0; i < 200; i++) { if ( ratingcolorsred[1 + i] && ratingcolorsred[1 + i].parentElement.parentElement.classList.length !== 2 ) { ratingcolorsred[1 + i].classList.replace("red", "white"); } if ( ratingcolorsyellow[1 + i] && ratingcolorsyellow[1 + i].parentElement.parentElement.classList .length !== 2 ) { ratingcolorsyellow[1 + i].classList.replace("yellow", "white"); } if ( ratingcolorsgreen[1 + i] && ratingcolorsgreen[1 + i].parentElement.parentElement.classList .length !== 2 ) { ratingcolorsgreen[1 + i].classList.replace("green", "white"); } if (ratings[i]) { if (ratings[i].parentElement.classList.length !== 2) { ratings[i].textContent = HSreplacetext; } } for (let i = 0; i < musthear2.length; i++) { if (musthear2[i]) { musthear2[i].remove(); } } if (onartist == "True") { let artistcriticscore = document.getElementsByClassName("artistCriticScore"); if (artistcriticscore.length >= 1) { artistcriticscore[0].children[0].textContent = HSreplacetext; } let artistuserscore = document.getElementsByClassName("artistUserScore"); if (artistuserscore.length >= 1) { artistuserscore[0].textContent = HSreplacetext; } let bestsongsratings = document.getElementsByClassName( "trackRating noPadding" ); if (bestsongsratings) { for (let i = 0; i < bestsongsratings.length; i++) { bestsongsratings[i].textContent = HSreplacetext; } } } if (onalbum == "True") { let musthearbutton = document.getElementsByClassName("mustHearButton"); if (musthearbutton) { for (let i = 0; i < musthearbutton.length; i++) { musthearbutton[i].remove(); } } if (criticreviews == "Hide") { let criticreviewcontainer = document.getElementById("critics"); if (criticreviewcontainer) { criticreviewcontainer.remove(); } } if (criticreviews == "Show") { let criticboxratings = document.getElementsByClassName("albumReviewRow"); for (let i = 0; i < criticboxratings.length; i++) { criticboxratings[ i ].children[1].children[0].children[0].textContent = HSreplacetext; } } let criticratings = document.getElementsByClassName("albumCriticScore"); criticratings[0].children[0].textContent = HSreplacetext; let userratings = document.getElementsByClassName("albumUserScore"); userratings[0].children[0].textContent = HSreplacetext; let likecount = document.getElementsByClassName("text"); if (likecount) { if (likecount.length == 3) { likecount[2].remove(); } } let albumrankings = document.getElementsByClassName("text gray"); if (albumrankings) { for (let i = 0; i < albumrankings.length; i++) { albumrankings[i].remove(); } } let trackratings = document.getElementsByClassName("trackRating"); if (trackratings) { for (let i = 0; i < trackratings.length; i++) { trackratings[i].remove(); } } } } } function round(value, decimals) { return Number(Math.round(value + "e" + decimals) + "e-" + decimals); } if (RSenabled == "On") { if (url.startsWith("https://www.albumoftheyear.org/album/")) { if (document.getElementsByClassName("albumCriticScore")[0]) { if ( document.getElementsByClassName("albumCriticScore")[0].children[0] .textContent !== "NR" ) { let criticscore = document.getElementsByClassName("albumCriticScore")[0].children[0]; let unrounded = criticscore.children[0].getAttribute("title"); if (round(unrounded, RSRound1) > 100) { criticscore.textContent = 100; } else { criticscore.textContent = round(unrounded, RSRound1); document.getElementsByClassName("albumCriticScore")[0].style.fontSize = `${RSFontSize1}px`; } } } if (document.getElementsByClassName("albumUserScore")[0]) { if ( document.getElementsByClassName("albumUserScore")[0] .textContent !== "NR" ) { let userscore = document.getElementsByClassName("albumUserScore")[0].children[0]; let unrounded2 = userscore.getAttribute("title"); userscore.textContent = round(unrounded2, RSRound1); document.getElementsByClassName("albumUserScore")[0].style.fontSize = `${RSFontSize1}px`; } } } if (url.startsWith("https://www.albumoftheyear.org/artist/")) { let truescore = document.getElementsByClassName("trackListTable large")[0] .children[0]; for (let i = 0; i < truescore.children.length; i++) { let score = truescore.children[i].children[3].children[0]; score.textContent = round(score.getAttribute("title"), RSRound2); } } if (url.startsWith("https://www.albumoftheyear.org/ratings/")) { let roundedscore = document.getElementsByClassName("scoreValue"); let truescore = document.getElementsByClassName("scoreValueContainer"); let check = document.getElementsByClassName("scoreHeader"); for (let i = 0; i < truescore.length; i++) { if ( check[i].textContent !== "Critic Score" && check[i].textContent !== "Score" ) { roundedscore[i].textContent = round( truescore[i].getAttribute("title"), RSRound2 ); roundedscore[i].style.fontSize = `${RSFontSize2}px`; } } } } if (RAEnabled == "On") { if (url.includes('https://www.albumoftheyear.org/user/') && url.includes('/ratings')) { function doc_keyUp(e) { switch (e.keyCode) { case RAKeyBind: let url = window.location.href; GM_setValue("first", false); if (url.endsWith("/ratings/1/") || url.endsWith("/ratings/")) { GM_setValue("first", true); } if (GM_getValue("first") == true) { let pagenumbers = document.getElementsByClassName("pageSelectSmall")[ document.getElementsByClassName("pageSelectSmall").length - 1 ].textContent; let randompage = Math.floor(Math.random() * pagenumbers) + 1; if (randompage == 1) { randompage++; } window.location.href = url.split(/ratings/)[0] + `ratings/${randompage}/`; } if (GM_getValue("first") == false) { let randomalbumnumber = Math.floor( Math.random() * document.getElementsByClassName("artistTitle").length + 1 ); window.location.href = "https://www.albumoftheyear.org" + document .getElementsByClassName("artistTitle")[ randomalbumnumber ].parentNode.parentNode.children[2].getAttribute("href"); } } } document.addEventListener("keyup", doc_keyUp, false); } } if (AARating == "On") { let ok = false let total = 0 let albsrated = 0 const Observe = (sel, opt, cb) => { const Obs = new MutationObserver((m) => [...m].forEach(cb)); document.querySelectorAll(sel).forEach(el => Obs.observe(el, opt)); }; Observe("#graybg > span > div.footer > div.overlay", { attributesList: ["style"], attributeOldValue: true, }, (m) => { if (m.target.getAttribute(m.attributeName) == "display: block;") { ok = true } }); setInterval(() => { if (ok == true && document.getElementsByClassName("albumInfo").length > 0) { for (let i = 0; document.getElementsByClassName("albumInfo").length * 2 > i; i++) { if (document.getElementsByClassName("tableRating")[i] && document.getElementsByClassName("tableRating")[i].children[0]) { if (document.getElementsByClassName("tableRating")[i].children[0].className == "green-font" || document.getElementsByClassName("tableRating")[i].children[0].className == "yellow-font" || document.getElementsByClassName("tableRating")[i].children[0].className == "red-font") { total += Number(document.getElementsByClassName("tableRating")[i].children[0].textContent) albsrated++ } } } let artistratings = document.getElementsByClassName("subHeadline artistRatings")[0] let avgscore = round((total / albsrated), 2) let color; if (avgscore >= 69.5) { color = "#85ce73" } if (avgscore < 69 && avgscore >= 49.5) { color = "#f0e68c" } if (avgscore < 49.5) { color = "#d76666" } artistratings.innerHTML += `
Average Artist Rating: ${round((total / albsrated), 2)}
` total = 0 albsrated = 0 ok = false } }, 100); } })();