Copy Plex token

Adds a button with which you can copy your plex access token to your clipboard

  1. // ==UserScript==
  2. // @name Copy Plex token
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024-05-12
  5. // @description Adds a button with which you can copy your plex access token to your clipboard
  6. // @license MIT
  7. // @author Bastian Ganze
  8. // @match https://app.plex.tv/*
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=plex.tv
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15. function createCopyButton() {
  16. // Get the user actions list
  17. const userActions = document.querySelector('[class*="NavBar-container"] > div:nth-child(2)');
  18. console.log(userActions);
  19. if (!userActions) {
  20. setTimeout(createCopyButton, 200);
  21. return;
  22. }
  23.  
  24. if (userActions) {
  25. // Create the download button
  26. var downloadButton = document.createElement('a');
  27. downloadButton.textContent = 'Copy Access Token';
  28. downloadButton.style.cursor = 'pointer';
  29. downloadButton.style.marginRight = "16px";
  30. downloadButton.style.borderRadius = "4px";
  31. downloadButton.style.backgroundColor = "rgb(229, 160, 13)";
  32. downloadButton.style.minHeight = "28px";
  33. downloadButton.style.color = "rgb(28, 28, 28)";
  34. downloadButton.style.lineHeight = "0";
  35. downloadButton.style.display = "flex";
  36. downloadButton.style.alignItems = "center";
  37. downloadButton.style.fontWeight = "600";
  38. downloadButton.style.padding = "0 12px";
  39.  
  40. // Add click event listener to the download button
  41. downloadButton.addEventListener('click', function() {
  42. const copyText = localStorage.getItem("myPlexAccessToken");
  43. if (!copyText) {
  44. console.error("Could not find any token, wtf!?");
  45. }
  46. navigator.clipboard.writeText(copyText).then(() => {
  47. alert(`${copyText} copied to clipboard`);
  48. },(err) => {
  49. console.error('Failed to copy Plex ID to clipboard copy');
  50. console.error(err);
  51. });
  52. });
  53.  
  54.  
  55. // Append the list item to the user actions list
  56. userActions.prepend(downloadButton);
  57. }
  58. }
  59.  
  60. window.addEventListener('load', function() {
  61. console.log("wat");
  62. createCopyButton();
  63. });
  64. })();