BetterYTM.user.js 26 KB

12345678910111213141516171819202122232425262728293031323334353637
  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 Improvements for YouTube Music
  7. // @description:de Verbesserungen für YouTube Music
  8. // @license MIT
  9. // @author Sv443
  10. // @copyright Sv443 <[email protected]>
  11. // @match https://music.youtube.com/*
  12. // @match https://www.youtube.com/*
  13. // @icon https://raw.githubusercontent.com/Sv443/BetterYTM/main/resources/icon/v2.1_200.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://github.com/Sv443/BetterYTM/raw/main/dist/BetterYTM.user.js
  22. // @updateURL https://github.com/Sv443/BetterYTM/raw/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. /* Disclaimer: I am not affiliated with YouTube, Google, Alphabet, Genius or anyone else */
  32. /* C&D this 🖕 */
  33. /*! For license information please see BetterYTM.user.js.LICENSE.txt */
  34. !function(){"use strict";var e={546:function(e,t){Object.defineProperty(t,"__esModule",{value:!0});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 i=0;i<n.length;i++)if(n[i]===t){n.splice(i,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 i=this.createEvent(e,t),o=0,r=n;o<r.length;o++){var l=r[o];this.isValidHandler(l)&&(l._once&&(i.once=!0),l(i),i.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.EventEmitter=n,t.globalEvent=new n},857:function(e,t,n){n.r(t),t.default='<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> '},358:function(e,t,n){var i=this&&this.__awaiter||function(e,t,n,i){return new(n||(n=Promise))((function(o,r){function l(e){try{a(i.next(e))}catch(e){r(e)}}function s(e){try{a(i.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(l,s)}a((i=i.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const o=n(913),r=n(601),l=n(582),s=n(593);i(void 0,void 0,void 0,(function*(){const e=yield(0,o.getFeatures)();yield(0,l.initLayout)();try{console.log(`${r.info.name} v${r.info.version} - ${r.info.namespace}`),console.log(`Powered by lots of ambition and my song metadata API called geniURL: ${l.geniUrlBase}`),document.addEventListener("DOMContentLoaded",(function(){return i(this,void 0,void 0,(function*(){const t=(0,s.getDomain)();r.dbg&&console.log(`BetterYTM: Initializing features for domain '${t}'`);try{if("ytm"===t&&(e.arrowKeySupport&&(0,l.initArrowKeySkip)(),e.removeUpgradeTab&&(0,l.removeUpgradeTab)(),e.watermarkEnabled&&(0,l.addWatermark)(),e.geniusLyrics&&(yield(0,l.addMediaCtrlGeniusBtn)()),e.lyricsButtonsOnSongQueue&&(yield(0,l.addQueueGeniusBtns)()),"number"==typeof e.volumeSliderSize&&(0,l.setVolSliderSize)(),(0,l.setVolSliderStep)()),["ytm","yt"].includes(t)){e.switchBetweenSites&&(0,l.initSiteSwitch)(t);try{(0,l.addMenu)()}catch(e){console.error("BetterYTM: Couldn't add menu:",e)}}}catch(e){console.error("BetterYTM: General error while executing feature:",e)}}))}))}catch(e){console.error("BetterYTM - General Error:",e)}yield(0,l.initChangelog)()}))},913:function(e,t,n){var i=this&&this.__awaiter||function(e,t,n,i){return new(n||(n=Promise))((function(o,r){function l(e){try{a(i.next(e))}catch(e){r(e)}}function s(e){try{a(i.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(l,s)}a((i=i.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.saveFeatureConf=t.loadFeatureConf=t.getFeatures=t.defaultFeatures=void 0;const o=n(582);let r;function l(){return i(this,void 0,void 0,(function*(){const e=Object.freeze(Object.assign({},t.defaultFeatures));try{const t=yield GM.getValue("betterytm-config");return"string"!=typeof t?(yield a(),r=e):Object.freeze(t?JSON.parse(t):{})}catch(t){return yield a(),r=e}}))}function s(e){if(!e||"object"!=typeof e)throw new TypeError("Feature config not provided or invalid");return GM.setValue("betterytm-config",JSON.stringify(e))}function a(){return GM.setValue("betterytm-config",JSON.stringify(t.defaultFeatures))}t.defaultFeatures=Object.keys(o.featInfo).reduce(((e,t)=>(e[t]=o.featInfo[t].default,e)),{}),t.getFeatures=function(e=!1){return i(this,void 0,void 0,(function*(){let n;if(void 0===r||e){const e=yield l();r=n=Object.assign(Object.assign({},t.defaultFeatures),e),yield s(n)}return r}))},t.loadFeatureConf=l,t.saveFeatureConf=s},601:function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.info=t.triesInterval=t.triesLimit=t.dbg=void 0,t.dbg=!0,t.triesLimit=50,t.triesInterval=150,t.info=Object.freeze({name:GM.info.script.name,version:GM.info.script.version,namespace:GM.info.script.namespace})},582:function(e,t,n){var i=this&&this.__createBinding||(Object.create?function(e,t,n,i){void 0===i&&(i=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,i,o)}:function(e,t,n,i){void 0===i&&(i=n),e[i]=t[n]}),o=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||i(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),t.featInfo=void 0,o(n(717),t),o(n(840),t),o(n(431),t),t.featInfo={arrowKeySupport:{desc:"Arrow keys skip forwards and backwards by 10 seconds",type:"toggle",default:!0},removeUpgradeTab:{desc:'Remove the "Upgrade" / YT Music Premium tab',type:"toggle",default:!0},switchBetweenSites:{desc:"Add F9 as a hotkey to switch between the YT and YTM sites on a video / song",type:"toggle",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",default:!0},lyricsButtonsOnSongQueue:{desc:'TODO: Add a lyrics button to each song in the queue ("up next" tab)',type:"toggle",default:!0},volumeSliderSize:{desc:"The width of the volume slider in pixels",type:"number",min:10,max:1e3,step:5,default:160},volumeSliderStep:{desc:"Volume slider sensitivity - the smaller this number, the finer the volume control",type:"slider",min:1,max:20,default:2},watermarkEnabled:{desc:"Show a BetterYTM watermark under the YTM logo",type:"toggle",default:!0}}},717:function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.initSiteSwitch=t.initArrowKeySkip=void 0;const i=n(593),o=n(601);function r(e){var t,n;if(["ArrowLeft","ArrowRight"].includes(e.code)){if(["INPUT","TEXTAREA","SELECT"].includes(null!==(n=null===(t=document.activeElement)||void 0===t?void 0:t.tagName)&&void 0!==n?n:"_"))return o.dbg&&console.info(`BetterYTM: Captured valid key but the current active element is <${document.activeElement.tagName.toLowerCase()}>, so the keypress is ignored`);o.dbg&&console.log(`BetterYTM: Captured key '${e.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};let r=!1,l={};switch(e.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)o.dbg&&console.warn(`BetterYTM: Captured key '${e.code}' has no defined behavior`);else{const t=Object.assign(Object.assign({code:""},i),l);document.body.dispatchEvent(new KeyboardEvent("keydown",t)),o.dbg&&console.log(`BetterYTM: Dispatched proxy keydown event: [${e.code}] -> [${t.code}]`)}}}t.initArrowKeySkip=function(){document.addEventListener("keydown",r),o.dbg&&console.log("BetterYTM: Added key press listener")},t.initSiteSwitch=function(e){document.addEventListener("keydown",(t=>{"F9"==t.key&&function(e){var t;try{let n;if("ytm"===e?n="music":"yt"===e&&(n="www"),!n)throw new TypeError(`Unrecognized domain '${e}'`);const{pathname:r,search:l,hash:s}=new URL(location.href),a=null!==(t=(0,i.getVideoTime)())&&void 0!==t?t:0;o.dbg&&console.log(`BetterYTM: Found video time of ${a} seconds`);const d=`https://${n}.youtube.com${r}${l.includes("?")?`${l}&t=${a}`:`?t=${a}`}${s}`;console.info(`BetterYTM - switching to domain '${e}' at ${d}`),location.href=d}catch(e){console.error("BetterYTM: Error while switching site:",e)}}("yt"===e?"ytm":"yt")})),o.dbg&&console.log("BetterYTM: Initialized site switch listener")}},840:function(e,t,n){var i=this&&this.__awaiter||function(e,t,n,i){return new(n||(n=Promise))((function(o,r){function l(e){try{a(i.next(e))}catch(e){r(e)}}function s(e){try{a(i.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(l,s)}a((i=i.apply(e,t||[])).next())}))},o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.initChangelog=t.setVolSliderStep=t.setVolSliderSize=t.removeUpgradeTab=t.addWatermark=t.openMenu=t.closeMenu=t.addMenu=t.initLayout=void 0;const r=n(601),l=n(913),s=n(593),a=n(582),d=o(n(857));let c;t.initLayout=function(){return i(this,void 0,void 0,(function*(){c=yield(0,l.getFeatures)()}))};const u=r.dbg?"develop":"main";function y(){const e=document.querySelector("#betterytm-menu-bg");e.style.visibility="hidden",e.style.display="none"}function f(){const e=document.querySelector("#betterytm-menu-bg");e.style.visibility="visible",e.style.display="block"}t.addMenu=function(){var e;return i(this,void 0,void 0,(function*(){const t=document.createElement("div");t.id="betterytm-menu-bg",t.title="Click here to close the menu",t.style.visibility="hidden",t.style.display="none",t.addEventListener("click",(e=>{"betterytm-menu-bg"===e.target.id&&y()}));const n=document.createElement("div");n.title="",n.id="betterytm-menu",n.style.borderRadius="15px",n.style.display="flex",n.style.flexDirection="column",n.style.justifyContent="space-between";const o=document.createElement("div");o.style.padding="8px 20px 15px 8px",o.style.display="flex",o.style.justifyContent="space-between",o.id="betterytm-menu-titlecont";const d=document.createElement("h2");d.id="betterytm-menu-title",d.innerText="BetterYTM - Configuration";const c=document.createElement("div");c.id="betterytm-menu-linkscont";const f=(e,t,n)=>{const i=document.createElement("a");i.className="betterytm-menu-link",i.rel="noopener noreferrer",i.target="_blank",i.href=t,i.title=n,i.style.marginLeft="10px";const o=document.createElement("img");o.className="betterytm-menu-img",o.src=e,o.style.width="32px",o.style.height="32px",i.appendChild(o),c.appendChild(i)};f(`https://raw.githubusercontent.com/Sv443/BetterYTM/${u}/resources/external/github.png`,r.info.namespace,`${r.info.name} on GitHub`),f(`https://raw.githubusercontent.com/Sv443/BetterYTM/${u}/resources/external/greasyfork.png`,"https://greasyfork.org/xyz",`${r.info.name} on GreasyFork`);const m=document.createElement("img");m.id="betterytm-menu-close",m.src=`https://raw.githubusercontent.com/Sv443/BetterYTM/${u}/resources/icon/close.png`,m.title="Click to close the menu",m.style.marginLeft="50px",m.style.width="32px",m.style.height="32px",m.addEventListener("click",y),c.appendChild(m),o.appendChild(d),o.appendChild(c);const p=document.createElement("div");p.id="betterytm-menu-opts",p.style.display="flex",p.style.flexDirection="column";const h=(e,t,n)=>i(this,void 0,void 0,(function*(){r.dbg&&console.info(`BetterYTM: Feature config changed, key '${e}' from value '${t}' to '${n}'`);const i=Object.assign({},yield(0,l.getFeatures)());i[e]=n,yield(0,l.saveFeatureConf)(i),r.dbg&&console.log("BetterYTM: Saved feature config changes:\n",yield GM.getValue("betterytm-config"))})),g=yield(0,l.getFeatures)(),b=Object.keys(g);for(const t of b){const n=a.featInfo[t];if(!n)continue;const{desc:i,type:o,default:r}=n,l=null!==(e=null==n?void 0:n.step)&&void 0!==e?e:void 0,s=g[t]||r||void 0,d=document.createElement("div");d.id=`betterytm-ftconf-${t}`,d.style.display="flex",d.style.flexDirection="row",d.style.justifyContent="space-between",d.style.padding="8px 20px";{const e=document.createElement("span");e.style.display="inline-block",e.style.fontSize="15px",e.innerText=i,d.appendChild(e)}{let e="text";switch(o){case"toggle":e="checkbox";break;case"slider":e="range";break;case"number":e="number"}const i=`betterytm-ftconf-${t}-input`,a=document.createElement("span");a.style.display="inline-block",a.style.whiteSpace="nowrap";const c=document.createElement("input");c.id=i,c.style.marginRight="37px",c.type=e,"toggle"===o&&(c.style.marginLeft="5px"),void 0!==s&&(c.value=String(s)),"number"===o&&l&&(c.step=l),n.min&&n.max&&(c.min=n.min,c.max=n.max),"toggle"===o&&void 0!==s&&(c.checked=Boolean(s));const u=e=>String(e),y=e=>e?"On":"Off";let f;"slider"===o?(f=document.createElement("label"),f.classList.add("betterytm-ftconf-label"),f.style.marginRight="20px",f.style.fontSize="16px",f.htmlFor=i,f.innerText=u(s),c.addEventListener("input",(()=>{f&&(f.innerText=u(parseInt(c.value)))}))):"toggle"===o&&void 0!==s&&(f=document.createElement("label"),f.classList.add("betterytm-ftconf-label"),f.style.paddingLeft="10px",f.style.paddingRight="5px",f.style.fontSize="16px",f.htmlFor=i,f.innerText=y(Boolean(s)),c.addEventListener("input",(()=>{f&&(f.innerText=y(c.checked))}))),c.addEventListener("input",(({currentTarget:e})=>{const n=e;let i=parseInt(n.value);isNaN(i)&&(i=Number(n.value)),void 0!==s&&h(t,s,"toggle"!==o?i:n.checked)}));const m=document.createElement("button");m.innerText="Reset",m.addEventListener("click",(()=>{c["toggle"!==o?"value":"checked"]=r,f&&(f.innerText="toggle"===o?y(c.checked):u(parseInt(c.value))),void 0!==s&&h(t,s,r)})),f&&a.appendChild(f),a.appendChild(c),a.appendChild(m),d.appendChild(a)}p.appendChild(d)}const v=document.createElement("div");v.style.marginTop="20px",v.style.fontSize="17px",v.style.textDecoration="underline",v.style.padding="8px 20px",v.innerText="You need to reload the page to apply changes.";const w=document.createElement("button");w.style.marginLeft="20px",w.innerText="Reload now",w.title="Click to reload the page",w.addEventListener("click",(()=>location.reload())),v.appendChild(w),p.appendChild(v);const x=document.createElement("div");x.id="betterytm-menu-body",x.appendChild(o),x.appendChild(p);const S=document.createElement("div");S.style.display="flex",S.style.justifyContent="space-around",S.style.fontSize="1.15em",S.style.marginTop="10px",S.style.marginBottom="5px";const T=document.createElement("span");T.id="betterytm-menu-version",T.innerText=`v${r.info.version}`,S.appendChild(T),p.appendChild(S),n.appendChild(x),n.appendChild(S),t.appendChild(n),document.body.appendChild(t),r.dbg&&console.log("BetterYTM: Added menu elem:",t),(0,s.addGlobalStyle)("#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#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")}))},t.closeMenu=y,t.openMenu=f,t.addWatermark=function(){const e=document.createElement("span");e.id="betterytm-watermark",e.className="style-scope ytmusic-nav-bar",e.innerText=r.info.name,e.title="Open menu",e.addEventListener("click",(()=>f())),(0,s.addGlobalStyle)("#betterytm-watermark {\n font-size: 10px;\n display: inline-block;\n position: absolute;\n left: 45px;\n top: 46px;\n z-index: 10;\n color: white;\n text-decoration: none;\n cursor: pointer;\n}\n\n@media(max-width: 615px) {\n #betterytm-watermark {\n display: none;\n }\n}\n\n#betterytm-watermark:hover {\n text-decoration: underline;\n}","watermark");const t=document.querySelector("#left-content");(0,s.insertAfter)(t,e),r.dbg&&console.log("BetterYTM: Added watermark element:",e)};let m=0;t.removeUpgradeTab=function e(){const t=document.querySelector('.ytmusic-nav-bar ytmusic-pivot-bar-item-renderer[tab-id="SPunlimited"]');t?(t.remove(),r.dbg&&console.log(`BetterYTM: Removed upgrade tab after ${m} tries`)):m<r.triesLimit?(setTimeout(e,r.triesInterval),m++):console.error(`BetterYTM: Couldn't find upgrade tab to remove after ${m} tries`)},t.setVolSliderSize=function(){const{volumeSliderSize:e}=c;if("number"!=typeof e||isNaN(Number(e)))return;const t=`.volume-slider.ytmusic-player-bar, .expand-volume-slider.ytmusic-player-bar {\n width: ${e}px !important;\n}`;(0,s.addGlobalStyle)(t,"vol_slider_size")},t.setVolSliderStep=function(){document.querySelector("tp-yt-paper-slider#volume-slider").setAttribute("step",String(c.volumeSliderStep))},t.initChangelog=function(){return i(this,void 0,void 0,(function*(){d.default}))}},431:function(e,t,n){var i=this&&this.__awaiter||function(e,t,n,i){return new(n||(n=Promise))((function(o,r){function l(e){try{a(i.next(e))}catch(e){r(e)}}function s(e){try{a(i.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(l,s)}a((i=i.apply(e,t||[])).next())}))},o=this&&this.__asyncValues||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={},i("next"),i("throw"),i("return"),t[Symbol.asyncIterator]=function(){return this},t);function i(n){t[n]=e[n]&&function(t){return new Promise((function(i,o){!function(e,t,n,i){Promise.resolve(i).then((function(t){e({value:t,done:n})}),t)}(i,o,(t=e[n](t)).done,t.value)}))}}};Object.defineProperty(t,"__esModule",{value:!0}),t.getCurrentGeniusUrl=t.addQueueGeniusBtns=t.addMediaCtrlGeniusBtn=t.geniUrlBase=void 0;const r=n(601),l=n(593);t.geniUrlBase="https://api.sv443.net/geniurl";const s=`${t.geniUrlBase}/search/top`;let a="",d=0;function c(){var e,t;return i(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"),r=document.querySelector("span.subtitle > yt-formatted-string:first-child");if(!o||!r||!o.title)return null;const l=e=>e.replace(/\(.+\)/gim,"").replace(/\[.+\]/gim,"").trim(),s=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()),a=l(o.title),d=s(r.title),c=()=>i(this,void 0,void 0,(function*(){if(!a.includes("-"))return yield u(d,a);const[e,...t]=a.split("-").map((e=>e.trim()));return yield u(e,t.join(" "))}));return n?yield c():null!==(t=yield u(d,a))&&void 0!==t?t:yield c()}catch(e){return console.error("BetterYTM: Couldn't resolve genius.com URL:",e),null}}))}function u(e,t){return i(this,void 0,void 0,(function*(){try{const n=`${s}?artist=${encodeURIComponent(e)}&song=${encodeURIComponent(t)}`;r.dbg&&console.log(`BetterYTM: Requesting URL from geniURL at '${n}'`);const i=yield(yield fetch(n)).json();if(i.error)return void console.error("BetterYTM: Couldn't fetch genius.com URL:",i.message);const o=i.url;return r.dbg&&console.info(`BetterYTM: Found genius URL: ${o}`),o}catch(e){return void console.error("BetterYTM: Couldn't get genius URL due to error:",e)}}))}t.addMediaCtrlGeniusBtn=function e(){return i(this,void 0,void 0,(function*(){const t=document.querySelector(".middle-controls-buttons ytmusic-like-button-renderer#like-button-renderer");if(!t)return d++,d<r.triesLimit?setTimeout(e,r.triesInterval):console.error(`BetterYTM: Couldn't find element to append lyrics buttons to after ${d} tries`);const n=document.querySelector(".content-info-wrapper > yt-formatted-string"),s=yield c(),u=document.createElement("a");u.id="betterytm-lyrics-button",u.className="ytmusic-player-bar",u.title=s?"Click to open this song's lyrics in a new tab":"Loading...",s&&(u.href=s),u.target="_blank",u.rel="noopener noreferrer",u.style.visibility=s?"initial":"hidden",u.style.display=s?"inline-flex":"none",(0,l.addGlobalStyle)(" #betterytm-lyrics-button {\n align-items: center;\n justify-content: center;\n position: relative;\n vertical-align: middle;\n\n margin-left: 8px;\n width: 40px;\n height: 40px;\n border-radius: 100%;\n background-color: transparent;\n }\n\n #betterytm-lyrics-button:hover {\n background-color: #383838;\n }\n\n #betterytm-lyrics-img {\n display: inline-block;\n z-index: 10;\n width: 24px;\n height: 24px;\n padding: 5px;\n }","lyrics");const y=document.createElement("img");y.id="betterytm-lyrics-img",y.src="https://raw.githubusercontent.com/Sv443/BetterYTM/main/resources/external/genius.png",u.appendChild(y),r.dbg&&console.log(`BetterYTM: Inserted genius button after ${d} tries:`,u),(0,l.insertAfter)(t,u),a=n.title,new MutationObserver((e=>{var t,n,l;return i(this,void 0,void 0,(function*(){var i,s,d,u;try{for(t=!0,n=o(e);!(i=(l=yield n.next()).done);){u=l.value,t=!1;try{const e=u.target.title;if(e!=a&&e.length>0){const t=document.querySelector("#betterytm-lyrics-button");if(!t)return;r.dbg&&console.log(`BetterYTM: Song title changed from '${a}' to '${e}'`),t.style.cursor="wait",t.style.pointerEvents="none",a=e;const n=yield c();if(!n)continue;t.href=n,t.title="Click to open this song's lyrics in a new tab",t.style.cursor="pointer",t.style.visibility="initial",t.style.display="inline-flex",t.style.pointerEvents="initial"}}finally{t=!0}}}catch(e){s={error:e}}finally{try{t||i||!(d=n.return)||(yield d.call(n))}finally{if(s)throw s.error}}}))})).observe(n,{attributes:!0,attributeFilter:["title"]})}))},t.addQueueGeniusBtns=function(){return i(this,void 0,void 0,(function*(){}))},t.getCurrentGeniusUrl=c},593:function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.siteEvents=t.addGlobalStyle=t.insertAfter=t.getVideoTime=t.getDomain=void 0;const i=n(546),o=n(601);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.")}t.getDomain=r,t.getVideoTime=function(){var e;const t=r();try{return"ytm"===t?null!==(e=document.querySelector("#progress-bar").value)&&void 0!==e?e:null:"yt"===t?0:null}catch(e){return console.error("BetterYTM: Couldn't get video time due to error:",e),null}},t.insertAfter=function(e,t){var n;return null===(n=e.parentNode)||void 0===n||n.insertBefore(t,e.nextSibling),t},t.addGlobalStyle=function(e,t){"string"==typeof t&&0!==t.length||(t=String(Math.floor(1e4*Math.random())));const n=document.createElement("style");n.id=`betterytm-style-${t}`,n.innerHTML=e,document.querySelector("head").appendChild(n),o.dbg&&console.log(`BetterYTM: Inserted global style with ref '${t}':`,n)};class l extends i.EventEmitter{constructor(){super(),document.addEventListener("DOMContentLoaded",this.initObserver)}initObserver(){}}t.siteEvents=new l}},t={};function n(i){var o=t[i];if(void 0!==o)return o.exports;var r=t[i]={exports:{}};return e[i].call(r.exports,r,r.exports,n),r.exports}n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n(358)}();