Greasy Fork

Plex web album and artist name swap

Swaps the album and artist names so the album name is on top

目前为 2024-02-09 提交的版本。查看 最新版本

// ==UserScript==
// @name         Plex web album and artist name swap
// @namespace    http://tampermonkey.net/
// @version      2024-02.3
// @description  Swaps the album and artist names so the album name is on top
// @author       frondonson
// @license      MIT

// @match        https://app.plex.tv/desktop/*
// @match        http://192.168.1.72:32400/web/*

// @icon         https://www.google.com/s2/favicons?sz=64&domain=plex.tv
// @grant        none
// ==/UserScript==


//Dead simple version to just check every poster and only switch cards where the poster has a 1:1 aspect ratio
//  since plex treats all media libraries and types the same 
//Fixes album names on every tab but is more crude and less performant
setInterval(scanForCards, 100);
function scanForCards()
{	
	let mediaCards = document.querySelectorAll('div[data-testid="cellItem"]:not(.SwapAlbumNameUserScript-swapped)');
	
	doSwaps(mediaCards);
}

function doSwaps(nodeList)
{
	for (const albumDiv of nodeList) 
	{
		//Reject non-albums, playlists and artists
		let poster = albumDiv.querySelector('.MetadataPosterListItem-card-BfbXw7.PosterCard-card-BRB1k_')
		if(poster==null || poster.clientHeight != poster.clientWidth)
		{ continue; }
		if(albumDiv.childElementCount < 3 || albumDiv.lastChild.nodeName == ('SPAN'))
		{ continue; }
		if(albumDiv.classList.contains('SwapAlbumNameUserScript-swapped'))
		{ continue; }
		
		let artistNode = albumDiv.children[1];
		//Classlist- MetadataPosterCardTitle-centeredSingleLineTitle-EuZHlc MetadataPosterCardTitle-singleLineTitle-lPd1B2 MetadataPosterCardTitle-title-ImAmGu Link-default-bdWb1S Link-isHrefLink-nk7Aiq
		let albumNode = albumDiv.children[2];
		//Classlist- MetadataPosterCardTitle-centeredSingleLineTitle-EuZHlc MetadataPosterCardTitle-singleLineTitle-lPd1B2 MetadataPosterCardTitle-title-ImAmGu MetadataPosterCardTitle-isSecondary-gGuBpd Link-default-bdWb1S Link-isHrefLink-nk7Aiq
		
		artistNode.classList.add('MetadataPosterCardTitle-isSecondary-gGuBpd');
		albumNode.classList.remove('MetadataPosterCardTitle-isSecondary-gGuBpd');
		
		//Swap positions - (x, y) insert node X before node Y
		albumDiv.insertBefore(albumNode, artistNode);
		
		albumDiv.classList.add('SwapAlbumNameUserScript-swapped');
	}
	
}