BetterYTM.user.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // ==UserScript==
  2. // @name BetterYTM
  3. // @homepageURL https://github.com/Sv443/BetterYTM#readme
  4. // @namespace https://github.com/Sv443/BetterYTM
  5. // @version 1.0.0
  6. // @description Configurable layout and UX improvements for YouTube Music
  7. // @description:de Konfigurierbares Layout und UX-Verbesserungen für YouTube Music
  8. // @license MIT
  9. // @author Sv443
  10. // @copyright Sv443 (https://github.com/Sv443)
  11. // @match https://music.youtube.com/*
  12. // @match https://www.youtube.com/*
  13. // @icon https://raw.githubusercontent.com/Sv443/BetterYTM/main/resources/icon/icon.png
  14. // @run-at document-start
  15. // @grant GM.getValue
  16. // @grant GM.setValue
  17. // @connect self
  18. // @connect youtube.com
  19. // @connect github.com
  20. // @connect githubusercontent.com
  21. // @downloadURL https://raw.githubusercontent.com/Sv443/BetterYTM/main/dist/BetterYTM.user.js
  22. // @updateURL https://raw.githubusercontent.com/Sv443/BetterYTM/main/dist/BetterYTM.user.js
  23. // ==/UserScript==
  24. /*
  25. ▄▄▄ ▄ ▄▄▄▄▄▄ ▄
  26. █ █ ▄▄▄ █ █ ▄▄▄ ▄ ▄█ █ █ █▀▄▀█
  27. █▀▀▄ █▄█ █▀ █▀ █▄█ █▀ █ █ █ █
  28. █▄▄▀ ▀▄▄ ▀▄▄ ▀▄▄ ▀▄▄ █ █ █ █ █
  29. Made with ❤️ by Sv443
  30. I welcome every contribution on GitHub!
  31. https://github.com/Sv443/BetterYTM
  32. */
  33. /* Disclaimer: I am not affiliated with YouTube, Google, Alphabet, Genius or anyone else */
  34. /* C&D this 🖕 */
  35. !function(){"use strict";var e={546:function(e,t){var n=function(){function e(){this._eventHandlers={}}return e.prototype.isValidType=function(e){return"string"==typeof e},e.prototype.isValidHandler=function(e){return"function"==typeof e},e.prototype.on=function(e,t){if(!e||!t)return!1;if(!this.isValidType(e))return!1;if(!this.isValidHandler(t))return!1;var n=this._eventHandlers[e];return n||(n=this._eventHandlers[e]=[]),!(n.indexOf(t)>=0||(t._once=!1,n.push(t),0))},e.prototype.once=function(e,t){if(!e||!t)return!1;if(!this.isValidType(e))return!1;if(!this.isValidHandler(t))return!1;var n=this.on(e,t);return n&&(t._once=!0),n},e.prototype.off=function(e,t){if(!e)return this.offAll();if(t){if(this.isValidType(e)&&this.isValidHandler(t)){var n=this._eventHandlers[e];if(n&&n.length)for(var o=0;o<n.length;o++)if(n[o]===t){n.splice(o,1);break}}}else this._eventHandlers[e]=[]},e.prototype.offAll=function(){this._eventHandlers={}},e.prototype.fire=function(e,t){if(e&&this.isValidType(e)){var n=this._eventHandlers[e];if(n&&n.length)for(var o=this.createEvent(e,t),i=0,r=n;i<r.length;i++){var l=r[i];this.isValidHandler(l)&&(l._once&&(o.once=!0),l(o),o.once&&this.off(e,l))}}},e.prototype.has=function(e,t){if(!e||!this.isValidType(e))return!1;var n=this._eventHandlers[e];return!(!n||!n.length||t&&this.isValidHandler(t)&&!(n.indexOf(t)>=0))},e.prototype.getHandlers=function(e){return e&&this.isValidType(e)&&this._eventHandlers[e]||[]},e.prototype.createEvent=function(e,t,n){return void 0===n&&(n=!1),{type:e,data:t,timestamp:Date.now(),once:n}},e}();t.vp=n,new n}},t={};function n(o){var i=t[o];if(void 0!==i)return i.exports;var r=t[o]={exports:{}};return e[o](r,r.exports,n),r.exports}!function(){const e=!0,t=25,o=200,i=Object.freeze({name:GM.info.script.name,version:GM.info.script.version,namespace:GM.info.script.namespace,lastCommit:"02aa915"});function r(){const{hostname:e}=new URL(location.href);if(e.includes("music.youtube"))return"ytm";if(e.includes("youtube"))return"yt";throw new Error("BetterYTM is running on an unexpected website. Please don't tamper with the @match directives in the userscript header.")}function l(e,t){var n;return null===(n=e.parentNode)||void 0===n||n.insertBefore(t,e.nextSibling),t}function s(t,n){"string"==typeof n&&0!==n.length||(n=String(Math.floor(1e4*Math.random())));const o=document.createElement("style");o.id=`betterytm-style-${n}`,o.innerHTML=t,document.head.appendChild(o),e&&console.log(`BetterYTM: Inserted global style with ref '${n}':`,o)}const c=new(n(546).vp);let a=null;function d(t){var n,o;if(["ArrowLeft","ArrowRight"].includes(t.code)){if(["INPUT","TEXTAREA","SELECT"].includes(null!==(o=null===(n=document.activeElement)||void 0===n?void 0:n.tagName)&&void 0!==o?o:"_"))return e&&console.info(`BetterYTM: Captured valid key but the current active element is <${document.activeElement.tagName.toLowerCase()}>, so the keypress is ignored`);e&&console.log(`BetterYTM: Captured key '${t.code}' in proxy listener`);const i={altKey:!1,ctrlKey:!1,metaKey:!1,shiftKey:!1,target:document.body,currentTarget:document.body,originalTarget:document.body,explicitOriginalTarget:document.body,srcElement:document.body,type:"keydown",bubbles:!0,cancelBubble:!1,cancelable:!0,isTrusted:!0,repeat:!1,view:window};let r=!1,l={};switch(t.code){case"ArrowLeft":l={code:"KeyH",key:"h",keyCode:72,which:72};break;case"ArrowRight":l={code:"KeyL",key:"l",keyCode:76,which:76};break;default:r=!0}if(r)e&&console.warn(`BetterYTM: Captured key '${t.code}' has no defined behavior`);else{const n=Object.assign(Object.assign({code:""},i),l);document.body.dispatchEvent(new KeyboardEvent("keydown",n)),e&&console.log(`BetterYTM: Dispatched proxy keydown event: [${t.code}] -> [${n.code}]`)}}}var u=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function l(e){try{c(o.next(e))}catch(e){r(e)}}function s(e){try{c(o.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(l,s)}c((o=o.apply(e,t||[])).next())}))};const m=e?"develop":"main";function y(){const e=document.querySelector("#betterytm-menu-bg");e.style.visibility="hidden",e.style.display="none"}let p;let f=0;function h(){const n=document.querySelector('.ytmusic-nav-bar ytmusic-pivot-bar-item-renderer[tab-id="SPunlimited"]');n?(n.remove(),e&&console.log(`BetterYTM: Removed upgrade tab after ${f} tries`)):f<t?(setTimeout(h,o),f++):console.error(`BetterYTM: Couldn't find upgrade tab to remove after ${f} tries`)}function g(){const{volumeSliderSize:e}=p;"number"!=typeof e||isNaN(Number(e))||s(`.volume-slider.ytmusic-player-bar, .expand-volume-slider.ytmusic-player-bar {\n width: ${e}px !important;\n}`,"vol-slider")}function b(){document.querySelector("tp-yt-paper-slider#volume-slider").setAttribute("step",String(p.volumeSliderStep))}function v(e){const t=document.createElement("div");t.className="bytm-queue-btn-container",t.innerText="ayo",e.querySelector(".song-info").appendChild(t),e.classList.add("bytm-has-queue-btns")}var w=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function l(e){try{c(o.next(e))}catch(e){r(e)}}function s(e){try{c(o.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(l,s)}c((o=o.apply(e,t||[])).next())}))},x=function(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,n=e[Symbol.asyncIterator];return n?n.call(e):(e="function"==typeof __values?__values(e):e[Symbol.iterator](),t={},o("next"),o("throw"),o("return"),t[Symbol.asyncIterator]=function(){return this},t);function o(n){t[n]=e[n]&&function(t){return new Promise((function(o,i){!function(e,t,n,o){Promise.resolve(o).then((function(t){e({value:t,done:n})}),t)}(o,i,(t=e[n](t)).done,t.value)}))}}};const T="https://api.sv443.net/geniurl",k=`${T}/search/top`;let S="",E=0;function M(){return w(this,void 0,void 0,(function*(){const n=document.querySelector(".middle-controls-buttons ytmusic-like-button-renderer#like-button-renderer");if(!n)return E++,E<t?setTimeout(M,o):console.error(`BetterYTM: Couldn't find element to append lyrics buttons to after ${E} tries`);const i=document.querySelector(".content-info-wrapper > yt-formatted-string"),r=yield C(),s=document.createElement("a");s.id="betterytm-lyrics-button",s.className="ytmusic-player-bar",s.title=r?"Click to open this song's lyrics in a new tab":"Loading...",r&&(s.href=r),s.target="_blank",s.rel="noopener noreferrer",s.style.visibility=r?"initial":"hidden",s.style.display=r?"inline-flex":"none";const c=document.createElement("img");c.id="betterytm-lyrics-img",c.src="https://raw.githubusercontent.com/Sv443/BetterYTM/main/resources/external/genius.png",s.appendChild(c),e&&console.log(`BetterYTM: Inserted genius button after ${E} tries:`,s),l(n,s),S=i.title,new MutationObserver((t=>{var n,o,i;return w(this,void 0,void 0,(function*(){var r,l,s,c;try{for(n=!0,o=x(t);!(r=(i=yield o.next()).done);){c=i.value,n=!1;try{const t=c.target.title;if(t!=S&&t.length>0){const n=document.querySelector("#betterytm-lyrics-button");if(!n)return;e&&console.log(`BetterYTM: Song title changed from '${S}' to '${t}'`),n.style.cursor="wait",n.style.pointerEvents="none",S=t;const o=yield C();if(!o)continue;n.href=o,n.title="Click to open this song's lyrics in a new tab",n.style.cursor="pointer",n.style.visibility="initial",n.style.display="inline-flex",n.style.pointerEvents="initial"}}finally{n=!0}}}catch(e){l={error:e}}finally{try{n||r||!(s=o.return)||(yield s.call(o))}finally{if(l)throw l.error}}}))})).observe(i,{attributes:!0,attributeFilter:["title"]})}))}function C(){var e,t;return w(this,void 0,void 0,(function*(){try{const n="string"==typeof(null===(e=document.querySelector("ytmusic-player"))||void 0===e?void 0:e.getAttribute("video-mode_")),o=document.querySelector(".content-info-wrapper > yt-formatted-string"),i=document.querySelector("span.subtitle > yt-formatted-string:first-child");if(!o||!i||!o.title)return null;const r=e=>e.replace(/\(.+\)/gim,"").replace(/\[.+\]/gim,"").trim(),l=e=>((e=e.split(/\s*\u2022\s*/gimu)[0]).match(/&/)&&(e=e.split(/\s*&\s*/gm)[0]),e.match(/,/)&&(e=e.split(/,\s*/gm)[0]),e.trim()),s=r(o.title),c=l(i.title),a=()=>w(this,void 0,void 0,(function*(){if(!s.includes("-"))return yield $(c,s);const[e,...t]=s.split("-").map((e=>e.trim()));return yield $(e,t.join(" "))}));return n?yield a():null!==(t=yield $(c,s))&&void 0!==t?t:yield a()}catch(e){return console.error("BetterYTM: Couldn't resolve genius.com URL:",e),null}}))}function $(t,n){return w(this,void 0,void 0,(function*(){try{const o=`${k}?artist=${encodeURIComponent(t)}&song=${encodeURIComponent(n)}`;e&&console.log(`BetterYTM: Requesting URL from geniURL at '${o}'`);const i=yield(yield fetch(o)).json();if(i.error)return void console.error("BetterYTM: Couldn't fetch genius.com URL:",i.message);const r=i.url;return e&&console.info(`BetterYTM: Found genius URL: ${r}`),r}catch(e){return void console.error("BetterYTM: Couldn't get genius URL due to error:",e)}}))}const B={options:"bytm-menu-tab-options",info:"bytm-menu-tab-info",changelog:"bytm-menu-tab-changelog"};let L=0;function Y(){var e;if(!document.querySelector("#bytm-menu-dialog"))return L++<t?setTimeout(Y,o):console.error(`BetterYTM: couldn't create menu element after ${t} tries.`);for(const t in B){const n=B[t];null===(e=document.querySelector(`#${n}-header`))||void 0===e||e.addEventListener("click",(()=>{O(t)}))}document.querySelector("#bytm-menu-tab-options-content"),document.querySelector("#bytm-menu-tab-info-content"),document.querySelector("#bytm-menu-tab-changelog-content").innerHTML='<h1 id="betterytm-changelog">BetterYTM Changelog</h1> <br> <h2 id="history">History:</h2> <ul> <li><strong><a href="#100">v1.0.0</a></strong></li> <li><a href="#020">v0.2.0</a></li> <li><a href="#010">v0.1.0</a></li> </ul> <hr> <p><br><br></p> <h2 id="100">1.0.0</h2> <ul> <li>Added menu to configure features</li> <li>New configurable features:<ul> <li>Make volume slider bigger</li> <li>Choose step of volume slider for finer control</li> <li>TODO: Add lyrics button to each song in a playlist</li> </ul> </li> <li>Changes / Fixes:<ul> <li>Now the lyrics button will directly link to the lyrics (using my API <a href="https://github.com/Sv443/geniURL">geniURL</a>)</li> <li>TODO: Site switch with <kbd>F9</kbd> will now keep the video time</li> </ul> </li> </ul> <br> <h2 id="020">0.2.0</h2> <ul> <li>Added Features:<ul> <li>Switch between YouTube and YT Music (with <kbd>F9</kbd> by default)</li> <li>Search for song lyrics with new button in media controls</li> <li>Remove &quot;Upgrade to YTM Premium&quot; tab</li> </ul> </li> </ul> <br> <h2 id="010">0.1.0</h2> <ul> <li>Added support for arrow keys to skip forward or backward (currently only by fixed 10 second interval)</li> </ul> <p><br><br><br><br><br><br><br><br><br></p> '}function O(e){const t=Object.assign({},B);delete t[e];for(const e of Object.keys(t))document.querySelector(`#${t[e]}-header`).dataset.active="false",document.querySelector(`#${t[e]}-content`).dataset.active="false";document.querySelector(`#${B[e]}-header`).dataset.active="true",document.querySelector(`#${B[e]}-content`).dataset.active="true"}const q=Object.freeze({arrowKeySupport:{desc:"Arrow keys skip forwards and backwards by 10 seconds",type:"toggle",category:"input",default:!0},switchBetweenSites:{desc:"Add F9 as a hotkey to switch between the YT and YTM sites on a video / song",type:"toggle",category:"input",default:!0},switchSitesHotkey:{desc:"Which hotkey needs to be pressed to switch sites?",type:"hotkey",category:"input",default:{key:"F9",shift:!1,ctrl:!1,meta:!1}},anchorImprovements:{desc:"TODO: Make it so middle clicking a song to open it in a new tab is easier",type:"toggle",category:"input",default:!0},removeUpgradeTab:{desc:'Remove the "Upgrade" / YT Music Premium tab',type:"toggle",category:"layout",default:!0},volumeSliderSize:{desc:"The width of the volume slider in pixels",type:"number",category:"layout",min:10,max:1e3,step:5,unit:"px",default:160},volumeSliderStep:{desc:"Volume slider sensitivity - the smaller this number, the finer the volume control",type:"slider",category:"layout",min:1,max:20,default:2},watermarkEnabled:{desc:`Show a ${i.name} watermark under the YTM logo`,type:"toggle",category:"layout",default:!0},queueButtons:{desc:"TODO: Add buttons while hovering over a song in a queue to quickly remove it or open its lyrics",type:"toggle",category:"layout",default:!0},dismissPopup:{desc:'TODO: Automatically dismisses the "are you still there" popup',type:"toggle",category:"layout",default:!0},geniusLyrics:{desc:"Add a button to the media controls to open the current song's lyrics on genius.com in a new tab",type:"toggle",category:"lyrics",default:!0}});var N=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function l(e){try{c(o.next(e))}catch(e){r(e)}}function s(e){try{c(o.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(l,s)}c((o=o.apply(e,t||[])).next())}))};const A=Object.keys(q).reduce(((e,t)=>(e[t]=q[t].default,e)),{});let R;function j(e=!1){return N(this,void 0,void 0,(function*(){return(void 0===R||e)&&(yield H(R=Object.assign(Object.assign({},A),yield function(){return N(this,void 0,void 0,(function*(){const e=Object.freeze(Object.assign({},A));try{const t=yield GM.getValue("betterytm-config");return"string"!=typeof t?(yield _(),R=e):Object.freeze(t?JSON.parse(t):{})}catch(t){return yield _(),R=e}}))}()))),R}))}function H(e){if(!e||"object"!=typeof e)throw new TypeError("Feature config not provided or invalid");return R=Object.assign({},e),GM.setValue("betterytm-config",JSON.stringify(e))}function _(){return R=Object.assign({},A),GM.setValue("betterytm-config",JSON.stringify(A))}var z=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function l(e){try{c(o.next(e))}catch(e){r(e)}}function s(e){try{c(o.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(l,s)}c((o=o.apply(e,t||[])).next())}))};function I(){return z(this,void 0,void 0,(function*(){const t=yield j(),n=r();e&&console.log(`BetterYTM: Initializing features for domain '${n}'`);try{if("ytm"===n&&(function(){const t=new MutationObserver((([{addedNodes:t,removedNodes:n,target:o}])=>{(t.length>0||n.length>0)&&(e&&console.info("BetterYTM: Detected queue change - added nodes:",t.length,"- removed nodes:",n.length),c.fire("queueChanged",o))}));t.observe(document.querySelector(".side-panel.modular #contents.ytmusic-player-queue"),{childList:!0}),e&&console.info("BetterYTM: Successfully initialized SiteEvents observers"),a=[t]}(),t.arrowKeySupport&&(document.addEventListener("keydown",d),e&&console.log("BetterYTM: Added key press listener")),t.removeUpgradeTab&&h(),t.watermarkEnabled&&function(){const t=document.createElement("span");t.id="betterytm-watermark",t.className="style-scope ytmusic-nav-bar",t.innerText=i.name,t.title="Open menu",t.addEventListener("click",(()=>function(){const e=document.querySelector("#betterytm-menu-bg");e.style.visibility="visible",e.style.display="block"}())),l(document.querySelector("#left-content"),t),e&&console.log("BetterYTM: Added watermark element:",t)}(),t.geniusLyrics&&M(),t.queueButtons&&function(){c.on("queueChanged",(e=>{for(const t of e.data.childNodes)t.classList.contains("bytm-has-queue-btns")||v(t)}));const e=document.querySelectorAll("#contents.ytmusic-player-queue > ytmusic-player-queue-item");0!==e.length&&e.forEach((e=>v(e)))}(),"number"==typeof t.volumeSliderSize&&g(),t.anchorImprovements,b()),["ytm","yt"].includes(n)){t.switchBetweenSites&&function(t){document.addEventListener("keydown",(n=>{"F9"==n.key&&function(t){var n;try{let o;if("ytm"===t?o="music":"yt"===t&&(o="www"),!o)throw new TypeError(`Unrecognized domain '${t}'`);const{pathname:i,search:l,hash:s}=new URL(location.href),c=null!==(n=function(e=!1){const t=r();try{if("ytm"===t){const e=document.querySelector("#progress-bar");return isNaN(Number(e.value))?null:Number(e.value)}return null}catch(e){return console.error("BetterYTM: Couldn't get video time due to error:",e),null}}())&&void 0!==n?n:0;e&&console.log(`BetterYTM: Found video time of ${c} seconds`);const a=`https://${o}.youtube.com${i}${l.includes("?")?`${l}&t=${c}`:`?t=${c}`}${s}`;console.info(`BetterYTM - switching to domain '${t}' at ${a}`),location.href=a}catch(e){console.error("BetterYTM: Error while switching site:",e)}}("yt"===t?"ytm":"yt")})),e&&console.log("BetterYTM: Initialized site switch listener")}(n);try{!function(){var t;u(this,void 0,void 0,(function*(){const n=document.createElement("div");n.id="betterytm-menu-bg",n.title="Click here to close the menu",n.style.visibility="hidden",n.style.display="none",n.addEventListener("click",(e=>{"betterytm-menu-bg"===e.target.id&&y()}));const o=document.createElement("div");o.title="",o.id="betterytm-menu",o.style.borderRadius="15px",o.style.display="flex",o.style.flexDirection="column",o.style.justifyContent="space-between";const r=document.createElement("div");r.style.padding="8px 20px 15px 8px",r.style.display="flex",r.style.justifyContent="space-between",r.id="betterytm-menu-titlecont";const l=document.createElement("h2");l.id="betterytm-menu-title",l.innerText=`${i.name} - Configuration`;const c=document.createElement("div");c.id="betterytm-menu-linkscont";const a=(e,t,n)=>{const o=document.createElement("a");o.className="betterytm-menu-link",o.rel="noopener noreferrer",o.target="_blank",o.href=t,o.title=n,o.style.marginLeft="10px";const i=document.createElement("img");i.className="betterytm-menu-img",i.src=e,i.style.width="32px",i.style.height="32px",o.appendChild(i),c.appendChild(o)};a(`https://raw.githubusercontent.com/Sv443/BetterYTM/${m}/resources/external/github.png`,i.namespace,`${i.name} on GitHub`),a(`https://raw.githubusercontent.com/Sv443/BetterYTM/${m}/resources/external/greasyfork.png`,"https://greasyfork.org/xyz",`${i.name} on GreasyFork`);const d=document.createElement("img");d.id="betterytm-menu-close",d.src=`https://raw.githubusercontent.com/Sv443/BetterYTM/${m}/resources/icon/close.png`,d.title="Click to close the menu",d.style.marginLeft="50px",d.style.width="32px",d.style.height="32px",d.addEventListener("click",y),c.appendChild(d),r.appendChild(l),r.appendChild(c);const p=document.createElement("div");p.id="betterytm-menu-opts",p.style.display="flex",p.style.flexDirection="column";const f=(t,n,o)=>u(this,void 0,void 0,(function*(){const i=e=>"object"==typeof e?JSON.stringify(e):String(e);e&&console.info(`BetterYTM: Feature config changed, key '${t}' from value '${i(n)}' to '${i(o)}'`);const r=Object.assign({},yield j());r[t]=o,yield H(r),e&&console.log("BetterYTM: Saved feature config changes:\n",yield GM.getValue("betterytm-config"))})),h=yield j(),g=Object.keys(h);for(const e of g){const n=q[e];if(!n)continue;const{desc:o,type:i,default:r}=n,l=null!==(t=null==n?void 0:n.step)&&void 0!==t?t:void 0,s=h[e]||r||void 0,c=document.createElement("div");c.id=`betterytm-ftconf-${e}`,c.style.display="flex",c.style.flexDirection="row",c.style.justifyContent="space-between",c.style.padding="8px 20px";{const e=document.createElement("span");e.style.display="inline-block",e.style.fontSize="15px",e.innerText=o,c.appendChild(e)}{let t="text";switch(i){case"toggle":t="checkbox";break;case"slider":t="range";break;case"number":t="number"}const o=`betterytm-ftconf-${e}-input`,a=document.createElement("span");a.style.display="inline-block",a.style.whiteSpace="nowrap";const d=document.createElement("input");d.id=o,d.style.marginRight="37px",d.type=t,"toggle"===i&&(d.style.marginLeft="5px"),void 0!==s&&(d.value=String(s)),"number"===i&&l&&(d.step=l),n.min&&n.max&&(d.min=n.min,d.max=n.max),"toggle"===i&&void 0!==s&&(d.checked=Boolean(s));const u=(null==n?void 0:n.unit)?" "+n.unit:"",m=e=>String(e).trim(),y=e=>e?"On":"Off";let p;"slider"===i?(p=document.createElement("label"),p.classList.add("betterytm-ftconf-label"),p.style.marginRight="20px",p.style.fontSize="16px",p.htmlFor=o,p.innerText=m(s)+u,d.addEventListener("input",(()=>{p&&(p.innerText=m(parseInt(d.value)))}))):"toggle"===i&&void 0!==s&&(p=document.createElement("label"),p.classList.add("betterytm-ftconf-label"),p.style.paddingLeft="10px",p.style.paddingRight="5px",p.style.fontSize="16px",p.htmlFor=o,p.innerText=y(Boolean(s))+u,d.addEventListener("input",(()=>{p&&(p.innerText=y(d.checked)+u)}))),d.addEventListener("input",(({currentTarget:t})=>{const n=t;let o=parseInt(n.value);isNaN(o)&&(o=Number(n.value)),void 0!==s&&f(e,s,"toggle"!==i?o:n.checked)}));const h=document.createElement("button");h.innerText="Reset",h.addEventListener("click",(()=>{d["toggle"!==i?"value":"checked"]=r,p&&(p.innerText="toggle"===i?y(d.checked)+u:m(parseInt(d.value))+u),void 0!==s&&f(e,s,r)})),p&&a.appendChild(p),a.appendChild(d),a.appendChild(h),c.appendChild(a)}p.appendChild(c)}const b=document.createElement("div");b.style.marginTop="20px",b.style.fontSize="17px",b.style.textDecoration="underline",b.style.padding="8px 20px",b.innerText="You need to reload the page to apply changes.";const v=document.createElement("button");v.style.marginLeft="20px",v.innerText="Reload now",v.title="Click to reload the page",v.addEventListener("click",(()=>location.reload())),b.appendChild(v),p.appendChild(b);const w=document.createElement("div");w.id="betterytm-menu-body",w.appendChild(r),w.appendChild(p);const x=document.createElement("div");x.style.display="flex",x.style.justifyContent="space-around",x.style.fontSize="1.15em",x.style.marginTop="10px",x.style.marginBottom="5px";const T=document.createElement("span");T.id="betterytm-menu-version",T.innerText=`v${i.version}`,x.appendChild(T),p.appendChild(x),o.appendChild(w),o.appendChild(x),n.appendChild(o),document.body.appendChild(n),e&&console.log("BetterYTM: Added menu elem:",n),s('#betterytm-menu-bg {\n display: block;\n position: fixed;\n width: 100vw;\n height: 100vh;\n top: 0;\n left: 0;\n z-index: 15;\n background-color: rgba(0, 0, 0, 0.6);\n}\n\n/* TODO:FIXME: needs better positioning (vw and vh === "big no no") */\n#betterytm-menu {\n display: inline-block;\n position: fixed;\n width: 50vw;\n height: auto;\n min-height: 500px;\n left: 25vw;\n top: 25vh;\n z-index: 16;\n overflow: auto;\n padding: 8px;\n color: #fff;\n background-color: #212121;\n}\n\n#betterytm-menu-titlecont {\n display: flex;\n}\n\n#betterytm-menu-title {\n font-size: 20px;\n margin-top: 5px;\n margin-bottom: 8px;\n}\n\n#betterytm-menu-linkscont {\n display: flex;\n}\n\n.betterytm-menu-link {\n display: inline-block;\n}\n\n/*.betterytm-menu-img {\n\n}*/\n\n#betterytm-menu-close {\n cursor: pointer;\n}\n\n.betterytm-ftconf-label {\n user-select: none;\n}',"menu")}))}()}catch(e){console.error("BetterYTM: Couldn't add menu:",e)}}}catch(e){console.error("BetterYTM: General error while executing feature:",e)}}))}!function(){z(this,void 0,void 0,(function*(){yield function(){return e=this,t=void 0,o=function*(){p=yield j()},new((n=void 0)||(n=Promise))((function(i,r){function l(e){try{c(o.next(e))}catch(e){r(e)}}function s(e){try{c(o.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(l,s)}c((o=o.apply(e,t||[])).next())}));var e,t,n,o}();try{console.log(`${i.name} v${i.version} (${i.lastCommit}) - ${i.namespace}`),console.log(`Powered by lots of ambition and my song metadata API: ${T}`),s(`#betterytm-watermark{color:#fff;cursor:pointer;display:inline-block;font-size:10px;left:45px;position:absolute;text-decoration:none;top:46px;z-index:10}@media(max-width:615px){#betterytm-watermark{display:none}}#betterytm-watermark:hover{text-decoration:underline}.side-panel.modular ytmusic-player-queue-item .song-info.ytmusic-player-queue-item{position:relative}.side-panel.modular ytmusic-player-queue-item .song-info .bytm-queue-btn-container{display:none;position:absolute;right:0}.side-panel.modular ytmusic-player-queue-item:hover .song-info .bytm-queue-btn-container{display:inline-block}#betterytm-lyrics-button{align-items:center;background-color:transparent;border-radius:100%;height:40px;justify-content:center;margin-left:8px;position:relative;vertical-align:middle;width:40px}#betterytm-lyrics-button:hover{background-color:#383838}#betterytm-lyrics-img{display:inline-block;height:24px;padding:5px;width:24px;z-index:10}#bytm-menu-header-container{align-items:center;border-color:#fff;border-style:none solid none none;display:flex;justify-content:flex-start}.bytm-menu-header-option{align-items:center;border-color:#fff;border-style:solid none;display:"flex";justify-content:center}#bytm-menu-header-option h3{margin:0}.bytm-menu-tab[data-active=false],.bytm-menu-tab[data-active=true]{display:none}`,"global"),document.addEventListener("DOMContentLoaded",I)}catch(e){console.error("BetterYTM - General Error:",e)}try{document.addEventListener("DOMContentLoaded",(()=>{const e=document.createElement("div");e.id="bytm-menu-container",e.innerHTML='<dialog id="bytm-menu-dialog"> <div id="bytm-menu-header-container"> <div class="bytm-menu-header-option" id="bytm-menu-tab-options-header" data-active="true"> <h3>Options</h3> </div> <div class="bytm-menu-header-option" id="bytm-menu-tab-info-header" data-active="false"> <h3>Info</h3> </div> <div class="bytm-menu-header-option" id="bytm-menu-tab-changelog-header" data-active="false"> <h3>Changelog</h3> </div> </div> <div id="bytm-menu-body"> <div class="bytm-menu-tab-content" id="bytm-menu-tab-options-content" data-active="true"></div> <div class="bytm-menu-tab-content" id="bytm-menu-tab-info-content" data-active="false"> ayo info </div> <div class="bytm-menu-tab-content" id="bytm-menu-tab-changelog-content" data-active="false"></div> </div> </dialog> ',document.body.appendChild(e),Y()}))}catch(e){console.error("BetterYTM: Couldn't initialize menu:",e)}}))}()}()}();
  36. //# sourceMappingURL=BetterYTM.user.js.map