NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript==
// @name Create custom button
// @namespace Violentmonkey Scripts
// @match https://rateyourmusic.com/*
// @grant window
// @version 1.1
// @author Craicy
// @description 21.8.2021, 13:59:21
// @license MIT
// ==/UserScript==
var currentLocation = window.location; // get website
var locationType = currentLocation.href.split(['/'])[3]; // the part after ...com/
if (locationType.search('customchart') == 0 || locationType.search('chart') == 0) {
var divs = document.getElementsByClassName("ui_media_links"); // The boxes: Listen: ...
// There are multiple entrys
for (let i = 0; i < divs.length; i++) {
let button_field = divs.item(i);
let button = get_spotify_button(button_field); // search the spotify button in the button_field
if (button != 0) {
add_album_button(button);
}
}
}
else if (locationType.search('release') == 0) {
var divs = document.getElementsByClassName("ui_media_links promoted"); // The boxes: Listen: ...
// Only one element
// find the element
let button_field = divs.item(1);
let button = get_spotify_button(button_field);
add_album_button(button);
}
else {
// not supported
}
function get_spotify_button(button_field) {
var buttons = button_field.children;
for (let j = 1; j < buttons.length - 1; j++) {
if (buttons.item(j).title == "Spotify") {
return buttons.item(j);
}
}
return 0;
}
function add_album_button(spotifyButton) {
var album_id_raw = spotifyButton.href;
var album_id = album_id_raw.split("/")[4];
var parentDiv = spotifyButton.parentNode;
var addToPlaylistButton = spotifyButton.cloneNode(true);
addToPlaylistButton.href = "spopy:" + album_id; // set link when clicked
addToPlaylistButton.target = "_self"; // make the link open in same window
addToPlaylistButton.title = "Change this to change mouse hover text"
addToPlaylistButton.style.backgroundImage = "url(https://i.imgur.com/8vsXJDbt.png)"; // link to a custom hosted image
parentDiv.insertBefore(addToPlaylistButton, spotifyButton.nextSibling); // this is insertAfter
}