Created
December 9, 2023 14:17
-
-
Save garnajee/7178de596dc6253289ac6f0f48c8b94c to your computer and use it in GitHub Desktop.
user-script-like-unlike-spotify-hotkey
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Spotify Auto Like with Hotkey | |
// @namespace http://tampermonkey.net/ | |
// @version 1 | |
// @description Automate liking/unliking a song on Spotify with hotkey (²) | |
// @author Garnajee | |
// @match https://open.spotify.com/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// Fonction pour liker ou unliker un titre | |
function toggleLike() { | |
const buttonLike = document.querySelector('.Button-sc-1dqy6lx-0.lhGroS.control-button.control-button-heart'); | |
const buttonUnlike = document.querySelector('.Button-sc-1dqy6lx-0.yUUNA.control-button.control-button-heart'); | |
if (buttonLike) { | |
// Si le bouton "like" existe, vérifiez son état | |
const isLiked = buttonLike.getAttribute('aria-checked') === 'true'; | |
// Clique sur le bouton approprié en fonction de l'état actuel | |
if (isLiked) { | |
buttonUnlike?.click(); // Si aimé, unliker (si le bouton "unlike" existe) | |
} else { | |
buttonLike.click(); // Si non aimé, liker | |
} | |
} else if (buttonUnlike) { | |
// Si le bouton "like" n'existe pas, vérifiez le bouton "unlike" | |
const isUnliked = buttonUnlike.getAttribute('aria-checked') === 'false'; | |
// Clique sur le bouton approprié en fonction de l'état actuel | |
if (isUnliked) { | |
buttonLike?.click(); // Si non aimé, liker (si le bouton "like" existe) | |
} else { | |
buttonUnlike.click(); // Si déjà aimé, unliker | |
} | |
} | |
} | |
// Fonction pour détecter la combinaison de touches | |
function isHotkeyPressed(event) { | |
return event.keyCode === 222; // hotkey is ² | |
} | |
// Exécutez la fonction lorsque la page est entièrement chargée | |
window.addEventListener('load', function() { | |
document.addEventListener('keydown', function(event) { | |
// Vérifiez si la combinaison de touches est enfoncée (Alt Gr + L) | |
if (isHotkeyPressed(event)) { | |
toggleLike(); | |
} | |
}); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment