123456789101112131415161718192021222324252627282930313233343536373839 |
- // ==UserScript==
- // @name BetterYTM
- // @homepageURL https://github.com/Sv443/BetterYTM#readme
- // @namespace https://github.com/Sv443/BetterYTM
- // @version 1.0.0
- // @description Configurable layout and UX improvements for YouTube Music
- // @description:de Konfigurierbares Layout und UX-Verbesserungen für YouTube Music
- // @license MIT
- // @author Sv443
- // @copyright Sv443 (https://github.com/Sv443)
- // @match https://music.youtube.com/*
- // @match https://www.youtube.com/*
- // @icon https://raw.githubusercontent.com/Sv443/BetterYTM/main/resources/icon/icon.png
- // @run-at document-start
- // @grant GM.getValue
- // @grant GM.setValue
- // @connect self
- // @connect youtube.com
- // @connect github.com
- // @connect githubusercontent.com
- // @downloadURL https://raw.githubusercontent.com/Sv443/BetterYTM/main/dist/BetterYTM.user.js
- // @updateURL https://raw.githubusercontent.com/Sv443/BetterYTM/main/dist/BetterYTM.user.js
- // ==/UserScript==
- /*
- ▄▄▄ ▄ ▄▄▄▄▄▄ ▄
- █ █ ▄▄▄ █ █ ▄▄▄ ▄ ▄█ █ █ █▀▄▀█
- █▀▀▄ █▄█ █▀ █▀ █▄█ █▀ █ █ █ █
- █▄▄▀ ▀▄▄ ▀▄▄ ▀▄▄ ▀▄▄ █ █ █ █ █
- Made with ❤️ by Sv443
- I welcome every contribution on GitHub!
- https://github.com/Sv443/BetterYTM
- */
- /* Disclaimer: I am not affiliated with YouTube, Google, Alphabet, Genius or anyone else */
- /* C&D this 🖕 */
- !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 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.vp=n,new n}},t={};function n(i){var o=t[i];if(void 0!==o)return o.exports;var r=t[i]={exports:{}};return e[i](r,r.exports,n),r.exports}!function(){const e="develop",t=25,i=200,o=Object.freeze({name:GM.info.script.name,version:GM.info.script.version,namespace:GM.info.script.namespace,lastCommit:"cd4514b"});var r=n(546);let l=1;function a(...e){return"number"==typeof e.at(-1)?e.splice(e.length-1,1)[0]:0}function s(...e){l<=a(...e)&&console.log(`${o.name}: `,...e)}function c(...e){l<=a(...e)&&console.info(`${o.name}: `,...e)}function d(...e){console.error(`${o.name}: `,...e)}function u(){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 m(e,t){var n;return null===(n=e.parentNode)||void 0===n||n.insertBefore(t,e.nextSibling),t}function y(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.head.appendChild(n),s(`Inserted global style with ref '${t}':`,n)}const p=new r.vp;let f=null;function h(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 c(`Captured valid key but the current active element is <${document.activeElement.tagName.toLowerCase()}>, so the keypress is ignored`);s(`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,view:window};let r=!1,d={};switch(e.code){case"ArrowLeft":d={code:"KeyH",key:"h",keyCode:72,which:72};break;case"ArrowRight":d={code:"KeyL",key:"l",keyCode:76,which:76};break;default:r=!0}if(r)!function(...e){l<=a(...e)&&console.warn(`${o.name}: `,...e)}(`Captured key '${e.code}' has no defined behavior`);else{const t=Object.assign(Object.assign({code:""},i),d);document.body.dispatchEvent(new KeyboardEvent("keydown",t)),s(`Dispatched proxy keydown event: [${e.code}] -> [${t.code}]`)}}}let b=!0;function v(){b=!1,c("Disabled popup before leaving the site")}var g=function(e,t,n,i){return new(n||(n=Promise))((function(o,r){function l(e){try{s(i.next(e))}catch(e){r(e)}}function a(e){try{s(i.throw(e))}catch(e){r(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(l,a)}s((i=i.apply(e,t||[])).next())}))};function w(){const e=document.querySelector("#betterytm-menu-bg");e.style.visibility="hidden",e.style.display="none"}let x;let k=0;function S(){const e=document.querySelector('.ytmusic-nav-bar ytmusic-pivot-bar-item-renderer[tab-id="SPunlimited"]');e?(e.remove(),s(`Removed upgrade tab after ${k} tries`)):k<t?(setTimeout(S,i),k++):console.error(`Couldn't find upgrade tab to remove after ${k} tries`)}function E(){const{volumeSliderSize:e}=x;"number"!=typeof e||isNaN(Number(e))||y(`.volume-slider.ytmusic-player-bar, .expand-volume-slider.ytmusic-player-bar {\n width: ${e}px !important;\n}`,"vol-slider")}function T(){document.querySelector("tp-yt-paper-slider#volume-slider").setAttribute("step",String(x.volumeSliderStep))}function C(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 $=function(e,t,n,i){return new(n||(n=Promise))((function(o,r){function l(e){try{s(i.next(e))}catch(e){r(e)}}function a(e){try{s(i.throw(e))}catch(e){r(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(l,a)}s((i=i.apply(e,t||[])).next())}))},L=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)}))}}};const O="https://api.sv443.net/geniurl",q=`${O}/search/top`;let M="",_=0;function N(){return $(this,void 0,void 0,(function*(){const e=document.querySelector(".middle-controls-buttons ytmusic-like-button-renderer#like-button-renderer");if(!e)return _++,_<t?setTimeout(N,i):console.error(`Couldn't find element to append lyrics buttons to after ${_} tries`);const n=document.querySelector(".content-info-wrapper > yt-formatted-string"),o=yield A(),r=document.createElement("a");r.id="betterytm-lyrics-button",r.className="ytmusic-player-bar",r.title=o?"Click to open this song's lyrics in a new tab":"Loading...",o&&(r.href=o),r.target="_blank",r.rel="noopener noreferrer",r.style.visibility=o?"initial":"hidden",r.style.display=o?"inline-flex":"none";const l=document.createElement("img");l.id="betterytm-lyrics-img",l.src="https://raw.githubusercontent.com/Sv443/BetterYTM/main/resources/external/genius.png",r.appendChild(l),s(`Inserted genius button after ${_} tries:`,r),m(e,r),M=n.title,new MutationObserver((e=>{var t,n,i;return $(this,void 0,void 0,(function*(){var o,r,l,a;try{for(t=!0,n=L(e);!(o=(i=yield n.next()).done);){a=i.value,t=!1;try{const e=a.target.title;if(e!=M&&e.length>0){const t=document.querySelector("#betterytm-lyrics-button");if(!t)return;s(`Song title changed from '${M}' to '${e}'`),t.style.cursor="wait",t.style.pointerEvents="none",M=e;const n=yield A();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){r={error:e}}finally{try{t||o||!(l=n.return)||(yield l.call(n))}finally{if(r)throw r.error}}}))})).observe(n,{attributes:!0,attributeFilter:["title"]})}))}function A(){var e,t;return $(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_")),i=document.querySelector(".content-info-wrapper > yt-formatted-string"),o=document.querySelector("span.subtitle > yt-formatted-string:first-child");if(!i||!o||!i.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()),a=r(i.title),s=l(o.title),c=()=>$(this,void 0,void 0,(function*(){if(!a.includes("-"))return yield R(s,a);const[e,...t]=a.split("-").map((e=>e.trim()));return yield R(e,t.join(" "))}));return n?yield c():null!==(t=yield R(s,a))&&void 0!==t?t:yield c()}catch(e){return d("Couldn't resolve genius.com URL:",e),null}}))}function R(e,t){return $(this,void 0,void 0,(function*(){try{const n=`${q}?artist=${encodeURIComponent(e)}&song=${encodeURIComponent(t)}`;s(`Requesting URL from geniURL at '${n}'`);const i=yield(yield fetch(n)).json();if(i.error)return void d("Couldn't fetch genius.com URL:",i.message);const o=i.url;return c(`Found genius URL: ${o}`),o}catch(e){return void d("Couldn't get genius URL due to error:",e)}}))}const j={options:"bytm-menu-tab-options",info:"bytm-menu-tab-info",changelog:"bytm-menu-tab-changelog"};let H=0;function z(){var e;if(!document.querySelector("#bytm-menu-dialog"))return H++<t?setTimeout(z,i):console.error(`couldn't create menu element after ${t} tries.`);for(const t in j){const n=j[t];null===(e=document.querySelector(`#${n}-header`))||void 0===e||e.addEventListener("click",(()=>{B(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 "Upgrade to YTM Premium" 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 B(e){const t=Object.assign({},j);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(`#${j[e]}-header`).dataset.active="true",document.querySelector(`#${j[e]}-content`).dataset.active="true"}const I=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}},disableBeforeUnloadPopup:{desc:"Whether to completely disable the popup that sometimes appears before leaving the site",type:"toggle",category:"input",default:!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 ${o.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 U=function(e,t,n,i){return new(n||(n=Promise))((function(o,r){function l(e){try{s(i.next(e))}catch(e){r(e)}}function a(e){try{s(i.throw(e))}catch(e){r(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(l,a)}s((i=i.apply(e,t||[])).next())}))};const P=Object.keys(I).reduce(((e,t)=>(e[t]=I[t].default,e)),{});let V;function Y(e=!1){return U(this,void 0,void 0,(function*(){return(void 0===V||e)&&(yield D(V=Object.assign(Object.assign({},P),yield function(){return U(this,void 0,void 0,(function*(){const e=Object.freeze(Object.assign({},P));try{const t=yield GM.getValue("betterytm-config");return"string"!=typeof t?(yield F(),V=e):Object.freeze(t?JSON.parse(t):{})}catch(t){return yield F(),V=e}}))}()))),V}))}function D(e){if(!e||"object"!=typeof e)throw new TypeError("Feature config not provided or invalid");return s(""),V=Object.assign({},e),GM.setValue("betterytm-config",JSON.stringify(e))}function F(){return V=Object.assign({},P),GM.setValue("betterytm-config",JSON.stringify(P))}var G=function(e,t,n,i){return new(n||(n=Promise))((function(o,r){function l(e){try{s(i.next(e))}catch(e){r(e)}}function a(e){try{s(i.throw(e))}catch(e){r(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(l,a)}s((i=i.apply(e,t||[])).next())}))};console.log(`${o.name} v${o.version} (${o.lastCommit}) - ${o.namespace}`),console.log(`Powered by lots of ambition and my song metadata API: ${O}`);const K=u();function J(){return G(this,void 0,void 0,(function*(){y(`#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");const t=yield Y();s(`Initializing features for domain '${K}'`);try{if("ytm"===K&&(function(){try{const e=new MutationObserver((([{addedNodes:e,removedNodes:t,target:n}])=>{(e.length>0||t.length>0)&&(c("Detected queue change - added nodes:",e.length,"- removed nodes:",t.length),p.fire("queueChanged",n))}));e.observe(document.querySelector(".side-panel.modular #contents.ytmusic-player-queue"),{childList:!0}),c("Successfully initialized SiteEvents observers"),f=[e]}catch(e){console.error("Couldn't initialize SiteEvents observers due to an error:\n",e)}}(),t.arrowKeySupport&&(document.addEventListener("keydown",h),s("Added key press listener")),t.removeUpgradeTab&&S(),t.watermarkEnabled&&function(){const e=document.createElement("span");e.id="betterytm-watermark",e.className="style-scope ytmusic-nav-bar",e.innerText=o.name,e.title="Open menu",e.addEventListener("click",(()=>function(){const e=document.querySelector("#betterytm-menu-bg");e.style.visibility="visible",e.style.display="block"}())),m(document.querySelector("#left-content"),e),s("Added watermark element:",e)}(),t.geniusLyrics&&N(),t.queueButtons&&function(){p.on("queueChanged",(e=>{for(const t of e.data.childNodes)t.classList.contains("bytm-has-queue-btns")||C(t)}));const e=document.querySelectorAll("#contents.ytmusic-player-queue > ytmusic-player-queue-item");0!==e.length&&e.forEach((e=>C(e)))}(),"number"==typeof t.volumeSliderSize&&E(),t.anchorImprovements,T()),["ytm","yt"].includes(K)){t.switchBetweenSites&&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:i,search:o,hash:r}=new URL(location.href),l=null!==(t=function(e=!1){const t=u();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("Couldn't get video time due to error:",e),null}}())&&void 0!==t?t:0;s(`Found video time of ${l} seconds`);const a=`https://${n}.youtube.com${i}${o.includes("?")?`${o}&t=${l}`:`?t=${l}`}${r}`;console.info(`BetterYTM - switching to domain '${e}' at ${a}`),v(),setImmediate((()=>location.href=a))}catch(e){console.error("Error while switching site:",e)}}("yt"===e?"ytm":"yt")})),s("Initialized site switch listener")}(K);try{!function(){var t,n;g(this,void 0,void 0,(function*(){const i=document.createElement("div");i.id="betterytm-menu-bg",i.title="Click here to close the menu",i.style.visibility="hidden",i.style.display="none",i.addEventListener("click",(e=>{"betterytm-menu-bg"===e.target.id&&w()}));const r=document.createElement("div");r.title="",r.id="betterytm-menu",r.style.borderRadius="15px",r.style.display="flex",r.style.flexDirection="column",r.style.justifyContent="space-between";const l=document.createElement("div");l.style.padding="8px 20px 15px 8px",l.style.display="flex",l.style.justifyContent="space-between",l.id="betterytm-menu-titlecont";const a=document.createElement("h2");a.id="betterytm-menu-title",a.innerText=`${o.name} - Configuration`;const d=document.createElement("div");d.id="betterytm-menu-linkscont";const u=(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),d.appendChild(i)};u(`https://raw.githubusercontent.com/Sv443/BetterYTM/${e}/resources/external/github.png`,o.namespace,`${o.name} on GitHub`),u(`https://raw.githubusercontent.com/Sv443/BetterYTM/${e}/resources/external/greasyfork.png`,"https://greasyfork.org/xyz",`${o.name} on GreasyFork`);const m=document.createElement("img");m.id="betterytm-menu-close",m.src=`https://raw.githubusercontent.com/Sv443/BetterYTM/${e}/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",w),d.appendChild(m),l.appendChild(a),l.appendChild(d);const p=document.createElement("div");p.id="betterytm-menu-opts",p.style.display="flex",p.style.flexDirection="column",p.style.overflowY="auto";const f=(e,t,n)=>g(this,void 0,void 0,(function*(){const i=e=>"object"==typeof e?JSON.stringify(e):String(e);c(`Feature config changed, key '${e}' from value '${i(t)}' to '${i(n)}'`);const o=Object.assign({},yield Y());o[e]=n,yield D(o),s("Saved feature config changes:\n",yield GM.getValue("betterytm-config"))})),h=yield Y();for(const e in h){const i=I[e];if(!i)continue;const{desc:o,type:r,default:l}=i,a=null!==(t=null==i?void 0:i.step)&&void 0!==t?t:void 0,s=h[e],c=null!==(n=null!=s?s:l)&&void 0!==n?n:void 0,d=document.createElement("div");d.id=`betterytm-ftconf-${e}`,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=o,d.appendChild(e)}{let t="text";switch(r){case"toggle":t="checkbox";break;case"slider":t="range";break;case"number":t="number"}const n=`betterytm-ftconf-${e}-input`,o=document.createElement("span");o.style.display="inline-block",o.style.whiteSpace="nowrap";const s=document.createElement("input");s.id=n,s.style.marginRight="37px",s.type=t,"toggle"===r&&(s.style.marginLeft="5px"),void 0!==c&&(s.value=String(c)),"number"===r&&a&&(s.step=a),i.min&&i.max&&(s.min=i.min,s.max=i.max),"toggle"===r&&void 0!==c&&(s.checked=Boolean(c));const u=(null==i?void 0:i.unit)?" "+i.unit:"",m=e=>String(e).trim(),y=e=>e?"On":"Off";let p;"slider"===r?(p=document.createElement("label"),p.classList.add("betterytm-ftconf-label"),p.style.marginRight="20px",p.style.fontSize="16px",p.htmlFor=n,p.innerText=m(c)+u,s.addEventListener("input",(()=>{p&&(p.innerText=m(parseInt(s.value)))}))):"toggle"===r&&(p=document.createElement("label"),p.classList.add("betterytm-ftconf-label"),p.style.paddingLeft="10px",p.style.paddingRight="5px",p.style.fontSize="16px",p.htmlFor=n,p.innerText=y(Boolean(c))+u,s.addEventListener("input",(()=>{p&&(p.innerText=y(s.checked)+u)}))),s.addEventListener("input",(()=>{let t=parseInt(s.value);isNaN(t)&&(t=Number(s.value)),void 0!==c&&f(e,c,"toggle"!==r?t:s.checked)}));const h=document.createElement("button");h.innerText="Reset",h.addEventListener("click",(()=>{s["toggle"!==r?"value":"checked"]=l,p&&(p.innerText="toggle"===r?y(s.checked)+u:m(parseInt(s.value))+u),void 0!==c&&f(e,c,l)})),p&&o.appendChild(p),o.appendChild(s),o.appendChild(h),d.appendChild(o)}p.appendChild(d)}const b=document.createElement("div");b.id="betterytm-menu-footer",b.style.marginTop="20px",b.style.fontSize="17px",b.style.textDecoration="underline",b.style.padding="10px 20px",b.style.position="sticky",b.style.backgroundColor="var(--bytm-menu-bg)",b.style.bottom="0",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 x=document.createElement("div");x.id="betterytm-menu-body",x.appendChild(l),x.appendChild(p);const k=document.createElement("div");k.style.display="flex",k.style.justifyContent="space-around",k.style.fontSize="1.15em",k.style.marginTop="10px",k.style.marginBottom="5px";const S=document.createElement("span");S.id="betterytm-menu-version",S.innerText=`v${o.version}`,k.appendChild(S),p.appendChild(k),r.appendChild(x),r.appendChild(k),i.appendChild(r),document.body.appendChild(i),s("Added menu elem:",i),y(':root {\n --bytm-menu-bg: #212121;\n}\n\n#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 left: 25vw;\n top: 10vh;\n z-index: 16;\n padding: 8px;\n color: #fff;\n background-color: var(--bytm-menu-bg);\n}\n\n#betterytm-menu-opts {\n max-height: 70vh;\n overflow: auto;\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("Couldn't add menu:",e)}}}catch(e){console.error("General error while executing feature:",e)}}))}var W;l=0,"ytm"===K&&(Error.stackTraceLimit=1/0,W=window.__proto__.addEventListener,window.__proto__.addEventListener=function(...e){const[t,n,...i]=e;return"beforeunload"===t?W.apply(this,[t,(...e)=>{b&&n(...e)},...i]):W.apply(this,e)},Y().then((e=>{e.disableBeforeUnloadPopup&&v()}))),function(){G(this,void 0,void 0,(function*(){yield function(){return e=this,t=void 0,i=function*(){x=yield Y()},new((n=void 0)||(n=Promise))((function(o,r){function l(e){try{s(i.next(e))}catch(e){r(e)}}function a(e){try{s(i.throw(e))}catch(e){r(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(l,a)}s((i=i.apply(e,t||[])).next())}));var e,t,n,i}();try{document.addEventListener("DOMContentLoaded",J)}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),z()}))}catch(e){d("Couldn't initialize menu:",e)}}))}()}()}();
- //# sourceMappingURL=BetterYTM.user.js.map
|