BetterYTM.user.js 89 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030
  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/assets/icon/icon.png
  14. // @run-at document-start
  15. // @grant GM.getValue
  16. // @grant GM.setValue
  17. // @grant unsafeWindow
  18. // @connect self
  19. // @connect youtube.com
  20. // @connect github.com
  21. // @connect githubusercontent.com
  22. // @downloadURL https://raw.githubusercontent.com/Sv443/BetterYTM/main/dist/BetterYTM.user.js
  23. // @updateURL https://raw.githubusercontent.com/Sv443/BetterYTM/main/dist/BetterYTM.user.js
  24. // ==/UserScript==
  25. /*
  26. ▄▄▄ ▄ ▄▄▄▄▄▄ ▄
  27. █ █ ▄▄▄ █ █ ▄▄▄ ▄ ▄█ █ █ █▀▄▀█
  28. █▀▀▄ █▄█ █▀ █▀ █▄█ █▀ █ █ █ █
  29. █▄▄▀ ▀▄▄ ▀▄▄ ▀▄▄ ▀▄▄ █ █ █ █ █
  30. Made with ❤️ by Sv443
  31. I welcome every contribution on GitHub!
  32. https://github.com/Sv443/BetterYTM
  33. */
  34. /* Disclaimer: I am not affiliated with YouTube, Google, Alphabet, Genius or anyone else */
  35. /* C&D this 🖕 */
  36. /******/ var __webpack_modules__ = ({
  37. /***/ "./node_modules/@billjs/event-emitter/lib/index.js":
  38. /*!*********************************************************!*\
  39. !*** ./node_modules/@billjs/event-emitter/lib/index.js ***!
  40. \*********************************************************/
  41. /***/ (function(__unused_webpack_module, exports) {
  42. /**
  43. * A simple and lightweight EventEmitter by TypeScript for Node.js or Browsers.
  44. *
  45. * @author billjs
  46. * @see https://github.com/billjs/event-emitter
  47. * @license MIT(https://opensource.org/licenses/MIT)
  48. */
  49. Object.defineProperty(exports, "__esModule", ({ value: true }));
  50. /**
  51. * It's a class for managing events.
  52. * It can be extended to provide event functionality for other classes or object.
  53. *
  54. * @export
  55. * @class EventEmitter
  56. */
  57. var EventEmitter = /** @class */ (function () {
  58. function EventEmitter() {
  59. /**
  60. * the all event handlers are added.
  61. * it's a Map data structure(key-value), the key is event type, and the value is event handler.
  62. *
  63. * @memberof EventEmitter
  64. */
  65. this._eventHandlers = {};
  66. }
  67. /**
  68. * event type validator.
  69. *
  70. * @param {string} type event type
  71. * @returns {boolean}
  72. * @memberof EventEmitter
  73. */
  74. EventEmitter.prototype.isValidType = function (type) {
  75. return typeof type === 'string';
  76. };
  77. /**
  78. * event handler validator.
  79. *
  80. * @param {EventHandler} handler event handler
  81. * @returns {boolean}
  82. * @memberof EventEmitter
  83. */
  84. EventEmitter.prototype.isValidHandler = function (handler) {
  85. return typeof handler === 'function';
  86. };
  87. /**
  88. * listen on a new event by type and handler.
  89. * if listen on, the true is returned, otherwise the false.
  90. * The handler will not be listen if it is a duplicate.
  91. *
  92. * @param {string} type event type, it must be a unique string.
  93. * @param {EventHandler} handler event handler, when if the same handler is passed, listen it by only once.
  94. * @returns {boolean}
  95. * @memberof EventEmitter
  96. * @example
  97. * const emitter = new EventEmitter();
  98. * emitter.on('change:name', evt => {
  99. * console.log(evt);
  100. * });
  101. */
  102. EventEmitter.prototype.on = function (type, handler) {
  103. if (!type || !handler)
  104. return false;
  105. if (!this.isValidType(type))
  106. return false;
  107. if (!this.isValidHandler(handler))
  108. return false;
  109. var handlers = this._eventHandlers[type];
  110. if (!handlers)
  111. handlers = this._eventHandlers[type] = [];
  112. // when the same handler is passed, listen it by only once.
  113. if (handlers.indexOf(handler) >= 0)
  114. return false;
  115. handler._once = false;
  116. handlers.push(handler);
  117. return true;
  118. };
  119. /**
  120. * listen on an once event by type and handler.
  121. * when the event is fired, that will be listen off immediately and automatically.
  122. * The handler will not be listen if it is a duplicate.
  123. *
  124. * @param {string} type event type, it must be a unique string.
  125. * @param {EventHandler} handler event handler, when if the same handler is passed, listen it by only once.
  126. * @returns {boolean}
  127. * @memberof EventEmitter
  128. * @example
  129. * const emitter = new EventEmitter();
  130. * emitter.once('change:name', evt => {
  131. * console.log(evt);
  132. * });
  133. */
  134. EventEmitter.prototype.once = function (type, handler) {
  135. if (!type || !handler)
  136. return false;
  137. if (!this.isValidType(type))
  138. return false;
  139. if (!this.isValidHandler(handler))
  140. return false;
  141. var ret = this.on(type, handler);
  142. if (ret) {
  143. // set `_once` private property after listened,
  144. // avoid to modify event handler that has been listened.
  145. handler._once = true;
  146. }
  147. return ret;
  148. };
  149. /**
  150. * listen off an event by type and handler.
  151. * or listen off events by type, when if only type argument is passed.
  152. * or listen off all events, when if no arguments are passed.
  153. *
  154. * @param {string} [type] event type
  155. * @param {EventHandler} [handler] event handler
  156. * @returns
  157. * @memberof EventEmitter
  158. * @example
  159. * const emitter = new EventEmitter();
  160. * // listen off the specified event
  161. * emitter.off('change:name', evt => {
  162. * console.log(evt);
  163. * });
  164. * // listen off events by type
  165. * emitter.off('change:name');
  166. * // listen off all events
  167. * emitter.off();
  168. */
  169. EventEmitter.prototype.off = function (type, handler) {
  170. // listen off all events, when if no arguments are passed.
  171. // it does samething as `offAll` method.
  172. if (!type)
  173. return this.offAll();
  174. // listen off events by type, when if only type argument is passed.
  175. if (!handler) {
  176. this._eventHandlers[type] = [];
  177. return;
  178. }
  179. if (!this.isValidType(type))
  180. return;
  181. if (!this.isValidHandler(handler))
  182. return;
  183. var handlers = this._eventHandlers[type];
  184. if (!handlers || !handlers.length)
  185. return;
  186. // otherwise, listen off the specified event.
  187. for (var i = 0; i < handlers.length; i++) {
  188. var fn = handlers[i];
  189. if (fn === handler) {
  190. handlers.splice(i, 1);
  191. break;
  192. }
  193. }
  194. };
  195. /**
  196. * listen off all events, that means every event will be emptied.
  197. *
  198. * @memberof EventEmitter
  199. * @example
  200. * const emitter = new EventEmitter();
  201. * emitter.offAll();
  202. */
  203. EventEmitter.prototype.offAll = function () {
  204. this._eventHandlers = {};
  205. };
  206. /**
  207. * fire the specified event, and you can to pass a data.
  208. * When fired, every handler attached to that event will be executed.
  209. * But, if it's an once event, listen off it immediately after called handler.
  210. *
  211. * @param {string} type event type
  212. * @param {*} [data] event data
  213. * @returns
  214. * @memberof EventEmitter
  215. * @example
  216. * const emitter = new EventEmitter();
  217. * emitter.fire('change:name', 'new name');
  218. */
  219. EventEmitter.prototype.fire = function (type, data) {
  220. if (!type || !this.isValidType(type))
  221. return;
  222. var handlers = this._eventHandlers[type];
  223. if (!handlers || !handlers.length)
  224. return;
  225. var event = this.createEvent(type, data);
  226. for (var _i = 0, handlers_1 = handlers; _i < handlers_1.length; _i++) {
  227. var handler = handlers_1[_i];
  228. if (!this.isValidHandler(handler))
  229. continue;
  230. if (handler._once)
  231. event.once = true;
  232. // call event handler, and pass the event argument.
  233. handler(event);
  234. // if it's an once event, listen off it immediately after called handler.
  235. if (event.once)
  236. this.off(type, handler);
  237. }
  238. };
  239. /**
  240. * check whether the specified event has been listen on.
  241. * or check whether the events by type has been listen on, when if only `type` argument is passed.
  242. *
  243. * @param {string} type event type
  244. * @param {EventHandler} [handler] event handler, optional
  245. * @returns {boolean}
  246. * @memberof EventEmitter
  247. * @example
  248. * const emitter = new EventEmitter();
  249. * const result = emitter.has('change:name');
  250. */
  251. EventEmitter.prototype.has = function (type, handler) {
  252. if (!type || !this.isValidType(type))
  253. return false;
  254. var handlers = this._eventHandlers[type];
  255. // if there are no any events, return false.
  256. if (!handlers || !handlers.length)
  257. return false;
  258. // at lest one event, and no pass `handler` argument, then return true.
  259. if (!handler || !this.isValidHandler(handler))
  260. return true;
  261. // otherwise, need to traverse the handlers.
  262. return handlers.indexOf(handler) >= 0;
  263. };
  264. /**
  265. * get the handlers for the specified event type.
  266. *
  267. * @param {string} type event type
  268. * @returns {EventHandler[]}
  269. * @memberof EventEmitter
  270. * @example
  271. * const emitter = new EventEmitter();
  272. * const handlers = emitter.getHandlers('change:name');
  273. * console.log(handlers);
  274. */
  275. EventEmitter.prototype.getHandlers = function (type) {
  276. if (!type || !this.isValidType(type))
  277. return [];
  278. return this._eventHandlers[type] || [];
  279. };
  280. /**
  281. * create event object.
  282. *
  283. * @param {string} type event type
  284. * @param {*} [data] event data
  285. * @param {boolean} [once=false] is it an once event?
  286. * @returns {Event}
  287. * @memberof EventEmitter
  288. */
  289. EventEmitter.prototype.createEvent = function (type, data, once) {
  290. if (once === void 0) { once = false; }
  291. var event = { type: type, data: data, timestamp: Date.now(), once: once };
  292. return event;
  293. };
  294. return EventEmitter;
  295. }());
  296. exports.EventEmitter = EventEmitter;
  297. /**
  298. * EventEmitter instance for global.
  299. * @type {EventEmitter}
  300. */
  301. exports.globalEvent = new EventEmitter();
  302. /***/ }),
  303. /***/ "./changelog.md":
  304. /*!**********************!*\
  305. !*** ./changelog.md ***!
  306. \**********************/
  307. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  308. __webpack_require__.r(__webpack_exports__);
  309. // Module
  310. var code = "<h1 id=\"betterytm-changelog\">BetterYTM Changelog</h1>\n<br>\n\n<h2 id=\"history\">History:</h2>\n<ul>\n<li><strong><a href=\"#100\">v1.0.0</a></strong></li>\n<li><a href=\"#020\">v0.2.0</a></li>\n<li><a href=\"#010\">v0.1.0</a></li>\n</ul>\n<hr>\n<p><br><br></p>\n<h2 id=\"100\">1.0.0</h2>\n<ul>\n<li>Added menu to configure features</li>\n<li>New configurable features:<ul>\n<li>Make volume slider bigger</li>\n<li>Choose step of volume slider for finer control</li>\n<li>TODO: Add lyrics button to each song in a playlist</li>\n</ul>\n</li>\n<li>Changes / Fixes:<ul>\n<li>Now the lyrics button will directly link to the lyrics (using my API <a href=\"https://github.com/Sv443/geniURL\">geniURL</a>)</li>\n<li>TODO: Site switch with <kbd>F9</kbd> will now keep the video time</li>\n</ul>\n</li>\n</ul>\n<br>\n\n<h2 id=\"020\">0.2.0</h2>\n<ul>\n<li>Added Features:<ul>\n<li>Switch between YouTube and YT Music (with <kbd>F9</kbd> by default)</li>\n<li>Search for song lyrics with new button in media controls</li>\n<li>Remove &quot;Upgrade to YTM Premium&quot; tab</li>\n</ul>\n</li>\n</ul>\n<br>\n\n<h2 id=\"010\">0.1.0</h2>\n<ul>\n<li>Added support for arrow keys to skip forward or backward (currently only by fixed 10 second interval)</li>\n</ul>\n<p><br><br><br><br><br><br><br><br><br></p>\n";
  311. // Exports
  312. /* harmony default export */ __webpack_exports__["default"] = (code);
  313. /***/ }),
  314. /***/ "./src/features/menu/menu.html":
  315. /*!*************************************!*\
  316. !*** ./src/features/menu/menu.html ***!
  317. \*************************************/
  318. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  319. __webpack_require__.r(__webpack_exports__);
  320. // Module
  321. var code = "<dialog id=\"bytm-menu-dialog\">\n <div id=\"bytm-menu-header-container\">\n <div class=\"bytm-menu-header-option\" id=\"bytm-menu-tab-options-header\" data-active=\"true\">\n <h3>Options</h3>\n </div>\n <div class=\"bytm-menu-header-option\" id=\"bytm-menu-tab-info-header\" data-active=\"false\">\n <h3>Info</h3>\n </div>\n <div class=\"bytm-menu-header-option\" id=\"bytm-menu-tab-changelog-header\" data-active=\"false\">\n <h3>Changelog</h3>\n </div>\n </div>\n <div id=\"bytm-menu-body\">\n <div class=\"bytm-menu-tab-content\" id=\"bytm-menu-tab-options-content\" data-active=\"true\"></div>\n <div class=\"bytm-menu-tab-content\" id=\"bytm-menu-tab-info-content\" data-active=\"false\">\n ayo info\n </div>\n <div class=\"bytm-menu-tab-content\" id=\"bytm-menu-tab-changelog-content\" data-active=\"false\"></div>\n </div>\n</dialog>\n";
  322. // Exports
  323. /* harmony default export */ __webpack_exports__["default"] = (code);
  324. /***/ }),
  325. /***/ "./src/features/layout.css":
  326. /*!*********************************!*\
  327. !*** ./src/features/layout.css ***!
  328. \*********************************/
  329. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  330. __webpack_require__.r(__webpack_exports__);
  331. // extracted by mini-css-extract-plugin
  332. /***/ }),
  333. /***/ "./src/features/lyrics.css":
  334. /*!*********************************!*\
  335. !*** ./src/features/lyrics.css ***!
  336. \*********************************/
  337. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  338. __webpack_require__.r(__webpack_exports__);
  339. // extracted by mini-css-extract-plugin
  340. /***/ }),
  341. /***/ "./src/features/menu/menu.css":
  342. /*!************************************!*\
  343. !*** ./src/features/menu/menu.css ***!
  344. \************************************/
  345. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  346. __webpack_require__.r(__webpack_exports__);
  347. // extracted by mini-css-extract-plugin
  348. /***/ }),
  349. /***/ "./src/config.ts":
  350. /*!***********************!*\
  351. !*** ./src/config.ts ***!
  352. \***********************/
  353. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  354. __webpack_require__.r(__webpack_exports__);
  355. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  356. /* harmony export */ defaultFeatures: function() { return /* binding */ defaultFeatures; },
  357. /* harmony export */ getFeatures: function() { return /* binding */ getFeatures; },
  358. /* harmony export */ loadFeatureConf: function() { return /* binding */ loadFeatureConf; },
  359. /* harmony export */ saveFeatureConf: function() { return /* binding */ saveFeatureConf; },
  360. /* harmony export */ setDefaultFeatConf: function() { return /* binding */ setDefaultFeatConf; }
  361. /* harmony export */ });
  362. /* harmony import */ var _features_index__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./features/index */ "./src/features/index.ts");
  363. /* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./utils */ "./src/utils.ts");
  364. var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
  365. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  366. return new (P || (P = Promise))(function (resolve, reject) {
  367. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  368. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  369. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  370. step((generator = generator.apply(thisArg, _arguments || [])).next());
  371. });
  372. };
  373. const defaultFeatures = Object.keys(_features_index__WEBPACK_IMPORTED_MODULE_0__.featInfo).reduce((acc, key) => {
  374. acc[key] = _features_index__WEBPACK_IMPORTED_MODULE_0__.featInfo[key].default;
  375. return acc;
  376. }, {});
  377. let featuresCache;
  378. /**
  379. * Returns the current FeatureConfig in memory or reads it from GM storage
  380. * Automatically applies defaults for non-existant keys
  381. * @param forceRead Set to true to force reading the config from GM storage
  382. */
  383. function getFeatures(forceRead = false) {
  384. return __awaiter(this, void 0, void 0, function* () {
  385. if (featuresCache === undefined || forceRead)
  386. yield saveFeatureConf(featuresCache = Object.assign(Object.assign({}, defaultFeatures), yield loadFeatureConf())); // look at this sexy one liner
  387. return featuresCache;
  388. });
  389. }
  390. /** Loads a feature configuration saved persistently, returns an empty object if no feature configuration was saved */
  391. function loadFeatureConf() {
  392. return __awaiter(this, void 0, void 0, function* () {
  393. const defConf = Object.freeze(Object.assign({}, defaultFeatures));
  394. try {
  395. const featureConf = yield GM.getValue("betterytm-config");
  396. if (typeof featureConf !== "string") {
  397. yield setDefaultFeatConf();
  398. return featuresCache = defConf;
  399. }
  400. return featuresCache = Object.freeze(featureConf ? JSON.parse(featureConf) : defConf);
  401. }
  402. catch (err) {
  403. yield setDefaultFeatConf();
  404. return featuresCache = defConf;
  405. }
  406. });
  407. }
  408. /**
  409. * Saves a feature configuration saved persistently
  410. * @param featureConf
  411. */
  412. function saveFeatureConf(featureConf) {
  413. if (!featureConf || typeof featureConf != "object")
  414. throw new TypeError("Feature config not provided or invalid");
  415. (0,_utils__WEBPACK_IMPORTED_MODULE_1__.log)("Saving new feature config:", featureConf);
  416. featuresCache = Object.assign({}, featureConf);
  417. return GM.setValue("betterytm-config", JSON.stringify(featureConf));
  418. }
  419. /** Resets the featuresCache synchronously and the persistent features storage asynchronously to its default values */
  420. function setDefaultFeatConf() {
  421. featuresCache = Object.assign({}, defaultFeatures);
  422. return GM.setValue("betterytm-config", JSON.stringify(defaultFeatures));
  423. }
  424. /***/ }),
  425. /***/ "./src/constants.ts":
  426. /*!**************************!*\
  427. !*** ./src/constants.ts ***!
  428. \**************************/
  429. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  430. __webpack_require__.r(__webpack_exports__);
  431. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  432. /* harmony export */ branch: function() { return /* binding */ branch; },
  433. /* harmony export */ logLevel: function() { return /* binding */ logLevel; },
  434. /* harmony export */ scriptInfo: function() { return /* binding */ scriptInfo; },
  435. /* harmony export */ triesInterval: function() { return /* binding */ triesInterval; },
  436. /* harmony export */ triesLimit: function() { return /* binding */ triesLimit; }
  437. /* harmony export */ });
  438. /** The branch to use in the @icon, @downloadURL and @updateURL directives */
  439. const branch = "develop";
  440. // export const branch = "main";
  441. /**
  442. * How much info should be logged to the devtools console?
  443. * 0 = Debug (show everything) or 1 = Info (show only important stuff)
  444. */
  445. const logLevel = 0;
  446. /** Specifies the hard limit for repetitive tasks */
  447. const triesLimit = 25;
  448. /** Specifies the interval for repetitive tasks */
  449. const triesInterval = 200;
  450. /** Info about the userscript, parsed from the userscript header (tools/post-build.js) */
  451. const scriptInfo = Object.freeze({
  452. name: GM.info.script.name,
  453. version: GM.info.script.version,
  454. namespace: GM.info.script.namespace,
  455. lastCommit: "4d46e00", // assert as generic string instead of union
  456. });
  457. /***/ }),
  458. /***/ "./src/features/index.ts":
  459. /*!*******************************!*\
  460. !*** ./src/features/index.ts ***!
  461. \*******************************/
  462. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  463. __webpack_require__.r(__webpack_exports__);
  464. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  465. /* harmony export */ addAnchorImprovements: function() { return /* reexport safe */ _layout__WEBPACK_IMPORTED_MODULE_2__.addAnchorImprovements; },
  466. /* harmony export */ addMediaCtrlGeniusBtn: function() { return /* reexport safe */ _lyrics__WEBPACK_IMPORTED_MODULE_3__.addMediaCtrlGeniusBtn; },
  467. /* harmony export */ addMenu: function() { return /* reexport safe */ _menu_menu_old__WEBPACK_IMPORTED_MODULE_5__.addMenu; },
  468. /* harmony export */ addWatermark: function() { return /* reexport safe */ _layout__WEBPACK_IMPORTED_MODULE_2__.addWatermark; },
  469. /* harmony export */ closeMenu: function() { return /* reexport safe */ _menu_menu_old__WEBPACK_IMPORTED_MODULE_5__.closeMenu; },
  470. /* harmony export */ disableBeforeUnload: function() { return /* reexport safe */ _input__WEBPACK_IMPORTED_MODULE_1__.disableBeforeUnload; },
  471. /* harmony export */ enableBeforeUnload: function() { return /* reexport safe */ _input__WEBPACK_IMPORTED_MODULE_1__.enableBeforeUnload; },
  472. /* harmony export */ featInfo: function() { return /* binding */ featInfo; },
  473. /* harmony export */ geniUrlBase: function() { return /* reexport safe */ _lyrics__WEBPACK_IMPORTED_MODULE_3__.geniUrlBase; },
  474. /* harmony export */ getCurrentGeniusUrl: function() { return /* reexport safe */ _lyrics__WEBPACK_IMPORTED_MODULE_3__.getCurrentGeniusUrl; },
  475. /* harmony export */ initArrowKeySkip: function() { return /* reexport safe */ _input__WEBPACK_IMPORTED_MODULE_1__.initArrowKeySkip; },
  476. /* harmony export */ initBeforeUnloadHook: function() { return /* reexport safe */ _input__WEBPACK_IMPORTED_MODULE_1__.initBeforeUnloadHook; },
  477. /* harmony export */ initMenu: function() { return /* reexport safe */ _menu_menu__WEBPACK_IMPORTED_MODULE_4__.initMenu; },
  478. /* harmony export */ initQueueButtons: function() { return /* reexport safe */ _layout__WEBPACK_IMPORTED_MODULE_2__.initQueueButtons; },
  479. /* harmony export */ initSiteSwitch: function() { return /* reexport safe */ _input__WEBPACK_IMPORTED_MODULE_1__.initSiteSwitch; },
  480. /* harmony export */ openMenu: function() { return /* reexport safe */ _menu_menu_old__WEBPACK_IMPORTED_MODULE_5__.openMenu; },
  481. /* harmony export */ preInitLayout: function() { return /* reexport safe */ _layout__WEBPACK_IMPORTED_MODULE_2__.preInitLayout; },
  482. /* harmony export */ removeUpgradeTab: function() { return /* reexport safe */ _layout__WEBPACK_IMPORTED_MODULE_2__.removeUpgradeTab; },
  483. /* harmony export */ setVolSliderSize: function() { return /* reexport safe */ _layout__WEBPACK_IMPORTED_MODULE_2__.setVolSliderSize; },
  484. /* harmony export */ setVolSliderStep: function() { return /* reexport safe */ _layout__WEBPACK_IMPORTED_MODULE_2__.setVolSliderStep; }
  485. /* harmony export */ });
  486. /* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../constants */ "./src/constants.ts");
  487. /* harmony import */ var _input__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./input */ "./src/features/input.ts");
  488. /* harmony import */ var _layout__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./layout */ "./src/features/layout.ts");
  489. /* harmony import */ var _lyrics__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./lyrics */ "./src/features/lyrics.ts");
  490. /* harmony import */ var _menu_menu__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./menu/menu */ "./src/features/menu/menu.ts");
  491. /* harmony import */ var _menu_menu_old__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./menu/menu_old */ "./src/features/menu/menu_old.ts");
  492. // TODO
  493. /** Contains all possible features with their default values and other config */
  494. const featInfo = {
  495. //#SECTION input
  496. arrowKeySupport: {
  497. desc: "Arrow keys skip forwards and backwards by 10 seconds",
  498. type: "toggle",
  499. category: "input",
  500. default: true,
  501. },
  502. switchBetweenSites: {
  503. desc: "Add F9 as a hotkey to switch between the YT and YTM sites on a video / song",
  504. type: "toggle",
  505. category: "input",
  506. default: true,
  507. },
  508. switchSitesHotkey: {
  509. desc: "TODO: Which hotkey needs to be pressed to switch sites?",
  510. type: "hotkey",
  511. category: "input",
  512. default: {
  513. key: "F9",
  514. shift: false,
  515. ctrl: false,
  516. meta: false,
  517. },
  518. visible: false,
  519. },
  520. disableBeforeUnloadPopup: {
  521. desc: "Completely disable the popup that sometimes appears before leaving the site",
  522. type: "toggle",
  523. category: "input",
  524. default: false,
  525. },
  526. anchorImprovements: {
  527. desc: "TODO: Make it so middle clicking a song to open it in a new tab is easier",
  528. type: "toggle",
  529. category: "input",
  530. default: true,
  531. visible: false,
  532. },
  533. //#SECTION layout
  534. removeUpgradeTab: {
  535. desc: "Remove the \"Upgrade\" / YT Music Premium tab",
  536. type: "toggle",
  537. category: "layout",
  538. default: true,
  539. },
  540. volumeSliderSize: {
  541. desc: "The width of the volume slider in pixels",
  542. type: "number",
  543. category: "layout",
  544. min: 10,
  545. max: 1000,
  546. step: 5,
  547. default: 160,
  548. unit: "px",
  549. },
  550. volumeSliderStep: {
  551. desc: "Volume slider sensitivity - the smaller this number, the finer the volume control",
  552. type: "slider",
  553. category: "layout",
  554. min: 1,
  555. max: 20,
  556. default: 2,
  557. },
  558. watermarkEnabled: {
  559. desc: `Show a ${_constants__WEBPACK_IMPORTED_MODULE_0__.scriptInfo.name} watermark under the YTM logo`,
  560. type: "toggle",
  561. category: "layout",
  562. default: true,
  563. },
  564. queueButtons: {
  565. desc: "TODO: Add buttons while hovering over a song in a queue to quickly remove it or open its lyrics",
  566. type: "toggle",
  567. category: "layout",
  568. default: true,
  569. visible: false,
  570. },
  571. //#SECTION lyrics
  572. geniusLyrics: {
  573. desc: "Add a button to the media controls to open the current song's lyrics on genius.com in a new tab",
  574. type: "toggle",
  575. category: "lyrics",
  576. default: true,
  577. },
  578. };
  579. /***/ }),
  580. /***/ "./src/features/input.ts":
  581. /*!*******************************!*\
  582. !*** ./src/features/input.ts ***!
  583. \*******************************/
  584. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  585. __webpack_require__.r(__webpack_exports__);
  586. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  587. /* harmony export */ disableBeforeUnload: function() { return /* binding */ disableBeforeUnload; },
  588. /* harmony export */ enableBeforeUnload: function() { return /* binding */ enableBeforeUnload; },
  589. /* harmony export */ initArrowKeySkip: function() { return /* binding */ initArrowKeySkip; },
  590. /* harmony export */ initBeforeUnloadHook: function() { return /* binding */ initBeforeUnloadHook; },
  591. /* harmony export */ initSiteSwitch: function() { return /* binding */ initSiteSwitch; }
  592. /* harmony export */ });
  593. /* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../utils */ "./src/utils.ts");
  594. /* harmony import */ var _config__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../config */ "./src/config.ts");
  595. //#MARKER arrow key skip
  596. function initArrowKeySkip() {
  597. document.addEventListener("keydown", onKeyDown);
  598. (0,_utils__WEBPACK_IMPORTED_MODULE_0__.log)("Added key press listener");
  599. }
  600. /** Called when the user presses any key, anywhere */
  601. function onKeyDown(evt) {
  602. var _a, _b;
  603. if (["ArrowLeft", "ArrowRight"].includes(evt.code)) {
  604. // discard the event when a (text) input is currently active, like when editing a playlist
  605. if (["INPUT", "TEXTAREA", "SELECT"].includes((_b = (_a = document.activeElement) === null || _a === void 0 ? void 0 : _a.tagName) !== null && _b !== void 0 ? _b : "_"))
  606. return (0,_utils__WEBPACK_IMPORTED_MODULE_0__.info)(`Captured valid key but the current active element is <${document.activeElement.tagName.toLowerCase()}>, so the keypress is ignored`);
  607. (0,_utils__WEBPACK_IMPORTED_MODULE_0__.log)(`Captured key '${evt.code}' in proxy listener`);
  608. // ripped this stuff from the console, most of these are probably unnecessary but this was finnicky af and I am sick and tired of trial and error
  609. const defaultProps = {
  610. altKey: false,
  611. ctrlKey: false,
  612. metaKey: false,
  613. shiftKey: false,
  614. target: document.body,
  615. currentTarget: document.body,
  616. originalTarget: document.body,
  617. explicitOriginalTarget: document.body,
  618. srcElement: document.body,
  619. type: "keydown",
  620. bubbles: true,
  621. cancelBubble: false,
  622. cancelable: true,
  623. isTrusted: true,
  624. repeat: false,
  625. view: unsafeWindow !== null && unsafeWindow !== void 0 ? unsafeWindow : window,
  626. };
  627. let invalidKey = false;
  628. let keyProps = {};
  629. switch (evt.code) {
  630. case "ArrowLeft":
  631. keyProps = {
  632. code: "KeyH",
  633. key: "h",
  634. keyCode: 72,
  635. which: 72,
  636. };
  637. break;
  638. case "ArrowRight":
  639. keyProps = {
  640. code: "KeyL",
  641. key: "l",
  642. keyCode: 76,
  643. which: 76,
  644. };
  645. break;
  646. default:
  647. invalidKey = true;
  648. break;
  649. }
  650. if (!invalidKey) {
  651. // TODO: check if the code prop is correct
  652. const proxyProps = Object.assign(Object.assign({ code: "" }, defaultProps), keyProps);
  653. document.body.dispatchEvent(new KeyboardEvent("keydown", proxyProps));
  654. (0,_utils__WEBPACK_IMPORTED_MODULE_0__.log)(`Dispatched proxy keydown event: [${evt.code}] -> [${proxyProps.code}]`);
  655. }
  656. else
  657. (0,_utils__WEBPACK_IMPORTED_MODULE_0__.warn)(`Captured key '${evt.code}' has no defined behavior`);
  658. }
  659. }
  660. //#MARKER site switch
  661. /** Initializes the site switch feature */
  662. function initSiteSwitch(domain) {
  663. // TODO:
  664. // extra features:
  665. // - keep video time
  666. // - configurable hotkey
  667. document.addEventListener("keydown", (e) => {
  668. if (e.key === "F9")
  669. switchSite(domain === "yt" ? "ytm" : "yt");
  670. });
  671. (0,_utils__WEBPACK_IMPORTED_MODULE_0__.log)("Initialized site switch listener");
  672. }
  673. /** Switches to the other site (between YT and YTM) */
  674. function switchSite(newDomain) {
  675. var _a;
  676. try {
  677. let subdomain;
  678. if (newDomain === "ytm")
  679. subdomain = "music";
  680. else if (newDomain === "yt")
  681. subdomain = "www";
  682. if (!subdomain)
  683. throw new TypeError(`Unrecognized domain '${newDomain}'`);
  684. const { pathname, search, hash } = new URL(location.href);
  685. const vt = (_a = (0,_utils__WEBPACK_IMPORTED_MODULE_0__.getVideoTime)()) !== null && _a !== void 0 ? _a : 0;
  686. (0,_utils__WEBPACK_IMPORTED_MODULE_0__.log)(`Found video time of ${vt} seconds`);
  687. const newSearch = search.includes("?") ? `${search}&t=${vt}` : `?t=${vt}`;
  688. const url = `https://${subdomain}.youtube.com${pathname}${newSearch}${hash}`;
  689. console.info(`BetterYTM - switching to domain '${newDomain}' at ${url}`);
  690. disableBeforeUnload();
  691. location.assign(url);
  692. }
  693. catch (err) {
  694. (0,_utils__WEBPACK_IMPORTED_MODULE_0__.error)("Error while switching site:", err);
  695. }
  696. }
  697. //#MARKER beforeunload popup
  698. let beforeUnloadEnabled = true;
  699. /** Disables the popup before leaving the site */
  700. function disableBeforeUnload() {
  701. beforeUnloadEnabled = false;
  702. (0,_utils__WEBPACK_IMPORTED_MODULE_0__.info)("Disabled popup before leaving the site");
  703. }
  704. /** (Re-)enables the popup before leaving the site */
  705. function enableBeforeUnload() {
  706. beforeUnloadEnabled = true;
  707. (0,_utils__WEBPACK_IMPORTED_MODULE_0__.info)("Enabled popup before leaving the site");
  708. }
  709. /** Adds a spy function into `window.__proto__.addEventListener` to selectively discard events before they can be captured by the original site's listeners */
  710. function initBeforeUnloadHook() {
  711. Error.stackTraceLimit = Infinity;
  712. (function (original) {
  713. // @ts-ignore
  714. window.__proto__.addEventListener = function (...args) {
  715. const [type, listener, ...rest] = args;
  716. if (type === "beforeunload") {
  717. return original.apply(this, [
  718. type,
  719. // @ts-ignore
  720. (...a) => {
  721. if (beforeUnloadEnabled)
  722. listener(...a);
  723. },
  724. ...rest,
  725. ]);
  726. }
  727. else
  728. return original.apply(this, args);
  729. };
  730. // @ts-ignore
  731. })(window.__proto__.addEventListener);
  732. (0,_config__WEBPACK_IMPORTED_MODULE_1__.getFeatures)().then(feats => {
  733. if (feats.disableBeforeUnloadPopup)
  734. disableBeforeUnload();
  735. });
  736. // (function(original) {
  737. // window.__proto__.removeEventListener = function(type, listener, useCapture) {
  738. // if(evtNames.includes(type)){
  739. // console.log("------> removeEventListener " + type, listener, useCapture);
  740. // }
  741. // return original.apply(this, arguments);
  742. // };
  743. // })(window.__proto__.removeEventListener);
  744. }
  745. /***/ }),
  746. /***/ "./src/features/layout.ts":
  747. /*!********************************!*\
  748. !*** ./src/features/layout.ts ***!
  749. \********************************/
  750. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  751. __webpack_require__.r(__webpack_exports__);
  752. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  753. /* harmony export */ addAnchorImprovements: function() { return /* binding */ addAnchorImprovements; },
  754. /* harmony export */ addWatermark: function() { return /* binding */ addWatermark; },
  755. /* harmony export */ initQueueButtons: function() { return /* binding */ initQueueButtons; },
  756. /* harmony export */ preInitLayout: function() { return /* binding */ preInitLayout; },
  757. /* harmony export */ removeUpgradeTab: function() { return /* binding */ removeUpgradeTab; },
  758. /* harmony export */ setVolSliderSize: function() { return /* binding */ setVolSliderSize; },
  759. /* harmony export */ setVolSliderStep: function() { return /* binding */ setVolSliderStep; }
  760. /* harmony export */ });
  761. /* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../constants */ "./src/constants.ts");
  762. /* harmony import */ var _config__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../config */ "./src/config.ts");
  763. /* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../utils */ "./src/utils.ts");
  764. /* harmony import */ var _menu_menu_old__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./menu/menu_old */ "./src/features/menu/menu_old.ts");
  765. /* harmony import */ var _layout_css__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./layout.css */ "./src/features/layout.css");
  766. var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
  767. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  768. return new (P || (P = Promise))(function (resolve, reject) {
  769. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  770. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  771. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  772. step((generator = generator.apply(thisArg, _arguments || [])).next());
  773. });
  774. };
  775. let features;
  776. function preInitLayout() {
  777. return __awaiter(this, void 0, void 0, function* () {
  778. features = yield (0,_config__WEBPACK_IMPORTED_MODULE_1__.getFeatures)();
  779. });
  780. }
  781. //#MARKER watermark
  782. /** Adds a watermark beneath the logo */
  783. function addWatermark() {
  784. const watermark = document.createElement("a");
  785. watermark.role = "button";
  786. watermark.id = "betterytm-watermark";
  787. watermark.className = "style-scope ytmusic-nav-bar";
  788. watermark.innerText = _constants__WEBPACK_IMPORTED_MODULE_0__.scriptInfo.name;
  789. watermark.title = "Open menu";
  790. watermark.tabIndex = 1000;
  791. watermark.addEventListener("click", () => (0,_menu_menu_old__WEBPACK_IMPORTED_MODULE_3__.openMenu)());
  792. watermark.addEventListener("keydown", (e) => e.key === "Enter" && (0,_menu_menu_old__WEBPACK_IMPORTED_MODULE_3__.openMenu)());
  793. const logoElem = document.querySelector("#left-content");
  794. (0,_utils__WEBPACK_IMPORTED_MODULE_2__.insertAfter)(logoElem, watermark);
  795. (0,_utils__WEBPACK_IMPORTED_MODULE_2__.log)("Added watermark element:", watermark);
  796. }
  797. //#MARKER remove upgrade tab
  798. let removeUpgradeTries = 0;
  799. /** Removes the "Upgrade" / YT Music Premium tab from the title / nav bar */
  800. function removeUpgradeTab() {
  801. const tabElem = document.querySelector(".ytmusic-nav-bar ytmusic-pivot-bar-item-renderer[tab-id=\"SPunlimited\"]");
  802. if (tabElem) {
  803. tabElem.remove();
  804. (0,_utils__WEBPACK_IMPORTED_MODULE_2__.log)(`Removed upgrade tab after ${removeUpgradeTries} tries`);
  805. }
  806. else if (removeUpgradeTries < _constants__WEBPACK_IMPORTED_MODULE_0__.triesLimit) {
  807. setTimeout(removeUpgradeTab, _constants__WEBPACK_IMPORTED_MODULE_0__.triesInterval); // TODO: improve this
  808. removeUpgradeTries++;
  809. }
  810. else
  811. (0,_utils__WEBPACK_IMPORTED_MODULE_2__.error)(`Couldn't find upgrade tab to remove after ${removeUpgradeTries} tries`);
  812. }
  813. //#MARKER volume slider
  814. /** Sets the volume slider to a set size */
  815. function setVolSliderSize() {
  816. const { volumeSliderSize: size } = features;
  817. if (typeof size !== "number" || isNaN(Number(size)))
  818. return;
  819. const style = `\
  820. .volume-slider.ytmusic-player-bar, .expand-volume-slider.ytmusic-player-bar {
  821. width: ${size}px !important;
  822. }`;
  823. (0,_utils__WEBPACK_IMPORTED_MODULE_2__.addGlobalStyle)(style, "vol-slider");
  824. }
  825. /** Sets the `step` attribute of the volume slider */
  826. function setVolSliderStep() {
  827. const sliderElem = document.querySelector("tp-yt-paper-slider#volume-slider");
  828. sliderElem.setAttribute("step", String(features.volumeSliderStep));
  829. }
  830. //#MARKER queue buttons
  831. // TODO: account for the fact initially the elements might not exist, if the site was not opened directly with a video playing or via the /watch path
  832. function initQueueButtons() {
  833. _utils__WEBPACK_IMPORTED_MODULE_2__.siteEvents.on("queueChanged", (evt) => {
  834. for (const queueItm of evt.data.childNodes) {
  835. if (!queueItm.classList.contains("bytm-has-queue-btns"))
  836. addQueueButtons(queueItm);
  837. }
  838. });
  839. const queueItems = document.querySelectorAll("#contents.ytmusic-player-queue > ytmusic-player-queue-item");
  840. if (queueItems.length === 0)
  841. return;
  842. queueItems.forEach(itm => addQueueButtons(itm));
  843. }
  844. function addQueueButtons(queueItem) {
  845. const queueBtnsCont = document.createElement("div");
  846. queueBtnsCont.className = "bytm-queue-btn-container";
  847. queueBtnsCont.innerText = "ayo";
  848. const songInfo = queueItem.querySelector(".song-info");
  849. if (!songInfo)
  850. return false;
  851. songInfo.appendChild(queueBtnsCont);
  852. queueItem.classList.add("bytm-has-queue-btns");
  853. return true;
  854. }
  855. //#MARKER better clickable stuff
  856. // TODO: account for the fact initially the elements might not exist, if the site was opened directly with the /watch path
  857. function addAnchorImprovements() {
  858. void 0;
  859. }
  860. /***/ }),
  861. /***/ "./src/features/lyrics.ts":
  862. /*!********************************!*\
  863. !*** ./src/features/lyrics.ts ***!
  864. \********************************/
  865. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  866. __webpack_require__.r(__webpack_exports__);
  867. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  868. /* harmony export */ addMediaCtrlGeniusBtn: function() { return /* binding */ addMediaCtrlGeniusBtn; },
  869. /* harmony export */ geniUrlBase: function() { return /* binding */ geniUrlBase; },
  870. /* harmony export */ getCurrentGeniusUrl: function() { return /* binding */ getCurrentGeniusUrl; }
  871. /* harmony export */ });
  872. /* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../constants */ "./src/constants.ts");
  873. /* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../utils */ "./src/utils.ts");
  874. /* harmony import */ var _lyrics_css__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./lyrics.css */ "./src/features/lyrics.css");
  875. var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
  876. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  877. return new (P || (P = Promise))(function (resolve, reject) {
  878. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  879. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  880. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  881. step((generator = generator.apply(thisArg, _arguments || [])).next());
  882. });
  883. };
  884. var __asyncValues = (undefined && undefined.__asyncValues) || function (o) {
  885. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  886. var m = o[Symbol.asyncIterator], i;
  887. return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
  888. function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
  889. function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
  890. };
  891. /** Base URL of geniURL */
  892. const geniUrlBase = "https://api.sv443.net/geniurl";
  893. /** GeniURL endpoint that gives song metadata when provided with a `?q` or `?artist` and `?song` parameter - [more info](https://api.sv443.net/geniurl) */
  894. const geniURLSearchTopUrl = `${geniUrlBase}/search/top`;
  895. let mcCurrentSongTitle = "";
  896. let mcLyricsButtonAddTries = 0;
  897. /** Adds a genius.com lyrics button to the media controls bar */
  898. function addMediaCtrlGeniusBtn() {
  899. return __awaiter(this, void 0, void 0, function* () {
  900. const likeContainer = document.querySelector(".middle-controls-buttons ytmusic-like-button-renderer#like-button-renderer");
  901. if (!likeContainer) {
  902. mcLyricsButtonAddTries++;
  903. if (mcLyricsButtonAddTries < _constants__WEBPACK_IMPORTED_MODULE_0__.triesLimit)
  904. return setTimeout(addMediaCtrlGeniusBtn, _constants__WEBPACK_IMPORTED_MODULE_0__.triesInterval); // TODO: improve this
  905. return (0,_utils__WEBPACK_IMPORTED_MODULE_1__.error)(`Couldn't find element to append lyrics buttons to after ${mcLyricsButtonAddTries} tries`);
  906. }
  907. const songTitleElem = document.querySelector(".content-info-wrapper > yt-formatted-string");
  908. const gUrl = yield getCurrentGeniusUrl();
  909. const linkElem = document.createElement("a");
  910. linkElem.id = "betterytm-lyrics-button";
  911. linkElem.className = "ytmusic-player-bar";
  912. linkElem.title = gUrl ? "Click to open this song's lyrics in a new tab" : "Loading...";
  913. if (gUrl)
  914. linkElem.href = gUrl;
  915. linkElem.target = "_blank";
  916. linkElem.rel = "noopener noreferrer";
  917. linkElem.style.visibility = gUrl ? "initial" : "hidden";
  918. linkElem.style.display = gUrl ? "inline-flex" : "none";
  919. const imgElem = document.createElement("img");
  920. imgElem.id = "betterytm-lyrics-img";
  921. imgElem.src = "https://raw.githubusercontent.com/Sv443/BetterYTM/main/assets/external/genius.png";
  922. linkElem.appendChild(imgElem);
  923. (0,_utils__WEBPACK_IMPORTED_MODULE_1__.log)(`Inserted genius button after ${mcLyricsButtonAddTries} tries:`, linkElem);
  924. (0,_utils__WEBPACK_IMPORTED_MODULE_1__.insertAfter)(likeContainer, linkElem);
  925. mcCurrentSongTitle = songTitleElem.title;
  926. const onMutation = (mutations) => { var _a, mutations_1, mutations_1_1; return __awaiter(this, void 0, void 0, function* () {
  927. var _b, e_1, _c, _d;
  928. try {
  929. for (_a = true, mutations_1 = __asyncValues(mutations); mutations_1_1 = yield mutations_1.next(), _b = mutations_1_1.done, !_b;) {
  930. _d = mutations_1_1.value;
  931. _a = false;
  932. try {
  933. const mut = _d;
  934. const newTitle = mut.target.title;
  935. if (newTitle != mcCurrentSongTitle && newTitle.length > 0) {
  936. const lyricsBtn = document.querySelector("#betterytm-lyrics-button");
  937. if (!lyricsBtn)
  938. return;
  939. (0,_utils__WEBPACK_IMPORTED_MODULE_1__.log)(`Song title changed from '${mcCurrentSongTitle}' to '${newTitle}'`);
  940. lyricsBtn.style.cursor = "wait";
  941. lyricsBtn.style.pointerEvents = "none";
  942. mcCurrentSongTitle = newTitle;
  943. const url = yield getCurrentGeniusUrl(); // can take a second or two
  944. if (!url)
  945. continue;
  946. lyricsBtn.href = url;
  947. lyricsBtn.title = "Click to open this song's lyrics in a new tab";
  948. lyricsBtn.style.cursor = "pointer";
  949. lyricsBtn.style.visibility = "initial";
  950. lyricsBtn.style.display = "inline-flex";
  951. lyricsBtn.style.pointerEvents = "initial";
  952. }
  953. }
  954. finally {
  955. _a = true;
  956. }
  957. }
  958. }
  959. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  960. finally {
  961. try {
  962. if (!_a && !_b && (_c = mutations_1.return)) yield _c.call(mutations_1);
  963. }
  964. finally { if (e_1) throw e_1.error; }
  965. }
  966. }); };
  967. // since YT and YTM don't reload the page on video change, MutationObserver needs to be used to watch for changes in the video title
  968. const obs = new MutationObserver(onMutation);
  969. obs.observe(songTitleElem, { attributes: true, attributeFilter: ["title"] });
  970. });
  971. }
  972. /** Returns the genius.com lyrics site URL for the current song */
  973. function getCurrentGeniusUrl() {
  974. var _a, _b;
  975. return __awaiter(this, void 0, void 0, function* () {
  976. try {
  977. // In videos the video title contains both artist and song title, in "regular" YTM songs, the video title only contains the song title
  978. const isVideo = typeof ((_a = document.querySelector("ytmusic-player")) === null || _a === void 0 ? void 0 : _a.getAttribute("video-mode_")) === "string";
  979. const songTitleElem = document.querySelector(".content-info-wrapper > yt-formatted-string");
  980. const songMetaElem = document.querySelector("span.subtitle > yt-formatted-string:first-child");
  981. if (!songTitleElem || !songMetaElem || !songTitleElem.title)
  982. return null;
  983. const sanitizeSongName = (songName) => {
  984. const parensRegex = /\(.+\)/gmi;
  985. const squareParensRegex = /\[.+\]/gmi;
  986. // trim right after the song name:
  987. const sanitized = songName
  988. .replace(parensRegex, "")
  989. .replace(squareParensRegex, "");
  990. return sanitized.trim();
  991. };
  992. const splitArtist = (songMeta) => {
  993. songMeta = songMeta.split(/\s*\u2022\s*/gmiu)[0]; // split at bullet (&bull; / •) character
  994. if (songMeta.match(/&/))
  995. songMeta = songMeta.split(/\s*&\s*/gm)[0];
  996. if (songMeta.match(/,/))
  997. songMeta = songMeta.split(/,\s*/gm)[0];
  998. return songMeta.trim();
  999. };
  1000. const songNameRaw = songTitleElem.title;
  1001. const songName = sanitizeSongName(songNameRaw);
  1002. const artistName = splitArtist(songMetaElem.title);
  1003. /** Use when the current song is not a "real YTM song" with a static background, but rather a music video */
  1004. const getGeniusUrlVideo = () => __awaiter(this, void 0, void 0, function* () {
  1005. if (!songName.includes("-")) // for some fucking reason some music videos have YTM-like song title and artist separation, some don't
  1006. return yield getGeniusUrl(artistName, songName);
  1007. const [artist, ...rest] = songName.split("-").map(v => v.trim());
  1008. return yield getGeniusUrl(artist, rest.join(" "));
  1009. });
  1010. // TODO: artist might need further splitting before comma or ampersand
  1011. const url = isVideo ? yield getGeniusUrlVideo() : ((_b = yield getGeniusUrl(artistName, songName)) !== null && _b !== void 0 ? _b : yield getGeniusUrlVideo());
  1012. return url;
  1013. }
  1014. catch (err) {
  1015. (0,_utils__WEBPACK_IMPORTED_MODULE_1__.error)("Couldn't resolve genius.com URL:", err);
  1016. return null;
  1017. }
  1018. });
  1019. }
  1020. /**
  1021. * @param artist
  1022. * @param song
  1023. */
  1024. function getGeniusUrl(artist, song) {
  1025. return __awaiter(this, void 0, void 0, function* () {
  1026. try {
  1027. const fetchUrl = `${geniURLSearchTopUrl}?artist=${encodeURIComponent(artist)}&song=${encodeURIComponent(song)}`;
  1028. (0,_utils__WEBPACK_IMPORTED_MODULE_1__.log)(`Requesting URL from geniURL at '${fetchUrl}'`);
  1029. const result = yield (yield fetch(fetchUrl)).json();
  1030. if (result.error) {
  1031. (0,_utils__WEBPACK_IMPORTED_MODULE_1__.error)("Couldn't fetch genius.com URL:", result.message);
  1032. return undefined;
  1033. }
  1034. const url = result.url;
  1035. (0,_utils__WEBPACK_IMPORTED_MODULE_1__.info)(`Found genius URL: ${url}`);
  1036. return url;
  1037. }
  1038. catch (err) {
  1039. (0,_utils__WEBPACK_IMPORTED_MODULE_1__.error)("Couldn't get genius URL due to error:", err);
  1040. return undefined;
  1041. }
  1042. });
  1043. }
  1044. /***/ }),
  1045. /***/ "./src/features/menu/menu.ts":
  1046. /*!***********************************!*\
  1047. !*** ./src/features/menu/menu.ts ***!
  1048. \***********************************/
  1049. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  1050. __webpack_require__.r(__webpack_exports__);
  1051. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  1052. /* harmony export */ closeMenu: function() { return /* binding */ closeMenu; },
  1053. /* harmony export */ initMenu: function() { return /* binding */ initMenu; },
  1054. /* harmony export */ openMenu: function() { return /* binding */ openMenu; },
  1055. /* harmony export */ setActiveTab: function() { return /* binding */ setActiveTab; }
  1056. /* harmony export */ });
  1057. /* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../constants */ "./src/constants.ts");
  1058. /* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../utils */ "./src/utils.ts");
  1059. /* harmony import */ var _changelog_md__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../../changelog.md */ "./changelog.md");
  1060. /* harmony import */ var _menu_html__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./menu.html */ "./src/features/menu/menu.html");
  1061. /* harmony import */ var _menu_css__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./menu.css */ "./src/features/menu/menu.css");
  1062. //#MARKER menu
  1063. /**
  1064. * These are the base selector values for the menu tabs
  1065. * Header selector: `#${baseValue}-header`
  1066. * Content selector: `#${baseValue}-content`
  1067. */
  1068. const tabsSelectors = {
  1069. options: "bytm-menu-tab-options",
  1070. info: "bytm-menu-tab-info",
  1071. changelog: "bytm-menu-tab-changelog",
  1072. };
  1073. function initMenu() {
  1074. document.addEventListener("DOMContentLoaded", () => {
  1075. // create menu container
  1076. const menuContainer = document.createElement("div");
  1077. menuContainer.id = "bytm-menu-container";
  1078. // add menu html
  1079. menuContainer.innerHTML = _menu_html__WEBPACK_IMPORTED_MODULE_3__["default"];
  1080. document.body.appendChild(menuContainer);
  1081. initMenuContents();
  1082. });
  1083. }
  1084. let menuContTries = 0;
  1085. function initMenuContents() {
  1086. var _a;
  1087. if (!document.querySelector("#bytm-menu-dialog"))
  1088. return menuContTries++ < _constants__WEBPACK_IMPORTED_MODULE_0__.triesLimit
  1089. ? setTimeout(initMenuContents, _constants__WEBPACK_IMPORTED_MODULE_0__.triesInterval)
  1090. : (0,_utils__WEBPACK_IMPORTED_MODULE_1__.error)(`couldn't create menu element after ${_constants__WEBPACK_IMPORTED_MODULE_0__.triesLimit} tries.`);
  1091. // hook events
  1092. for (const tab in tabsSelectors) {
  1093. const selector = tabsSelectors[tab];
  1094. (_a = document.querySelector(`#${selector}-header`)) === null || _a === void 0 ? void 0 : _a.addEventListener("click", () => {
  1095. setActiveTab(tab);
  1096. });
  1097. }
  1098. // init tab contents
  1099. initOptionsContent();
  1100. initInfoContent();
  1101. initChangelogContent();
  1102. }
  1103. /** Opens the specified tab */
  1104. function setActiveTab(tab) {
  1105. const tabs = Object.assign({}, tabsSelectors);
  1106. delete tabs[tab];
  1107. // disable all but new active tab
  1108. for (const disableTab of Object.keys(tabs)) {
  1109. document.querySelector(`#${tabs[disableTab]}-header`).dataset.active = "false";
  1110. document.querySelector(`#${tabs[disableTab]}-content`).dataset.active = "false";
  1111. }
  1112. // enable new active tab
  1113. document.querySelector(`#${tabsSelectors[tab]}-header`).dataset.active = "true";
  1114. document.querySelector(`#${tabsSelectors[tab]}-content`).dataset.active = "true";
  1115. }
  1116. /** Opens the modal menu dialog */
  1117. function openMenu() {
  1118. document.querySelector("#bytm-menu-dialog").showModal();
  1119. }
  1120. /** Closes the modal menu dialog */
  1121. function closeMenu() {
  1122. document.querySelector("#bytm-menu-dialog").close();
  1123. }
  1124. //#MARKER menu tab contents
  1125. function initOptionsContent() {
  1126. const tab = document.querySelector("#bytm-menu-tab-options-content");
  1127. void tab;
  1128. }
  1129. function initInfoContent() {
  1130. const tab = document.querySelector("#bytm-menu-tab-info-content");
  1131. void tab;
  1132. }
  1133. function initChangelogContent() {
  1134. const tab = document.querySelector("#bytm-menu-tab-changelog-content");
  1135. tab.innerHTML = _changelog_md__WEBPACK_IMPORTED_MODULE_2__["default"];
  1136. }
  1137. /***/ }),
  1138. /***/ "./src/features/menu/menu_old.ts":
  1139. /*!***************************************!*\
  1140. !*** ./src/features/menu/menu_old.ts ***!
  1141. \***************************************/
  1142. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  1143. __webpack_require__.r(__webpack_exports__);
  1144. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  1145. /* harmony export */ addMenu: function() { return /* binding */ addMenu; },
  1146. /* harmony export */ closeMenu: function() { return /* binding */ closeMenu; },
  1147. /* harmony export */ openMenu: function() { return /* binding */ openMenu; }
  1148. /* harmony export */ });
  1149. /* harmony import */ var _config__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../config */ "./src/config.ts");
  1150. /* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../constants */ "./src/constants.ts");
  1151. /* harmony import */ var _index__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../index */ "./src/features/index.ts");
  1152. /* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../utils */ "./src/utils.ts");
  1153. var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
  1154. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  1155. return new (P || (P = Promise))(function (resolve, reject) {
  1156. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  1157. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  1158. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  1159. step((generator = generator.apply(thisArg, _arguments || [])).next());
  1160. });
  1161. };
  1162. //#MARKER menu
  1163. /**
  1164. * Adds an element to open the BetterYTM menu
  1165. * @deprecated
  1166. */
  1167. function addMenu() {
  1168. var _a, _b;
  1169. return __awaiter(this, void 0, void 0, function* () {
  1170. // bg & menu
  1171. const backgroundElem = document.createElement("div");
  1172. backgroundElem.id = "betterytm-menu-bg";
  1173. backgroundElem.title = "Click here to close the menu";
  1174. backgroundElem.style.visibility = "hidden";
  1175. backgroundElem.style.display = "none";
  1176. backgroundElem.addEventListener("click", (e) => {
  1177. if (e.target.id === "betterytm-menu-bg")
  1178. closeMenu();
  1179. });
  1180. document.body.addEventListener("keydown", ({ key }) => {
  1181. if (key === "Escape")
  1182. closeMenu();
  1183. });
  1184. const menuContainer = document.createElement("div");
  1185. menuContainer.title = "";
  1186. menuContainer.id = "betterytm-menu";
  1187. menuContainer.style.borderRadius = "15px";
  1188. menuContainer.style.display = "flex";
  1189. menuContainer.style.flexDirection = "column";
  1190. menuContainer.style.justifyContent = "space-between";
  1191. // title
  1192. const titleCont = document.createElement("div");
  1193. titleCont.style.padding = "8px 20px 15px 8px";
  1194. titleCont.style.display = "flex";
  1195. titleCont.style.justifyContent = "space-between";
  1196. titleCont.id = "betterytm-menu-titlecont";
  1197. const titleElem = document.createElement("h2");
  1198. titleElem.id = "betterytm-menu-title";
  1199. titleElem.innerText = `${_constants__WEBPACK_IMPORTED_MODULE_1__.scriptInfo.name} - Configuration`;
  1200. const linksCont = document.createElement("div");
  1201. linksCont.id = "betterytm-menu-linkscont";
  1202. const addLink = (imgSrc, href, title) => {
  1203. const anchorElem = document.createElement("a");
  1204. anchorElem.className = "betterytm-menu-link";
  1205. anchorElem.rel = "noopener noreferrer";
  1206. anchorElem.target = "_blank";
  1207. anchorElem.href = href;
  1208. anchorElem.title = title;
  1209. anchorElem.style.marginLeft = "10px";
  1210. const imgElem = document.createElement("img");
  1211. imgElem.className = "betterytm-menu-img";
  1212. imgElem.src = imgSrc;
  1213. imgElem.style.width = "32px";
  1214. imgElem.style.height = "32px";
  1215. anchorElem.appendChild(imgElem);
  1216. linksCont.appendChild(anchorElem);
  1217. };
  1218. addLink(`https://raw.githubusercontent.com/Sv443/BetterYTM/${_constants__WEBPACK_IMPORTED_MODULE_1__.branch}/assets/external/github.png`, _constants__WEBPACK_IMPORTED_MODULE_1__.scriptInfo.namespace, `${_constants__WEBPACK_IMPORTED_MODULE_1__.scriptInfo.name} on GitHub`);
  1219. addLink(`https://raw.githubusercontent.com/Sv443/BetterYTM/${_constants__WEBPACK_IMPORTED_MODULE_1__.branch}/assets/external/greasyfork.png`, "https://greasyfork.org/xyz", `${_constants__WEBPACK_IMPORTED_MODULE_1__.scriptInfo.name} on GreasyFork`);
  1220. const closeElem = document.createElement("img");
  1221. closeElem.id = "betterytm-menu-close";
  1222. closeElem.src = `https://raw.githubusercontent.com/Sv443/BetterYTM/${_constants__WEBPACK_IMPORTED_MODULE_1__.branch}/assets/icon/close.png`;
  1223. closeElem.title = "Click to close the menu";
  1224. closeElem.style.marginLeft = "50px";
  1225. closeElem.style.width = "32px";
  1226. closeElem.style.height = "32px";
  1227. closeElem.addEventListener("click", closeMenu);
  1228. linksCont.appendChild(closeElem);
  1229. titleCont.appendChild(titleElem);
  1230. titleCont.appendChild(linksCont);
  1231. // TODO: features
  1232. const featuresCont = document.createElement("div");
  1233. featuresCont.id = "betterytm-menu-opts";
  1234. featuresCont.style.display = "flex";
  1235. featuresCont.style.flexDirection = "column";
  1236. featuresCont.style.overflowY = "auto";
  1237. /** Gets called whenever the feature config is changed */
  1238. const confChanged = (key, initialVal, newVal) => __awaiter(this, void 0, void 0, function* () {
  1239. const fmt = (val) => typeof val === "object" ? JSON.stringify(val) : String(val);
  1240. (0,_utils__WEBPACK_IMPORTED_MODULE_3__.info)(`Feature config changed, key '${key}' from value '${fmt(initialVal)}' to '${fmt(newVal)}'`);
  1241. const featConf = Object.assign({}, yield (0,_config__WEBPACK_IMPORTED_MODULE_0__.getFeatures)());
  1242. featConf[key] = newVal;
  1243. yield (0,_config__WEBPACK_IMPORTED_MODULE_0__.saveFeatureConf)(featConf);
  1244. (0,_utils__WEBPACK_IMPORTED_MODULE_3__.log)("Saved feature config changes:\n", yield GM.getValue("betterytm-config"));
  1245. });
  1246. const features = yield (0,_config__WEBPACK_IMPORTED_MODULE_0__.getFeatures)();
  1247. for (const key in features) {
  1248. const ftInfo = _index__WEBPACK_IMPORTED_MODULE_2__.featInfo[key];
  1249. // @ts-ignore
  1250. if (!ftInfo || ftInfo.visible === false)
  1251. continue;
  1252. const { desc, type, default: ftDefault } = ftInfo;
  1253. // @ts-ignore
  1254. const step = (_a = ftInfo === null || ftInfo === void 0 ? void 0 : ftInfo.step) !== null && _a !== void 0 ? _a : undefined;
  1255. const val = features[key];
  1256. const initialVal = (_b = val !== null && val !== void 0 ? val : ftDefault) !== null && _b !== void 0 ? _b : undefined;
  1257. const ftConfElem = document.createElement("div");
  1258. ftConfElem.id = `betterytm-ftconf-${key}`;
  1259. ftConfElem.style.display = "flex";
  1260. ftConfElem.style.flexDirection = "row";
  1261. ftConfElem.style.justifyContent = "space-between";
  1262. ftConfElem.style.padding = "8px 20px";
  1263. {
  1264. const textElem = document.createElement("span");
  1265. textElem.style.display = "inline-block";
  1266. textElem.style.fontSize = "15px";
  1267. textElem.innerText = desc;
  1268. ftConfElem.appendChild(textElem);
  1269. }
  1270. {
  1271. let inputType = "text";
  1272. switch (type) {
  1273. case "toggle":
  1274. inputType = "checkbox";
  1275. break;
  1276. case "slider":
  1277. inputType = "range";
  1278. break;
  1279. case "number":
  1280. inputType = "number";
  1281. break;
  1282. }
  1283. const inputElemId = `betterytm-ftconf-${key}-input`;
  1284. const ctrlElem = document.createElement("span");
  1285. ctrlElem.style.display = "inline-block";
  1286. ctrlElem.style.whiteSpace = "nowrap";
  1287. const inputElem = document.createElement("input");
  1288. inputElem.id = inputElemId;
  1289. inputElem.style.marginRight = "37px";
  1290. inputElem.type = inputType;
  1291. if (type === "toggle")
  1292. inputElem.style.marginLeft = "5px";
  1293. if (typeof initialVal !== "undefined")
  1294. inputElem.value = String(initialVal);
  1295. if (type === "number" && step)
  1296. inputElem.step = step;
  1297. // @ts-ignore
  1298. if (ftInfo.min && ftInfo.max) {
  1299. // @ts-ignore
  1300. inputElem.min = ftInfo.min;
  1301. // @ts-ignore
  1302. inputElem.max = ftInfo.max;
  1303. }
  1304. if (type === "toggle" && typeof initialVal !== "undefined")
  1305. inputElem.checked = Boolean(initialVal);
  1306. // @ts-ignore
  1307. const unitTxt = typeof ftInfo.unit === "string" ? " " + ftInfo.unit : "";
  1308. const fmtVal = (v) => String(v).trim();
  1309. const toggleLabelText = (toggled) => toggled ? "On" : "Off";
  1310. let labelElem;
  1311. if (type === "slider") {
  1312. labelElem = document.createElement("label");
  1313. labelElem.classList.add("betterytm-ftconf-label");
  1314. labelElem.style.marginRight = "20px";
  1315. labelElem.style.fontSize = "16px";
  1316. labelElem.htmlFor = inputElemId;
  1317. labelElem.innerText = fmtVal(initialVal) + unitTxt;
  1318. inputElem.addEventListener("input", () => {
  1319. if (labelElem)
  1320. labelElem.innerText = fmtVal(parseInt(inputElem.value)) + unitTxt;
  1321. });
  1322. }
  1323. else if (type === "toggle") {
  1324. labelElem = document.createElement("label");
  1325. labelElem.classList.add("betterytm-ftconf-label");
  1326. labelElem.style.paddingLeft = "10px";
  1327. labelElem.style.paddingRight = "5px";
  1328. labelElem.style.fontSize = "16px";
  1329. labelElem.htmlFor = inputElemId;
  1330. labelElem.innerText = toggleLabelText(Boolean(initialVal)) + unitTxt;
  1331. inputElem.addEventListener("input", () => {
  1332. if (labelElem)
  1333. labelElem.innerText = toggleLabelText(inputElem.checked) + unitTxt;
  1334. });
  1335. }
  1336. inputElem.addEventListener("input", () => {
  1337. let v = parseInt(inputElem.value);
  1338. if (isNaN(v))
  1339. v = Number(inputElem.value);
  1340. if (typeof initialVal !== "undefined")
  1341. confChanged(key, initialVal, (type !== "toggle" ? v : inputElem.checked));
  1342. });
  1343. const resetElem = document.createElement("button");
  1344. resetElem.innerText = "Reset";
  1345. resetElem.addEventListener("click", () => {
  1346. inputElem[type !== "toggle" ? "value" : "checked"] = ftDefault;
  1347. if (labelElem) {
  1348. if (type === "toggle")
  1349. labelElem.innerText = toggleLabelText(inputElem.checked);
  1350. else
  1351. labelElem.innerText = fmtVal(parseInt(inputElem.value));
  1352. }
  1353. if (typeof initialVal !== "undefined")
  1354. confChanged(key, initialVal, ftDefault);
  1355. });
  1356. labelElem && ctrlElem.appendChild(labelElem);
  1357. ctrlElem.appendChild(inputElem);
  1358. ctrlElem.appendChild(resetElem);
  1359. ftConfElem.appendChild(ctrlElem);
  1360. }
  1361. featuresCont.appendChild(ftConfElem);
  1362. }
  1363. const footerElem = document.createElement("div");
  1364. footerElem.id = "betterytm-menu-footer";
  1365. footerElem.style.marginTop = "20px";
  1366. footerElem.style.fontSize = "17px";
  1367. footerElem.style.textDecoration = "underline";
  1368. footerElem.style.padding = "10px 20px";
  1369. footerElem.style.position = "sticky";
  1370. footerElem.style.backgroundColor = "var(--bytm-menu-bg)";
  1371. footerElem.style.bottom = "0";
  1372. footerElem.innerText = "You need to reload the page to apply changes.";
  1373. const reloadElem = document.createElement("button");
  1374. reloadElem.style.marginLeft = "20px";
  1375. reloadElem.innerText = "Reload now";
  1376. reloadElem.title = "Click to reload the page";
  1377. reloadElem.addEventListener("click", () => location.reload());
  1378. footerElem.appendChild(reloadElem);
  1379. featuresCont.appendChild(footerElem);
  1380. // finalize
  1381. const menuBody = document.createElement("div");
  1382. menuBody.id = "betterytm-menu-body";
  1383. menuBody.appendChild(titleCont);
  1384. menuBody.appendChild(featuresCont);
  1385. const versionCont = document.createElement("div");
  1386. versionCont.style.display = "flex";
  1387. versionCont.style.justifyContent = "space-around";
  1388. versionCont.style.fontSize = "1.15em";
  1389. versionCont.style.marginTop = "10px";
  1390. versionCont.style.marginBottom = "5px";
  1391. const versionElem = document.createElement("span");
  1392. versionElem.id = "betterytm-menu-version";
  1393. versionElem.innerText = `v${_constants__WEBPACK_IMPORTED_MODULE_1__.scriptInfo.version}`;
  1394. versionCont.appendChild(versionElem);
  1395. featuresCont.appendChild(versionCont);
  1396. menuContainer.appendChild(menuBody);
  1397. menuContainer.appendChild(versionCont);
  1398. backgroundElem.appendChild(menuContainer);
  1399. document.body.appendChild(backgroundElem);
  1400. // add style
  1401. const menuStyle = `\
  1402. :root {
  1403. --bytm-menu-bg: #212121;
  1404. }
  1405. #betterytm-menu-bg {
  1406. display: block;
  1407. position: fixed;
  1408. width: 100vw;
  1409. height: 100vh;
  1410. top: 0;
  1411. left: 0;
  1412. z-index: 15;
  1413. background-color: rgba(0, 0, 0, 0.6);
  1414. }
  1415. /* TODO:FIXME: needs better positioning (vw and vh === "big no no") */
  1416. #betterytm-menu {
  1417. display: inline-block;
  1418. position: fixed;
  1419. width: 50vw;
  1420. height: auto;
  1421. left: 25vw;
  1422. top: 10vh;
  1423. z-index: 16;
  1424. padding: 8px;
  1425. color: #fff;
  1426. background-color: var(--bytm-menu-bg);
  1427. }
  1428. #betterytm-menu-opts {
  1429. max-height: 70vh;
  1430. overflow: auto;
  1431. }
  1432. #betterytm-menu-titlecont {
  1433. display: flex;
  1434. }
  1435. #betterytm-menu-title {
  1436. font-size: 20px;
  1437. margin-top: 5px;
  1438. margin-bottom: 8px;
  1439. }
  1440. #betterytm-menu-linkscont {
  1441. display: flex;
  1442. }
  1443. .betterytm-menu-link {
  1444. display: inline-block;
  1445. }
  1446. /*.betterytm-menu-img {
  1447. }*/
  1448. #betterytm-menu-close {
  1449. cursor: pointer;
  1450. }
  1451. .betterytm-ftconf-label {
  1452. user-select: none;
  1453. }`;
  1454. (0,_utils__WEBPACK_IMPORTED_MODULE_3__.log)("Added menu elem:", backgroundElem);
  1455. (0,_utils__WEBPACK_IMPORTED_MODULE_3__.addGlobalStyle)(menuStyle, "menu");
  1456. });
  1457. }
  1458. function closeMenu() {
  1459. const menuBg = document.querySelector("#betterytm-menu-bg");
  1460. menuBg.style.visibility = "hidden";
  1461. menuBg.style.display = "none";
  1462. }
  1463. function openMenu() {
  1464. const menuBg = document.querySelector("#betterytm-menu-bg");
  1465. menuBg.style.visibility = "visible";
  1466. menuBg.style.display = "block";
  1467. }
  1468. /***/ }),
  1469. /***/ "./src/utils.ts":
  1470. /*!**********************!*\
  1471. !*** ./src/utils.ts ***!
  1472. \**********************/
  1473. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  1474. __webpack_require__.r(__webpack_exports__);
  1475. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  1476. /* harmony export */ addGlobalStyle: function() { return /* binding */ addGlobalStyle; },
  1477. /* harmony export */ error: function() { return /* binding */ error; },
  1478. /* harmony export */ getDomain: function() { return /* binding */ getDomain; },
  1479. /* harmony export */ getVideoTime: function() { return /* binding */ getVideoTime; },
  1480. /* harmony export */ info: function() { return /* binding */ info; },
  1481. /* harmony export */ initSiteEvents: function() { return /* binding */ initSiteEvents; },
  1482. /* harmony export */ insertAfter: function() { return /* binding */ insertAfter; },
  1483. /* harmony export */ log: function() { return /* binding */ log; },
  1484. /* harmony export */ removeAllObservers: function() { return /* binding */ removeAllObservers; },
  1485. /* harmony export */ setLogLevel: function() { return /* binding */ setLogLevel; },
  1486. /* harmony export */ siteEvents: function() { return /* binding */ siteEvents; },
  1487. /* harmony export */ warn: function() { return /* binding */ warn; }
  1488. /* harmony export */ });
  1489. /* harmony import */ var _billjs_event_emitter__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @billjs/event-emitter */ "./node_modules/@billjs/event-emitter/lib/index.js");
  1490. /* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./constants */ "./src/constants.ts");
  1491. //#MARKER BYTM-specific
  1492. let curLogLevel = 1;
  1493. /** Sets the current log level. 0 = Debug, 1 = Info */
  1494. function setLogLevel(level) {
  1495. curLogLevel = level;
  1496. }
  1497. function getLogLevel(...args) {
  1498. if (typeof args.at(-1) === "number")
  1499. return args.splice(args.length - 1, 1)[0];
  1500. return 0;
  1501. }
  1502. /** Common prefix to be able to tell logged messages apart */
  1503. const consPrefix = `[${_constants__WEBPACK_IMPORTED_MODULE_1__.scriptInfo.name}]`;
  1504. /**
  1505. * Logs string-compatible values to the console, as long as the log level is sufficient.
  1506. * @param args Last parameter is logLevel: 0 = Debug, 1/undefined = Info
  1507. */
  1508. function log(...args) {
  1509. if (curLogLevel <= getLogLevel(...args))
  1510. console.log(consPrefix, ...args);
  1511. }
  1512. /**
  1513. * Logs string-compatible values to the console as info, as long as the log level is sufficient.
  1514. * @param args Last parameter is logLevel: 0 = Debug, 1/undefined = Info
  1515. */
  1516. function info(...args) {
  1517. if (curLogLevel <= getLogLevel(...args))
  1518. console.info(consPrefix, ...args);
  1519. }
  1520. /**
  1521. * Logs string-compatible values to the console as a warning, as long as the log level is sufficient.
  1522. * @param args Last parameter is logLevel: 0 = Debug, 1/undefined = Info
  1523. */
  1524. function warn(...args) {
  1525. if (curLogLevel <= getLogLevel(...args))
  1526. console.warn(consPrefix, ...args);
  1527. }
  1528. /** Logs string-compatible values to the console as an error. */
  1529. function error(...args) {
  1530. console.error(consPrefix, ...args);
  1531. }
  1532. /**
  1533. * Returns the current domain as a constant string representation
  1534. * @throws Throws if script runs on an unexpected website
  1535. */
  1536. function getDomain() {
  1537. const { hostname } = new URL(location.href);
  1538. if (hostname.includes("music.youtube"))
  1539. return "ytm";
  1540. else if (hostname.includes("youtube"))
  1541. return "yt";
  1542. else
  1543. throw new Error("BetterYTM is running on an unexpected website. Please don't tamper with the @match directives in the userscript header.");
  1544. }
  1545. /**
  1546. * Returns the current video time in seconds
  1547. * @param force Set to true to dispatch mouse movement events in case the video time can't be estimated
  1548. * @returns Returns null if the video time is unavailable
  1549. */
  1550. function getVideoTime(force = false) {
  1551. const domain = getDomain();
  1552. try {
  1553. if (domain === "ytm") {
  1554. const pbEl = document.querySelector("#progress-bar");
  1555. return !isNaN(Number(pbEl.value)) ? Number(pbEl.value) : null;
  1556. }
  1557. else if (domain === "yt") {
  1558. // YT doesn't update the progress bar when it's hidden (YTM doesn't hide it) so TODO: come up with some solution here
  1559. // Possible solution:
  1560. // - Use MutationObserver to detect when attributes of progress bar (selector `div.ytp-progress-bar[role="slider"]`) change
  1561. // - Wait until the attribute increments, then save the value of `aria-valuenow` and the current system time to memory
  1562. // - When site switch hotkey is pressed, take saved `aria-valuenow` value and add the difference between saved system time and current system time
  1563. // - If no value is present, use the script from `dev/ytForceShowVideoTime.js` to simulate mouse movement to force the element to update
  1564. // - Subtract one or two seconds to make up for rounding errors
  1565. // - profit
  1566. // if(!ytCurrentVideoTime) {
  1567. // ytForceShowVideoTime();
  1568. // const videoTime = document.querySelector("#TODO")?.getAttribute("aria-valuenow") ?? null;
  1569. // }
  1570. void [force, ytForceShowVideoTime];
  1571. return null;
  1572. }
  1573. return null;
  1574. }
  1575. catch (err) {
  1576. error("Couldn't get video time due to error:", err);
  1577. return null;
  1578. }
  1579. }
  1580. /** Sends events that force the video controls to become visible for about 3 seconds */
  1581. function ytForceShowVideoTime() {
  1582. const player = document.querySelector("#movie_player");
  1583. if (!player)
  1584. return false;
  1585. const defaultProps = {
  1586. view: unsafeWindow !== null && unsafeWindow !== void 0 ? unsafeWindow : window,
  1587. bubbles: true,
  1588. cancelable: false,
  1589. };
  1590. player.dispatchEvent(new MouseEvent("mouseenter", defaultProps));
  1591. const { x, y, width, height } = player.getBoundingClientRect();
  1592. const screenY = Math.round(y + height / 2);
  1593. const screenX = x + Math.min(50, Math.round(width / 3));
  1594. player.dispatchEvent(new MouseEvent("mousemove", Object.assign(Object.assign({}, defaultProps), { screenY,
  1595. screenX, movementX: 5, movementY: 0 })));
  1596. setTimeout(() => {
  1597. player.dispatchEvent(new MouseEvent("mouseleave", defaultProps));
  1598. }, 4000);
  1599. return true;
  1600. }
  1601. //#MARKER DOM
  1602. /**
  1603. * Inserts `afterNode` as a sibling just after the provided `beforeNode`
  1604. * @param beforeNode
  1605. * @param afterNode
  1606. * @returns Returns the `afterNode`
  1607. */
  1608. function insertAfter(beforeNode, afterNode) {
  1609. var _a;
  1610. (_a = beforeNode.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(afterNode, beforeNode.nextSibling);
  1611. return afterNode;
  1612. }
  1613. /**
  1614. * Adds global CSS style through a `<style>` element in the document's `<head>`
  1615. * @param style CSS string
  1616. * @param ref Reference name that is included in the `<style>`'s ID - prefixed with `betterytm-style-` - defaults to a random number if left undefined
  1617. */
  1618. function addGlobalStyle(style, ref) {
  1619. if (typeof ref !== "string" || ref.length === 0)
  1620. ref = String(Math.floor(Math.random() * 10000));
  1621. const styleElem = document.createElement("style");
  1622. styleElem.id = `betterytm-style-${ref}`;
  1623. styleElem.innerHTML = style;
  1624. document.head.appendChild(styleElem);
  1625. log(`Inserted global style with ref '${ref}':`, styleElem);
  1626. }
  1627. const siteEvents = new _billjs_event_emitter__WEBPACK_IMPORTED_MODULE_0__.EventEmitter();
  1628. let observers = [];
  1629. /** Creates MutationObservers that check if parts of the site have changed, then emit an event on the `siteEvents` instance */
  1630. function initSiteEvents() {
  1631. try {
  1632. //#SECTION queue
  1633. const queueObs = new MutationObserver(([{ addedNodes, removedNodes, target }]) => {
  1634. if (addedNodes.length > 0 || removedNodes.length > 0) {
  1635. info("Detected queue change - added nodes:", addedNodes.length, "- removed nodes:", removedNodes.length);
  1636. siteEvents.fire("queueChanged", target);
  1637. }
  1638. });
  1639. // only observe added or removed elements
  1640. queueObs.observe(document.querySelector(".side-panel.modular #contents.ytmusic-player-queue"), {
  1641. childList: true,
  1642. });
  1643. //#SECTION carousel shelves
  1644. const shelfContainerObs = new MutationObserver(([{ addedNodes, removedNodes }]) => {
  1645. if (addedNodes.length > 0 || removedNodes.length > 0) {
  1646. info("Detected carousel shelf container change - added nodes:", addedNodes.length, "- removed nodes:", removedNodes.length);
  1647. siteEvents.fire("carouselShelvesChanged", { addedNodes, removedNodes });
  1648. }
  1649. });
  1650. shelfContainerObs.observe(document.querySelector("#contents.ytmusic-section-list-renderer"), {
  1651. childList: true,
  1652. });
  1653. info("Successfully initialized SiteEvents observers");
  1654. observers = [
  1655. queueObs,
  1656. shelfContainerObs,
  1657. ];
  1658. }
  1659. catch (err) {
  1660. error("Couldn't initialize SiteEvents observers due to an error:\n", err);
  1661. }
  1662. }
  1663. /** Disconnects and deletes all observers. Run `initSiteEvents()` again to create new ones. */
  1664. function removeAllObservers() {
  1665. observers.forEach((observer) => observer.disconnect());
  1666. observers = [];
  1667. }
  1668. /***/ })
  1669. /******/ });
  1670. /************************************************************************/
  1671. /******/ // The module cache
  1672. /******/ var __webpack_module_cache__ = {};
  1673. /******/
  1674. /******/ // The require function
  1675. /******/ function __webpack_require__(moduleId) {
  1676. /******/ // Check if module is in cache
  1677. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  1678. /******/ if (cachedModule !== undefined) {
  1679. /******/ return cachedModule.exports;
  1680. /******/ }
  1681. /******/ // Create a new module (and put it into the cache)
  1682. /******/ var module = __webpack_module_cache__[moduleId] = {
  1683. /******/ // no module.id needed
  1684. /******/ // no module.loaded needed
  1685. /******/ exports: {}
  1686. /******/ };
  1687. /******/
  1688. /******/ // Execute the module function
  1689. /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
  1690. /******/
  1691. /******/ // Return the exports of the module
  1692. /******/ return module.exports;
  1693. /******/ }
  1694. /******/
  1695. /************************************************************************/
  1696. /******/ /* webpack/runtime/define property getters */
  1697. /******/ !function() {
  1698. /******/ // define getter functions for harmony exports
  1699. /******/ __webpack_require__.d = function(exports, definition) {
  1700. /******/ for(var key in definition) {
  1701. /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  1702. /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  1703. /******/ }
  1704. /******/ }
  1705. /******/ };
  1706. /******/ }();
  1707. /******/
  1708. /******/ /* webpack/runtime/hasOwnProperty shorthand */
  1709. /******/ !function() {
  1710. /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
  1711. /******/ }();
  1712. /******/
  1713. /******/ /* webpack/runtime/make namespace object */
  1714. /******/ !function() {
  1715. /******/ // define __esModule on exports
  1716. /******/ __webpack_require__.r = function(exports) {
  1717. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  1718. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  1719. /******/ }
  1720. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  1721. /******/ };
  1722. /******/ }();
  1723. /******/
  1724. /************************************************************************/
  1725. var __webpack_exports__ = {};
  1726. // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
  1727. !function() {
  1728. /*!*******************************!*\
  1729. !*** ./src/BetterYTM.user.ts ***!
  1730. \*******************************/
  1731. __webpack_require__.r(__webpack_exports__);
  1732. /* harmony import */ var _config__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./config */ "./src/config.ts");
  1733. /* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./constants */ "./src/constants.ts");
  1734. /* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./utils */ "./src/utils.ts");
  1735. /* harmony import */ var _features_index__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./features/index */ "./src/features/index.ts");
  1736. var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
  1737. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  1738. return new (P || (P = Promise))(function (resolve, reject) {
  1739. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  1740. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  1741. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  1742. step((generator = generator.apply(thisArg, _arguments || [])).next());
  1743. });
  1744. };
  1745. // TODO: add some style
  1746. console.log(`${_constants__WEBPACK_IMPORTED_MODULE_1__.scriptInfo.name} v${_constants__WEBPACK_IMPORTED_MODULE_1__.scriptInfo.version} (${_constants__WEBPACK_IMPORTED_MODULE_1__.scriptInfo.lastCommit}) - ${_constants__WEBPACK_IMPORTED_MODULE_1__.scriptInfo.namespace}`);
  1747. console.log(`Powered by lots of ambition and my song metadata API: ${_features_index__WEBPACK_IMPORTED_MODULE_3__.geniUrlBase}`);
  1748. const domain = (0,_utils__WEBPACK_IMPORTED_MODULE_2__.getDomain)();
  1749. function init() {
  1750. return __awaiter(this, void 0, void 0, function* () {
  1751. yield (0,_features_index__WEBPACK_IMPORTED_MODULE_3__.preInitLayout)();
  1752. try {
  1753. document.addEventListener("DOMContentLoaded", onDomLoad);
  1754. }
  1755. catch (err) {
  1756. console.error(`${_constants__WEBPACK_IMPORTED_MODULE_1__.scriptInfo.name} - General Error:`, err);
  1757. }
  1758. try {
  1759. (0,_features_index__WEBPACK_IMPORTED_MODULE_3__.initMenu)();
  1760. }
  1761. catch (err) {
  1762. (0,_utils__WEBPACK_IMPORTED_MODULE_2__.error)("Couldn't initialize menu:", err);
  1763. }
  1764. });
  1765. }
  1766. /** Called when the DOM has finished loading and can be queried and altered by the userscript */
  1767. function onDomLoad() {
  1768. return __awaiter(this, void 0, void 0, function* () {
  1769. // post-build these double quotes are replaced by backticks
  1770. (0,_utils__WEBPACK_IMPORTED_MODULE_2__.addGlobalStyle)(`/*!***************************************************************************!*\
  1771. !*** css ./node_modules/css-loader/dist/cjs.js!./src/features/layout.css ***!
  1772. \***************************************************************************/
  1773. #betterytm-watermark {
  1774. font-size: 10px;
  1775. display: inline-block;
  1776. position: absolute;
  1777. left: 45px;
  1778. top: 46px;
  1779. z-index: 10;
  1780. color: white;
  1781. text-decoration: none;
  1782. cursor: pointer;
  1783. }
  1784. @media(max-width: 615px) {
  1785. #betterytm-watermark {
  1786. display: none;
  1787. }
  1788. }
  1789. #betterytm-watermark:hover {
  1790. text-decoration: underline;
  1791. }
  1792. .side-panel.modular ytmusic-player-queue-item .song-info.ytmusic-player-queue-item {
  1793. position: relative;
  1794. }
  1795. .side-panel.modular ytmusic-player-queue-item .song-info .bytm-queue-btn-container {
  1796. display: none;
  1797. position: absolute;
  1798. right: 0;
  1799. }
  1800. .side-panel.modular ytmusic-player-queue-item:hover .song-info .bytm-queue-btn-container {
  1801. display: inline-block;
  1802. }
  1803. /*!***************************************************************************!*\
  1804. !*** css ./node_modules/css-loader/dist/cjs.js!./src/features/lyrics.css ***!
  1805. \***************************************************************************/
  1806. #betterytm-lyrics-button {
  1807. align-items: center;
  1808. justify-content: center;
  1809. position: relative;
  1810. vertical-align: middle;
  1811. margin-left: 8px;
  1812. width: 40px;
  1813. height: 40px;
  1814. border-radius: 100%;
  1815. background-color: transparent;
  1816. }
  1817. #betterytm-lyrics-button:hover {
  1818. background-color: #383838;
  1819. }
  1820. #betterytm-lyrics-img {
  1821. display: inline-block;
  1822. z-index: 10;
  1823. width: 24px;
  1824. height: 24px;
  1825. padding: 5px;
  1826. }
  1827. /*!******************************************************************************!*\
  1828. !*** css ./node_modules/css-loader/dist/cjs.js!./src/features/menu/menu.css ***!
  1829. \******************************************************************************/
  1830. /* #bytm-menu-backdrop {
  1831. display: none;
  1832. flex-direction: column;
  1833. justify-content: center;
  1834. align-items: center;
  1835. }
  1836. #bytm-menu-backdrop[data-menu-open="true"] {
  1837. display: flex;
  1838. } */
  1839. #bytm-menu-header-container {
  1840. display: flex;
  1841. justify-content: flex-start;
  1842. align-items: center;
  1843. border-color: #ffffff;
  1844. border-style: none solid none none;
  1845. }
  1846. .bytm-menu-header-option {
  1847. display: "flex";
  1848. justify-content: center;
  1849. align-items: center;
  1850. border-color: #ffffff;
  1851. border-style: solid none solid none;
  1852. }
  1853. #bytm-menu-header-option h3 {
  1854. margin: 0;
  1855. }
  1856. .bytm-menu-tab[data-active="true"] {
  1857. display: none;
  1858. }
  1859. .bytm-menu-tab[data-active="false"] {
  1860. display: none;
  1861. }`, "global");
  1862. const features = yield (0,_config__WEBPACK_IMPORTED_MODULE_0__.loadFeatureConf)();
  1863. (0,_utils__WEBPACK_IMPORTED_MODULE_2__.log)(`Initializing features for domain '${domain}'`);
  1864. try {
  1865. if (domain === "ytm") {
  1866. (0,_utils__WEBPACK_IMPORTED_MODULE_2__.initSiteEvents)();
  1867. if (features.arrowKeySupport)
  1868. (0,_features_index__WEBPACK_IMPORTED_MODULE_3__.initArrowKeySkip)();
  1869. if (features.removeUpgradeTab)
  1870. (0,_features_index__WEBPACK_IMPORTED_MODULE_3__.removeUpgradeTab)();
  1871. if (features.watermarkEnabled)
  1872. (0,_features_index__WEBPACK_IMPORTED_MODULE_3__.addWatermark)();
  1873. if (features.geniusLyrics)
  1874. (0,_features_index__WEBPACK_IMPORTED_MODULE_3__.addMediaCtrlGeniusBtn)();
  1875. if (features.queueButtons)
  1876. (0,_features_index__WEBPACK_IMPORTED_MODULE_3__.initQueueButtons)();
  1877. if (typeof features.volumeSliderSize === "number")
  1878. (0,_features_index__WEBPACK_IMPORTED_MODULE_3__.setVolSliderSize)();
  1879. if (features.anchorImprovements)
  1880. (0,_features_index__WEBPACK_IMPORTED_MODULE_3__.addAnchorImprovements)();
  1881. (0,_features_index__WEBPACK_IMPORTED_MODULE_3__.setVolSliderStep)();
  1882. }
  1883. if (["ytm", "yt"].includes(domain)) {
  1884. if (features.switchBetweenSites)
  1885. (0,_features_index__WEBPACK_IMPORTED_MODULE_3__.initSiteSwitch)(domain);
  1886. try {
  1887. (0,_features_index__WEBPACK_IMPORTED_MODULE_3__.addMenu)(); // TODO: remove
  1888. }
  1889. catch (err) {
  1890. (0,_utils__WEBPACK_IMPORTED_MODULE_2__.error)("Couldn't add menu:", err);
  1891. }
  1892. }
  1893. }
  1894. catch (err) {
  1895. (0,_utils__WEBPACK_IMPORTED_MODULE_2__.error)("General error while executing feature:", err);
  1896. }
  1897. });
  1898. }
  1899. // stuff that needs to be called ASAP, before anything async happens
  1900. (0,_utils__WEBPACK_IMPORTED_MODULE_2__.setLogLevel)(_constants__WEBPACK_IMPORTED_MODULE_1__.logLevel);
  1901. if (domain === "ytm")
  1902. (0,_features_index__WEBPACK_IMPORTED_MODULE_3__.initBeforeUnloadHook)();
  1903. init();
  1904. }();
  1905. //# sourceMappingURL=BetterYTM.user.js.map