├── .github └── workflows │ └── standardjs.yml ├── LICENSE ├── README.md ├── YoutubeGeniusLyrics.user.js ├── screenshot-2022-light.png ├── screenshot-2022-tabview-youtube.png ├── screenshot-2022.png ├── screenshot-dark(spotify).png └── screenshot.png /.github/workflows/standardjs.yml: -------------------------------------------------------------------------------- 1 | name: standardjs 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build: 7 | timeout-minutes: 5 8 | runs-on: ubuntu-latest 9 | steps: 10 | - name: Checkout code 11 | uses: actions/checkout@v3 12 | - name: Setup bun 13 | uses: oven-sh/setup-bun@v1 14 | with: 15 | bun-version: latest # or "latest", "canary", 16 | - name: Run linting and formatting 17 | run: bunx standard --verbose | bunx snazzy 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Youtube-Genius-Lyrics-userscript 2 | 3 | ### Description: 4 | 5 | A userscript or greasemonkey script that shows lyrics from [genius.com](https://genius.com/) on [YouTube](https://www.youtube.com/) music videos 6 | 7 | This is a userscript for your browser. It's primarily designed for Firefox and Chrome with 8 | [Tampermonkey](https://www.tampermonkey.net/) [![Chrome logo](https://raw.githubusercontent.com/OpenUserJS/OpenUserJS.org/master/public/images/ua/chrome16.png)](https://chrome.google.com/webstore/detail/tampermonkey/dhdgffkkebhmkfjojejmpbldmpobfkfo) [![Firefox logo](https://raw.githubusercontent.com/OpenUserJS/OpenUserJS.org/master/public/images/ua/firefox16.png)](https://addons.mozilla.org/en-US/firefox/addon/tampermonkey/) 9 | 10 | General information about userscripts and how to use them can be found at [openuserjs.org/about/Userscript-Beginners-HOWTO](https://openuserjs.org/about/Userscript-Beginners-HOWTO). 11 | 12 | [**Click here to install**](https://greasyfork.org/scripts/386259-youtube-genius-lyrics/code/Youtube%20Genius%20Lyrics.user.js) 13 | Tested with Firefox/**Tampermonkey** and Chrome/**Tampermonkey**. 14 | 15 | Family of GeniusLyrics Userscripts: 16 | * Powered by **GeniusLyrics Library** [GitHub](https://github.com/cvzi/genius-lyrics-userscript/) [Greaskfork](https://greasyfork.org/en/scripts/406698-geniuslyrics) 17 | * **Spotify Genius Lyrics** [GitHub](https://github.com/cvzi/Spotify-Genius-Lyrics-userscript) [Greaskfork](https://greasyfork.org/en/scripts/377439-spotify-genius-lyrics) 18 | * **Youtube Genius Lyrics** [GitHub](https://github.com/cvzi/Youtube-Genius-Lyrics-userscript) [Greaskfork](https://greasyfork.org/en/scripts/386259-youtube-genius-lyrics) 19 | * **Youtube Music Genius Lyrics** [GitHub](https://github.com/cvzi/Youtube-Music-Genius-Lyrics-userscript/) [Greaskfork](https://greasyfork.org/en/scripts/406892-youtube-music-genius-lyrics) 20 | 21 | ### Contributors: 22 | [![Contributors](https://contrib.rocks/image?repo=cvzi/Youtube-Genius-Lyrics-userscript)](https://github.com/cvzi/Youtube-Genius-Lyrics-userscript/graphs/contributors) 23 | 24 | ### Screenshots: 25 | * Year 2022 26 | - Default theme (Dynamic Color with YouTube Dark & Light Themes) 27 | * *Note: YouTube is now moving forwards into the dark mode (Darker Dark Mode with Cinematic Annotations)* 28 | * *Using Light Theme is highly non-recommended* 29 | ![Screenshot as of 2022](screenshot-2022.png) 30 | ![Screenshot as of 2022 (Light)](screenshot-2022-light.png) 31 | - Integrated with [Tabview Youtube](https://greasyfork.org/en/scripts/428651-tabview-youtube) 32 | * *Tabview Youtube*[(GitHub)](https://github.com/cyfung1031/Tabview-Youtube) is a userscript developed by [CY Fung](https://github.com/cyfung1031) to manage the page layout as tabs to maximize the watching experience. 33 | ![Screenshot as of 2022 with TabView Youtube](screenshot-2022-tabview-youtube.png) 34 | * Year 2019 - 2021 35 | - Default theme 36 | ![Screenshot of youtube music video with lyrics](screenshot.png) 37 | - Dark (Spotify) theme 38 | ![Screenshot of youtube music video with lyrics (dark)](screenshot-dark(spotify).png) 39 | 40 | [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com) ![standardjs](https://github.com/cvzi/Youtube-Genius-Lyrics-userscript/workflows/standardjs/badge.svg) 41 | -------------------------------------------------------------------------------- /YoutubeGeniusLyrics.user.js: -------------------------------------------------------------------------------- 1 | // ==UserScript== 2 | // @name Youtube Genius Lyrics 3 | // @namespace https://greasyfork.org/users/20068 4 | // @description Shows lyrics/songtexts from genius.com on Youtube next to music videos 5 | // @description:es Mostra la letra de genius.com de las canciones en Youtube junto a los vídeos musicales 6 | // @description:de Zeigt den Songtext von genius.com neben Musikvideos auf Youtube 7 | // @description:fr Présente les paroles des chansons de genius.com sur Youtube à côté des vidéos de musique. 8 | // @description:pl Pokazuje teksty piosenek z genius.com na Youtube obok teledysków 9 | // @description:pt Mostra letras de canções de genius.com no Youtube ao lado de vídeos de música 10 | // @description:it Mostra i testi delle canzoni di genius.com su Youtube accanto ai video musicali 11 | // @description:ja Youtube(ユーチューブ)では、ミュージックビデオの横に genius.com の歌詞が表示されます 12 | // @license GPL-3.0-or-later; http://www.gnu.org/licenses/gpl-3.0.txt 13 | // @copyright 2020, cuzi (https://github.com/cvzi) 14 | // @author cuzi 15 | // @icon https://raw.githubusercontent.com/hfg-gmuend/openmoji/master/color/72x72/E044.png 16 | // @supportURL https://github.com/cvzi/Youtube-Genius-Lyrics-userscript/issues 17 | // @version 10.10.15 18 | // @require https://update.greasyfork.org/scripts/406698/GeniusLyrics.js 19 | // @require https://cdnjs.cloudflare.com/ajax/libs/lz-string/1.5.0/lz-string.min.js 20 | // @grant GM.xmlHttpRequest 21 | // @grant GM.setValue 22 | // @grant GM.getValue 23 | // @grant GM.registerMenuCommand 24 | // @grant GM_addValueChangeListener 25 | // @connect genius.com 26 | // @match https://www.youtube.com/* 27 | // @match https://music.youtube.com/* 28 | // @exclude https://www.youtube.com/embed/* 29 | // @exclude https://www.youtube-nocookie.com/embed/* 30 | // @exclude https://www.youtube.com/live_chat* 31 | // @exclude https://www.youtube.com/live_chat_replay* 32 | // @exclude /^https?://\S+\.(png|jpg|jpeg|gif|xml|svg|manifest|log|ini)[^\/]*$/ 33 | // ==/UserScript== 34 | 35 | /* 36 | Copyright (C) 2020 cuzi (cuzi@openmail.cc) 37 | This program is free software: you can redistribute it and/or modify 38 | it under the terms of the GNU General Public License as published by 39 | the Free Software Foundation, either version 3 of the License, or 40 | (at your option) any later version. 41 | This program is distributed in the hope that it will be useful, 42 | but WITHOUT ANY WARRANTY; without even the implied warranty of 43 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 44 | GNU General Public License for more details. 45 | You should have received a copy of the GNU General Public License 46 | along with this program. If not, see . 47 | */ 48 | 49 | /* global GM, genius, geniusLyrics, top, GM_addValueChangeListener, sessionStorage */ // eslint-disable-line no-unused-vars, no-redeclare 50 | /* jshint asi: true, esversion: 8 */ 51 | 52 | 'use strict' 53 | 54 | let genius 55 | const SCRIPT_NAME = 'Youtube Genius Lyrics' 56 | /** @type {globalThis.PromiseConstructor} */ 57 | const Promise = (async () => { })().constructor // YouTube polyfill to Promise in older browsers will make the feature being unstable. 58 | 59 | let lyricsDisplayState = 'hidden' 60 | let disableShowLyricsButton = false // hide if the page is confirmed as non-video page 61 | let isYouTubeLive = false 62 | let iframeBlankURL = null 63 | 64 | const EXCLUDE_LIVE_VIDEO = true // this should be configurable in "options" ? [>=25min] 65 | const EXCLUDE_SHORT_LEN = true // this should be configurable in "options" ? [<15s] 66 | 67 | const elmBuild = (tag, ...contents) => { 68 | /** @type {HTMLElement} */ 69 | const elm = typeof tag === 'string' ? document.createElement(tag) : tag 70 | for (const content of contents) { 71 | if (!content || typeof content !== 'object' || (content instanceof Node)) { // eslint-disable-line no-undef 72 | elm.append(content) 73 | } else if (content.length > 0) { 74 | elm.appendChild(elmBuild(...content)) 75 | } else if (content.style) { 76 | Object.assign(elm.style, content.style) 77 | } else if (content.classList) { 78 | elm.classList.add(...content.classList) 79 | } else if (content.attr) { 80 | for (const [attr, val] of Object.entries(content.attr)) elm.setAttribute(attr, val) 81 | } else { 82 | Object.assign(elm, content) 83 | } 84 | } 85 | return elm 86 | } 87 | 88 | const elmBuildNS = (tag, ...contents) => { 89 | const ns = 'http://www.w3.org/2000/svg' 90 | /** @type {Element} */ 91 | const elm = typeof tag === 'string' ? document.createElementNS(ns, tag) : tag 92 | for (const content of contents) { 93 | if (!content || typeof content !== 'object' || (content instanceof Node)) { // eslint-disable-line no-undef 94 | elm.append(content) 95 | } else if (content.length > 0) { 96 | elm.appendChild(elmBuildNS(...content)) 97 | } else if (content.style) { 98 | Object.assign(elm.style, content.style) 99 | } else if (content.classList) { 100 | elm.classList.add(...content.classList) 101 | } else if (content.attr) { 102 | for (const [attr, val] of Object.entries(content.attr)) elm.setAttributeNS(null, attr, val) 103 | } else if (content.attrNS) { 104 | for (const [attr, val] of Object.entries(content.attrNS)) elm.setAttributeNS(ns, attr, val) 105 | } else { 106 | Object.assign(elm, content) 107 | } 108 | } 109 | return elm 110 | } 111 | 112 | function addCss () { 113 | let style = document.querySelector('style#youtube_genius_lyrics_style') 114 | if (style === null) { 115 | style = document.createElement('style') 116 | style.id = 'youtube_genius_lyrics_style' 117 | style.textContent = ` 118 | body #mycaptchahint897454 { 119 | z-index: 2070; 120 | } 121 | 122 | body #myoverlay7658438 { 123 | z-index: 2050; 124 | } 125 | 126 | body #myconfigwin39457845 { 127 | z-index: 2060; 128 | } 129 | 130 | html { 131 | /* allow modification from external */ 132 | --ygl-container-right: var(--ytd-margin-6x, 4px); 133 | --ygl-container-default-padding: 2px 6px; 134 | --ygl-spinner-color: rgb(255, 255, 100); 135 | } 136 | 137 | #lyricscontainer { 138 | box-sizing: border-box; 139 | position: fixed; 140 | right: 0; 141 | margin: 0px; 142 | padding: 0px; 143 | background-color: white; 144 | z-index: 2001; 145 | font-size: 1.4rem; 146 | border: 0; 147 | border-radius: 0; 148 | 149 | background: var(--ytd-searchbox-background); 150 | color: var(--ytd-searchbox-text-color); 151 | border: 1px solid var(--ytd-searchbox-legacy-border-color); 152 | padding: var(--ygl-container-default-padding); 153 | /* overrided by found/loading */ 154 | line-height: 100%; 155 | 156 | width: calc(var(--ygl-container-width, 324px) - var(--ytd-margin-6x, 24px) + 7px); 157 | right: calc(var(--ygl-container-right) - 1px); 158 | } 159 | 160 | #lyricsiframe { 161 | opacity: 0.1; 162 | transition: opacity 2s; 163 | margin: 0; 164 | padding: 0; 165 | } 166 | 167 | .lyricsnavbar { 168 | font-size: 0.83em; 169 | text-align: right; 170 | padding-right: 10px; 171 | background-color: #fafafa; 172 | background: transparent; 173 | color: inherit; 174 | display: flex; 175 | user-select: none; 176 | flex-direction: row; 177 | justify-content: end; 178 | align-items: center; 179 | align-items: stretch; 180 | } 181 | 182 | .lyricsnavbar span { 183 | color: var(--yt-live-chat-primary-text-color); 184 | text-decoration: none; 185 | transition: color 400ms; 186 | } 187 | 188 | .lyricsnavbar span:hover { 189 | color: var(--yt-live-chat-toast-action-color); 190 | text-decoration: none; 191 | } 192 | 193 | body .loadingspinner { 194 | /* override .loadingspinner */ 195 | color: currentColor; 196 | font-size: 1em; 197 | line-height: 2.5em; 198 | --ygl-spinner-border-color: var(--yt-live-chat-secondary-text-color, #181818); 199 | border-color: var(--ygl-spinner-color) var(--ygl-spinner-border-color) var(--ygl-spinner-border-color) var(--ygl-spinner-border-color); 200 | } 201 | 202 | .loadingspinnerholder { 203 | z-index: 2050; 204 | background-color: inherit; 205 | cursor: progress; 206 | } 207 | 208 | .lorem br { 209 | height: 0px; 210 | line-height: 0; 211 | font-size: 0; 212 | padding: 0; 213 | margin: 0; 214 | } 215 | 216 | .lorem { 217 | --ygl-lorem-gray: var(--yt-live-chat-disabled-icon-button-color); 218 | padding: 10px 0px 0px 15px; 219 | font-size: 1.4rem; 220 | line-height: 2.2rem; 221 | letter-spacing: 0.3rem; 222 | user-select: none !important; 223 | pointer-events: none !important; 224 | width: 100%; 225 | } 226 | 227 | /* this is only supported in modern browsers */ 228 | @property --num { 229 | syntax: ''; 230 | initial-value: 0; 231 | inherits: false; 232 | } 233 | 234 | @keyframes loadingLorem { 235 | 0% { 236 | --num: 0; 237 | } 238 | 239 | 99% { 240 | --num: 8; 241 | } 242 | 243 | 100% { 244 | --num: 0; 245 | } 246 | } 247 | 248 | .lorem-scroll { 249 | --num: 0; 250 | animation: loadingLorem 4s ease infinite; 251 | margin-top: calc(-13rem - 2rem*var(--num, 0)); 252 | contain: content; 253 | width: 96%; 254 | overflow: hidden; 255 | } 256 | 257 | .lorem .white { 258 | background-color: inherit; 259 | color: white; 260 | user-select: none !important; 261 | } 262 | 263 | .lorem .gray { 264 | background-color: var(--ygl-lorem-gray); 265 | color: transparent; 266 | user-select: none !important; 267 | } 268 | 269 | #showlyricsbutton { 270 | position: fixed; /* youtube's unknown layout bug - the 'absolute' position top would offset upwards by around 80px after the page is changed */ 271 | /* note: youtube layouts are inside ytd-watch-flexy by default; therefore the 'absolute' layout for elements outside ytd-watch-flexy is not guaranteed */ 272 | z-index: 3000; 273 | right: 4px; 274 | cursor: pointer; 275 | border-radius: 50%; 276 | margin: auto; 277 | padding: 0px 1px; 278 | text-align: center; 279 | font-size: 15px; 280 | line-height: 14px; 281 | 282 | background: #ffff64; 283 | color: #000a; 284 | padding: 9px; 285 | display: flex; 286 | align-content: center; 287 | align-items: center; 288 | justify-content: center; 289 | contain: strict; 290 | opacity: 0.7; 291 | transition: opacity 50ms; 292 | 293 | /* 294 | --ytd-masthead-height 295 | --ytd-toolbar-height 296 | --ytd-watch-flexy-masthead-height 297 | */ 298 | top: var(--ytd-toolbar-height, var(--ytd-masthead-height, var(--ytd-watch-flexy-masthead-height, 56px))); 299 | 300 | } 301 | 302 | #showlyricsbutton.hide-during-ytlive { 303 | display: none; 304 | } 305 | 306 | #showlyricsbutton:hover { 307 | opacity: 1.0; 308 | } 309 | 310 | /* :fullscreen shall be sufficient for modern browsers */ 311 | /* see more at https://caniuse.com/mdn-css_selectors_fullscreen */ 312 | /* just except opera ? */ 313 | 314 | :fullscreen #showlyricsbutton, :fullscreen #lyricscontainer { 315 | display: none; 316 | } 317 | 318 | :-moz-full-screen #showlyricsbutton { 319 | display: none; 320 | } 321 | 322 | :-webkit-full-screen #showlyricsbutton { 323 | display: none; 324 | } 325 | 326 | #showlyricsbutton::before { 327 | color: inherit; 328 | content: 'G'; 329 | position: absolute; 330 | display: block; 331 | pointer-events: none; 332 | user-select: none; 333 | touch-action: none; 334 | } 335 | 336 | .youtube-genius-lyrics-search-container { 337 | border: 1px solid black; 338 | border-radius: 3px; 339 | --ygl-lyricscontainer-padding: 0px 10px; 340 | } 341 | 342 | span.youtube-genius-lyrics-results-line-separator, 343 | span.youtube-genius-lyrics-found-separator { 344 | padding: 0px 3px; 345 | } 346 | 347 | .youtube-genius-lyrics-results-container { 348 | border: 1px solid black; 349 | border-radius: 3px; 350 | } 351 | 352 | ol.youtube-genius-lyrics-results-tracklist { 353 | list-style: none; 354 | width: 99%; 355 | font-size: 1.15em; 356 | } 357 | 358 | li.youtube-genius-lyrics-results-li { 359 | cursor: pointer; 360 | transition: background-color 0.2s; 361 | margin: 2px; 362 | border-radius: 3px; 363 | padding: 8px 6px; 364 | } 365 | 366 | span.youtube-genius-lyrics-results-hide-btn, 367 | span.youtube-genius-lyrics-results-back-btn, 368 | span.youtube-genius-lyrics-found-hide-btn, 369 | span.youtube-genius-lyrics-found-back-btn { 370 | cursor: pointer; 371 | } 372 | 373 | li.youtube-genius-lyrics-results-li div.onhover { 374 | display: none; 375 | margin-top: -0.25em; 376 | } 377 | 378 | li.youtube-genius-lyrics-results-li div.onout { 379 | display: block; 380 | } 381 | 382 | li.youtube-genius-lyrics-results-li:hover div.onhover { 383 | display: block; 384 | } 385 | 386 | li.youtube-genius-lyrics-results-li:hover div.onout { 387 | display: none; 388 | } 389 | 390 | ol.youtube-genius-lyrics-results-tracklist { 391 | font-size: var(--ytd-link-font-size); 392 | } 393 | 394 | li.youtube-genius-lyrics-results-li { 395 | 396 | /* --tyt-tracklist-li-background: var(--yt-live-chat-slider-container-color); */ 397 | 398 | --tyt-tracklist-li-background: var(--ytd-searchbox-legacy-button-color); 399 | 400 | background-color: var(--tyt-tracklist-li-background); 401 | color: var(--ytd-searchbox-text-color); 402 | border: 1px solid var(--ytd-searchbox-legacy-border-color); 403 | list-style: none; 404 | 405 | /* 406 | color: var(--yt-live-chat-secondary-text-color); 407 | 408 | --tyt-tracklist-li-background: var(--ytd-searchbox-legacy-button-color); 409 | --tyt-tracklist-li-background: var(--yt-spec-commerce-tonal-hover); 410 | 411 | */ 412 | 413 | opacity: 0.9; 414 | } 415 | 416 | li.youtube-genius-lyrics-results-li:hover { 417 | 418 | --tyt-tracklist-li-background: var(--yt-live-chat-button-dark-background-color); 419 | /* --tyt-tracklist-li-background: var(--yt-live-chat-slider-active-color); */ 420 | border: 1px solid var(--ytd-searchbox-legacy-button-hover-border-color); 421 | 422 | opacity: 1.0; 423 | } 424 | 425 | li.youtube-genius-lyrics-results-li.lyrics-minor-result { 426 | font-size: 80%; 427 | opacity: 0.6; 428 | 429 | } 430 | 431 | li.youtube-genius-lyrics-results-li.lyrics-minor-result:hover { 432 | opacity: 0.7; 433 | } 434 | 435 | li.youtube-genius-lyrics-results-li * { 436 | pointer-events: none; 437 | } 438 | 439 | li.youtube-genius-lyrics-results-li div.onhover span { 440 | color: black; 441 | font-size: 2.0em; 442 | } 443 | 444 | li.youtube-genius-lyrics-results-li div.onout span { 445 | font-size: 1.5em; 446 | } 447 | 448 | 449 | body #lyricscontainer ol.tracklist li .onhover, 450 | body #lyricscontainer ol.tracklist li .onout { 451 | display: none; 452 | 453 | } 454 | 455 | 456 | body #lyricscontainer>ol.tracklist { 457 | 458 | max-width: 480px; 459 | min-width: 280px; 460 | width: auto; 461 | } 462 | 463 | 464 | span.youtube-genius-lyrics-found-config-btn { 465 | cursor: pointer; 466 | } 467 | 468 | span.youtube-genius-lyrics-found-wonglyrics-btn { 469 | cursor: pointer; 470 | } 471 | 472 | 473 | html { 474 | --ygl-theater-player-max-width: '--NULL--'; 475 | --ygl-theater-player-float: '--NULL--'; 476 | } 477 | 478 | html[youtube-genius-lyrics-container="found"] ytd-watch-flexy[theater], 479 | html[youtube-genius-lyrics-container="loading"] ytd-watch-flexy[theater] { 480 | --ygl-theater-player-max-width: 50%; 481 | --ygl-theater-player-float: right; 482 | } 483 | 484 | ytd-watch-flexy[theater] #movie_player .ytp-left-controls { 485 | max-width: var(--ygl-theater-player-max-width); 486 | } 487 | 488 | ytd-watch-flexy[theater] #movie_player .ytp-right-controls { 489 | float: var(--ygl-theater-player-float); 490 | } 491 | 492 | html[youtube-genius-lyrics-container="found"] ytd-watch-flexy[theater] #movie_player video[src], 493 | html[youtube-genius-lyrics-container="loading"] ytd-watch-flexy[theater] #movie_player video[src] { 494 | left: 0 !important; 495 | } 496 | 497 | html[youtube-genius-lyrics-container] #showlyricsbutton { 498 | display: none; 499 | } 500 | 501 | 502 | .youtube-genius-lyrics-search-input { 503 | -webkit-appearance: none; 504 | appearance: none; 505 | -webkit-font-smoothing: antialiased; 506 | background-color: transparent; 507 | border: none; 508 | box-shadow: none; 509 | color: inherit; 510 | font-family: Roboto, Noto, sans-serif; 511 | text-align: inherit; 512 | border: 1px solid currentColor; 513 | box-sizing: border-box; 514 | padding: 1px 0; 515 | margin: 0; 516 | outline-offset: 0px; 517 | outline: none; 518 | padding: 1px 6px; 519 | font-size: 80%; 520 | background-color: var(--yt-emoji-picker-search-background-color); 521 | border-color: currentColor; 522 | margin: 0 6px 0 6px; 523 | flex: 1; 524 | } 525 | 526 | [dark] .youtube-genius-lyrics-search-input { 527 | border-color: transparent; 528 | } 529 | 530 | .youtube-genius-lyrics-search-input:not(:focus)::placeholder { 531 | border-color: var(--yt-emoji-picker-search-placeholder-color); 532 | color: var(--yt-emoji-picker-search-placeholder-color); 533 | } 534 | 535 | .youtube-genius-lyrics-search-input.placeholder-lastfetch:not(:focus)::placeholder, 536 | .youtube-genius-lyrics-search-input.placeholder-lastfetch:focus::placeholder{ 537 | color: var(--yt-spec-text-secondary); 538 | font-weight: bold; 539 | } 540 | 541 | .youtube-genius-lyrics-search-input:focus, 542 | .youtube-genius-lyrics-search-input:active { 543 | border-color: var(--paper-checkbox-checked-color); 544 | } 545 | 546 | span.youtube-genius-lyrics-search-search-btn { 547 | cursor: pointer; 548 | vertical-align: middle; 549 | align-self: center; 550 | display: inline-flex; 551 | margin-left: 0; 552 | margin-right: 8px; 553 | } 554 | 555 | 556 | 557 | .youtube-genius-lyrics-search-search-btn:hover { 558 | color: var(--yt-live-chat-toast-action-color); 559 | } 560 | 561 | span.youtube-genius-lyrics-search-search-btn > svg { 562 | fill: currentColor; 563 | pointer-events: none; 564 | touch-action: none; 565 | user-select: none; 566 | } 567 | 568 | @keyframes inputNoResult { 569 | 0% { 570 | transform: translateX(0px); 571 | } 572 | 573 | 25% { 574 | transform: translateX(-6px); 575 | } 576 | 577 | 50% { 578 | transform: translateX(0px); 579 | } 580 | 581 | 75% { 582 | transform: translateX(6px); 583 | } 584 | 585 | 100% { 586 | transform: translateX(6px); 587 | } 588 | } 589 | 590 | .youtube-genius-lyrics-search-input.lyrics-input-noresult { 591 | border-color: red; 592 | opacity: 0.75; 593 | animation: inputNoResult 140ms; 594 | animation-iteration-count: 3; 595 | } 596 | 597 | .lyrics-searching { 598 | /* dont make animation here */ 599 | filter: blur(0.7px); 600 | opacity: 0.85; 601 | pointer-events: none; 602 | } 603 | 604 | 605 | html { 606 | --ygl-lyricsiframe-flex: '--NULL--'; 607 | --ygl-lyricscontainer-bottom: '--NULL--'; 608 | --ygl-lyricscontainer-border-radius: '--NULL--'; 609 | --ygl-lyricscontainer-padding: '--NULL--'; 610 | --ygl-lyricscontainer-display: '--NULL--'; 611 | --ygl-lyricscontainer-flex-direction: '--NULL--'; 612 | --ygl-lyricscontainer-bar-padding: '--NULL--'; 613 | } 614 | 615 | 616 | .youtube-genius-lyrics-loading-container, 617 | .youtube-genius-lyrics-found-container { 618 | --ygl-lyricsiframe-flex: 1; 619 | --ygl-lyricscontainer-bottom: 4px; 620 | /* allow override */ 621 | --ygl-lyricscontainer-border-radius: 0px 0px 8px 8px; 622 | /* allow override */ 623 | --ygl-lyricscontainer-padding: 0px 8px 8px 8px; 624 | /* allow override */ 625 | --ygl-lyricscontainer-display: flex; 626 | --ygl-lyricscontainer-flex-direction: column; 627 | --ygl-lyricscontainer-bar-padding: 4px 6px; 628 | 629 | } 630 | 631 | 632 | .lyricsnavbar { 633 | padding: var(--ygl-lyricscontainer-bar-padding); 634 | } 635 | 636 | body #lyricscontainer { 637 | display: var(--ygl-lyricscontainer-display); 638 | flex-direction: var(--ygl-lyricscontainer-flex-direction); 639 | bottom: var(--ygl-lyricscontainer-bottom); 640 | border-radius: var(--ygl-lyricscontainer-border-radius); 641 | padding: var(--ygl-lyricscontainer-padding); 642 | } 643 | 644 | #lyricsiframe { 645 | flex: var(--ygl-lyricsiframe-flex); 646 | } 647 | 648 | 649 | 650 | #lyricscontainer.youtube-genius-lyrics-loading-container #lyricsiframe { 651 | 652 | position: absolute; 653 | 654 | width: 80%; 655 | height: 80%; 656 | transform: translate(10%, 10%); 657 | 658 | 659 | } 660 | 661 | #lyricscontainer.youtube-genius-lyrics-loading-container .loadingspinnerholder { 662 | 663 | position: relative; 664 | width: auto !important; 665 | top: auto !important; 666 | 667 | display: flex; 668 | flex-direction: column; 669 | 670 | align-content: center; 671 | align-items: center; 672 | justify-content: center; 673 | 674 | overflow: hidden; 675 | contain: content; 676 | } 677 | 678 | 679 | 680 | .youtube-genius-lyrics-search-container { 681 | --ygl-lyricscontainer-display: flex; 682 | --ygl-lyricscontainer-flex-direction: row; 683 | align-items: center; 684 | } 685 | 686 | .youtube-genius-lyrics-results-container { 687 | --ygl-lyricscontainer-padding: 2px 6px 6px 6px; 688 | } 689 | 690 | .youtube-genius-lyrics-search-hide-btn, 691 | .youtube-genius-lyrics-results-back-btn, 692 | .youtube-genius-lyrics-results-hide-btn, 693 | .youtube-genius-lyrics-results-config-btn, 694 | .youtube-genius-lyrics-search-config-btn { 695 | border: 1px solid var(--ytd-searchbox-background); 696 | margin: 3px; 697 | font-size: 0.83em; 698 | color: var(--yt-live-chat-primary-text-color); 699 | text-decoration: none; 700 | transition: color 400ms; 701 | cursor: pointer; 702 | } 703 | 704 | .youtube-genius-lyrics-search-hide-btn:hover, 705 | .youtube-genius-lyrics-results-back-btn:hover, 706 | .youtube-genius-lyrics-results-hide-btn:hover, 707 | .youtube-genius-lyrics-results-config-btn:hover, 708 | .youtube-genius-lyrics-search-config-btn:hover { 709 | color: var(--yt-live-chat-toast-action-color); 710 | text-decoration: none; 711 | } 712 | 713 | .youtube-genius-lyrics-results-line-separator { 714 | font-size: 0.83em; 715 | color: var(--yt-live-chat-primary-text-color); 716 | } 717 | 718 | .youtube-genius-lyrics-search-label { 719 | font-family: cursive; 720 | padding: 0px 6px; 721 | color: var(--yt-live-chat-primary-text-color); 722 | font-size: 80%; 723 | } 724 | 725 | [dark] .youtube-genius-lyrics-search-label { 726 | color: var(--yt-live-chat-author-chip-owner-background-color); 727 | } 728 | 729 | .youtube-genius-lyrics-tracklist-info-container{ 730 | display: flex; 731 | column-gap: 6px; 732 | flex-direction: row; 733 | flex-wrap: nowrap; 734 | } 735 | 736 | .youtube-genius-lyrics-tracklist-info-primary{ 737 | flex:1; 738 | } 739 | 740 | .youtube-genius-lyrics-tracklist-info-secondary{ 741 | text-transform: uppercase; 742 | font-style: italic; 743 | } 744 | 745 | svg.svg-genius-pageviews { 746 | fill: currentColor; 747 | width: 10px; 748 | margin-right: 2px; 749 | } 750 | 751 | ` 752 | document.head.appendChild(style) 753 | } 754 | } 755 | 756 | const { requestAnimationFrame, setTimeout, setInterval, clearTimeout, clearInterval } = (() => { // eslint-disable-line no-unused-vars 757 | let win = typeof unsafeWindow !== 'undefined' ? unsafeWindow : window // eslint-disable-line no-undef 758 | let removeIframeFn = null 759 | try { 760 | const frameId = 'vanillajs-iframe-v1' 761 | let frame = document.getElementById(frameId) 762 | if (!frame) { 763 | frame = document.createElement('iframe') 764 | frame.id = frameId 765 | const blobURL = typeof webkitCancelAnimationFrame === 'function' ? (frame.src = URL.createObjectURL(new Blob([], { type: 'text/html' }))) : null // avoid Brave Crash 766 | frame.sandbox = 'allow-same-origin' // script cannot be run inside iframe but API can be obtained from iframe 767 | let n = document.createElement('noscript') // wrap into NOSCRPIT to avoid reflow (layouting) 768 | n.appendChild(frame) 769 | const root = document.documentElement 770 | if (root) { 771 | root.appendChild(n) 772 | if (blobURL) Promise.resolve().then(() => URL.revokeObjectURL(blobURL)) 773 | removeIframeFn = (setTimeout) => { 774 | const removeIframeOnDocumentReady = (e) => { 775 | e && win.removeEventListener('DOMContentLoaded', removeIframeOnDocumentReady, false) 776 | e = n 777 | n = win = removeIframeFn = 0 778 | setTimeout ? setTimeout(() => e.remove(), 200) : e.remove() 779 | } 780 | if (!setTimeout || document.readyState !== 'loading') { 781 | removeIframeOnDocumentReady() 782 | } else { 783 | win.addEventListener('DOMContentLoaded', removeIframeOnDocumentReady, false) 784 | } 785 | } 786 | } 787 | } 788 | 789 | const fc = frame ? frame.contentWindow : null 790 | if (fc) { 791 | try { 792 | const { requestAnimationFrame, setTimeout, setInterval, clearTimeout, clearInterval } = fc 793 | const res = { requestAnimationFrame, setTimeout, setInterval, clearTimeout, clearInterval } 794 | for (const k in res) res[k] = res[k].bind(win) // necessary 795 | if (removeIframeFn) Promise.resolve(res.setTimeout).then(removeIframeFn) 796 | return res 797 | } catch (e) { 798 | if (removeIframeFn) removeIframeFn() 799 | } 800 | } 801 | } catch (e) { 802 | console.warn(e) 803 | } 804 | 805 | // since the mechanism does not utilize async/await, use the old method as fallback. 806 | function isFakeWindow () { 807 | // window is not window in Spotify Web App 808 | return (window instanceof window.constructor) === false 809 | } 810 | /** 811 | * getTrueWindow 812 | * @returns {Window} 813 | */ 814 | function getTrueWindow () { 815 | // this can bypass Spotify's window Proxy Object and obtain the original window object 816 | try { 817 | return new Function('return window')() // eslint-disable-line no-new-func 818 | } catch (e) { 819 | console.warn('the actual window object cannot be obtained.', e) // e.g. YouTube Music 820 | return window // fallback 821 | } 822 | } 823 | 824 | let trueWindow = isFakeWindow() ? getTrueWindow() : win 825 | const { requestAnimationFrame, setTimeout, setInterval, clearTimeout, clearInterval } = trueWindow 826 | const res = { requestAnimationFrame, setTimeout, setInterval, clearTimeout, clearInterval } 827 | for (const k in res) res[k] = res[k].bind(trueWindow) // necessary 828 | trueWindow = null 829 | 830 | if (removeIframeFn) Promise.resolve(res.setTimeout).then(removeIframeFn) 831 | return res 832 | })() 833 | 834 | function appendElements (target, elements) { 835 | if (typeof target.append === 'function') { 836 | target.append(...elements) 837 | } else { 838 | for (const element of elements) { 839 | target.appendChild(element) 840 | } 841 | } 842 | } 843 | 844 | const removeElements = (typeof window.DocumentFragment.prototype.append === 'function') 845 | ? function (elements) { 846 | document.createDocumentFragment().append(...elements) 847 | } 848 | : function (elements) { 849 | for (const element of elements) { 850 | element.remove() 851 | } 852 | } 853 | 854 | function getMastheadHeight () { 855 | // can be replaced by youtube css custom properties 856 | const masthead = document.querySelector('ytd-masthead#masthead') 857 | return masthead.getBoundingClientRect().height 858 | } 859 | 860 | function calcContainerWidthTop () { 861 | let w 862 | const upnext = document.querySelector('#secondary #secondary-inner') || document.getElementById('upnext') 863 | const playlist = document.querySelector('ytd-playlist-panel-renderer#playlist') 864 | const video = document.querySelector('ytd-watch-flexy div#primary video') 865 | 866 | if (upnext && upnext.getBoundingClientRect().left > 0) { 867 | w = window.innerWidth - upnext.getBoundingClientRect().left - 5 868 | } else if (playlist && playlist.getBoundingClientRect().left > 0) { 869 | w = window.innerWidth - playlist.getBoundingClientRect().left - 5 870 | } else if (video) { 871 | w = window.innerWidth - 1.02 * video.getBoundingClientRect().right 872 | } else { 873 | w = window.innerWidth * 0.45 874 | } 875 | w = Math.min(window.innerWidth * 0.75, w) 876 | 877 | const top = getMastheadHeight() 878 | const isTheatherView = !!document.querySelector('ytd-watch-flexy[theater]') 879 | if (isTheatherView) { 880 | return { 881 | top, 882 | width: parseInt(0.3 * document.querySelector('#columns').clientWidth), 883 | isTheatherView 884 | } 885 | } else { 886 | return { 887 | top, 888 | width: w, 889 | isTheatherView 890 | } 891 | } 892 | } 893 | 894 | function setFrameDimensions (container, iframe, bar) { // eslint-disable-line no-unused-vars 895 | // if (!container || !iframe || !bar) { 896 | // console.warn('elements not found in setFrameDimensions()') 897 | // return 898 | // } 899 | // const bar = container.querySelector('.lyricsnavbar') 900 | // const width = iframe.style.width = container.clientWidth - 1 + 'px' 901 | // const height = iframe.style.height = window.innerHeight - bar.clientHeight - getMastheadHeight() + 'px' 902 | /* 903 | iframe.style.width = container.clientWidth - 1 + 'px' 904 | iframe.style.height = window.innerHeight - bar.clientHeight - getMastheadHeight() + 'px' 905 | 906 | if (genius.option.themeKey === 'spotify') { 907 | iframe.style.backgroundColor = '#181818' 908 | bar.style.backgroundColor = '#181818' 909 | } else { 910 | iframe.style.backgroundColor = '' 911 | } 912 | */ 913 | 914 | // return [width, height] 915 | } 916 | 917 | let lastResizeDT = 0 918 | function onResize () { 919 | const tdt = Date.now() 920 | lastResizeDT = tdt 921 | setTimeout(function () { 922 | if (tdt === lastResizeDT) { 923 | resize() 924 | } 925 | }, 600) 926 | } 927 | 928 | function resize () { 929 | const container = document.getElementById('lyricscontainer') 930 | 931 | if (!container) { 932 | return 933 | } 934 | 935 | const { top, width } = calcContainerWidthTop() 936 | 937 | // container.style.top = `${top}px` 938 | container.style.setProperty('--ygl-container-top', `${top}px`) 939 | container.style.top = 'var(--ytd-toolbar-height, var(--ytd-masthead-height, var(--ytd-watch-flexy-masthead-height, var(--ygl-container-top))))' // compatible with YouTube Live Borderless 940 | container.style.setProperty('--ygl-container-width', `${width}px`) 941 | 942 | // const iframe = document.getElementById('lyricsiframe') 943 | // if (iframe) { 944 | // const bar = container.querySelector('.lyricsnavbar') 945 | // if (bar) { 946 | // setFrameDimensions(container, iframe, bar) 947 | // } 948 | // } 949 | } 950 | 951 | function getCleanLyricsContainer () { 952 | let container = null 953 | 954 | const { top, width } = calcContainerWidthTop() 955 | 956 | if (!document.getElementById('lyricscontainer')) { 957 | container = document.createElement('div') 958 | container.id = 'lyricscontainer' 959 | document.body.appendChild(container) 960 | } else { 961 | container = document.getElementById('lyricscontainer') 962 | container.textContent = '' 963 | container.className = '' 964 | container.style = '' 965 | } 966 | 967 | // container.style.top = `${top}px` 968 | container.style.setProperty('--ygl-container-top', `${top}px`) 969 | container.style.top = 'var(--ytd-toolbar-height, var(--ytd-masthead-height, var(--ytd-watch-flexy-masthead-height, var(--ygl-container-top))))' // compatible with YouTube Live Borderless 970 | container.style.setProperty('--ygl-container-width', `${width}px`) 971 | 972 | document.body.appendChild(container) 973 | 974 | const result = document.getElementById('lyricscontainer') 975 | if (result !== container) { 976 | console.warn(SCRIPT_NAME + ' getCleanLyricsContainer() Could not insert the element correctly') 977 | } 978 | 979 | return result 980 | } 981 | 982 | function hideLyrics () { 983 | if (document.querySelector('.loadingspinnerholder') !== null) { 984 | genius.f.cancelLoading() 985 | } 986 | const elementsToBeRemoved = [...document.querySelectorAll('.loadingspinnerholder')] 987 | const lyricscontainer = document.getElementById('lyricscontainer') 988 | if (lyricscontainer) { 989 | elementsToBeRemoved.push(lyricscontainer) 990 | } 991 | document.documentElement.removeAttribute('youtube-genius-lyrics-container') 992 | const isHiding = elementsToBeRemoved.length > 0 993 | removeElements(elementsToBeRemoved) 994 | addLyricsButton() 995 | return isHiding 996 | } 997 | 998 | async function showLyricsButtonClicked () { 999 | removeLyricsButton() 1000 | genius.option.autoShow = true // Temporarily enable showing lyrics automatically on song change 1001 | addLyrics(true) 1002 | } 1003 | 1004 | function addLyricsButton () { 1005 | if (disableShowLyricsButton === true) return 1006 | if (document.getElementById('showlyricsbutton')) { 1007 | return 1008 | } 1009 | // const top = getMastheadHeight() 1010 | const showlyricsbutton = document.createElement('div') 1011 | showlyricsbutton.id = 'showlyricsbutton' 1012 | if (isYouTubeLive) showlyricsbutton.classList.add('hide-during-ytlive') 1013 | showlyricsbutton.setAttribute('title', 'Load lyrics from genius.com') 1014 | showlyricsbutton.addEventListener('click', showLyricsButtonClicked, false) 1015 | document.body.appendChild(showlyricsbutton) 1016 | } 1017 | 1018 | function removeLyricsButton () { 1019 | let showlyricsbutton = document.getElementById('showlyricsbutton') 1020 | if (showlyricsbutton !== null) { 1021 | try { 1022 | showlyricsbutton.remove() 1023 | } catch (e) { 1024 | // do nothing 1025 | } 1026 | } 1027 | showlyricsbutton = null 1028 | } 1029 | 1030 | let lastVideoId = null 1031 | let lastForceVideoId = null 1032 | let hitMaps = null 1033 | 1034 | function obtainDataCarouselLockups (ep) { 1035 | if (!ep) { 1036 | return null 1037 | } 1038 | let m = null 1039 | try { 1040 | m = ep.engagementPanelSectionListRenderer.content.structuredDescriptionContentRenderer.items[2].videoDescriptionMusicSectionRenderer.carouselLockups 1041 | } catch (e) { 1042 | m = null 1043 | } 1044 | return m 1045 | } 1046 | 1047 | function getSimpleText (defaultMetadata) { 1048 | if (!defaultMetadata) { 1049 | return null 1050 | } 1051 | if (typeof defaultMetadata.simpleText === 'string') { 1052 | return defaultMetadata.simpleText 1053 | } 1054 | if (defaultMetadata.runs) { 1055 | const texts = defaultMetadata.runs.map(entry => entry.text) 1056 | if (texts.length === 1 && typeof texts[0] === 'string') { 1057 | return texts[0] 1058 | } 1059 | } 1060 | return null 1061 | } 1062 | 1063 | function simpleTextFixup (text) { 1064 | return text.replace(/だ/g, 'だ') 1065 | } 1066 | 1067 | function titleFix (text) { 1068 | return text.replace(/\(([A-Za-z][a-z]+) ([Vv]ersion|[Vv]er\.?)\)/g, '($1)') // Genius Lyrics title use Ver. instead of Version; e.g. English Version 1069 | } 1070 | 1071 | function removeEmojis (str) { 1072 | return str.replace(/[\u{1F600}-\u{1F64F}\u{1F300}-\u{1F5FF}\u{1F680}-\u{1F6FF}\u{1F700}-\u{1F77F}\u{1F780}-\u{1F7FF}\u{1F800}-\u{1F8FF}\u{1F900}-\u{1F9FF}\u{1FA00}-\u{1FA6F}\u{1FA70}-\u{1FAFF}\u{2600}-\u{26FF}\u{2700}-\u{27BF}\u{2300}-\u{23FF}\u{2B50}\u{1F004}\u{1F0CF}\u{E0020}-\u{E007F}\u{FE0F}]/gu, '') // eslint-disable-line no-misleading-character-class 1073 | } 1074 | 1075 | function getMusicTitleAndAuthor (pData) { 1076 | const response = pData.response 1077 | const engagementPanels = response.engagementPanels 1078 | let carouselLockups = null 1079 | for (const ep of engagementPanels) { 1080 | const m = obtainDataCarouselLockups(ep) 1081 | if (m !== null) { 1082 | carouselLockups = m 1083 | break 1084 | } 1085 | } 1086 | 1087 | if (carouselLockups && carouselLockups.length === 1) { 1088 | let a1 = null 1089 | let a2 = null 1090 | try { 1091 | a1 = carouselLockups[0].carouselLockupRenderer.infoRows[0].infoRowRenderer.defaultMetadata 1092 | a2 = carouselLockups[0].carouselLockupRenderer.infoRows[1].infoRowRenderer.defaultMetadata 1093 | } catch (e) { } 1094 | a1 = getSimpleText(a1) 1095 | a2 = getSimpleText(a2) 1096 | 1097 | if (a1 && a2 && typeof a1 === 'string' && typeof a2 === 'string') { 1098 | let title = null 1099 | try { 1100 | title = pData.playerResponse.videoDetails.title 1101 | } catch (e) { } 1102 | if (title && typeof title === 'string') { 1103 | a1 = removeEmojis(a1).trim().replace(/\s+/g, ' ') 1104 | a1 = titleFix(simpleTextFixup(a1)) 1105 | a2 = simpleTextFixup(a2) 1106 | title = removeEmojis(title).trim().replace(/\s+/g, ' ') 1107 | title = simpleTextFixup(title) 1108 | const newValue = `${a2} ${a1}` 1109 | return { 1110 | title, 1111 | singer: a2, 1112 | song: a1, 1113 | text: newValue 1114 | } 1115 | } 1116 | } 1117 | } else if (carouselLockups && carouselLockups.length > 1) { 1118 | setDisableShowLyricsButton(true) // one video with multiple musics 1119 | } 1120 | return null 1121 | } 1122 | 1123 | function getYoutubeMainVideo () { 1124 | let video = document.querySelector('#ytd-player #movie_player video[src]') 1125 | if (video !== null) { 1126 | return video 1127 | } 1128 | video = document.querySelector('video[src]') 1129 | if (video !== null) { 1130 | return video 1131 | } 1132 | return null 1133 | } 1134 | 1135 | function isYoutubeVideoPlaying () { 1136 | const videoPlayerContainer = document.querySelector('#ytd-player #movie_player') 1137 | let video = null 1138 | if (videoPlayerContainer) { 1139 | const isPaused = videoPlayerContainer.classList.contains('paused-mode') 1140 | if (isPaused) { 1141 | return false 1142 | } 1143 | const isPlaying = videoPlayerContainer.classList.contains('playing-mode') 1144 | if (isPlaying) { 1145 | return true 1146 | } 1147 | video = window.HTMLElement.prototype.querySelector.call(videoPlayerContainer, 'video[src]') 1148 | if (video !== null) { 1149 | const paused = video.paused 1150 | if (paused === true) { 1151 | return false 1152 | } 1153 | if (paused === false) { 1154 | return true 1155 | } 1156 | } 1157 | } 1158 | if (video === null) { 1159 | video = document.querySelector('video[src]') 1160 | } 1161 | if (video !== null) { 1162 | const paused = video.paused 1163 | if (paused === true) { 1164 | return false 1165 | } 1166 | if (paused === false) { 1167 | return true 1168 | } 1169 | } 1170 | } 1171 | 1172 | function keywordProcess (title, keywords, kHash) { 1173 | const upperTitle = title.toUpperCase() 1174 | return keywords.filter(keywordObj => { 1175 | if (typeof keywordObj === 'object') { 1176 | const keyword = keywordObj.keyword 1177 | return title.includes(keyword) 1178 | } 1179 | const keyword = keywordObj 1180 | const upperKeyword = keyword.toUpperCase() 1181 | if (!upperTitle.includes(upperKeyword)) return false 1182 | let type = kHash.get(keyword) 1183 | if (!type) { 1184 | type = 1 1185 | if (/^[a-zA-Z]+$/.test(keyword)) { 1186 | type = 3 1187 | let ignoreCase = false 1188 | if (keyword.length > 1) { 1189 | if ((keyword === keyword.toLowerCase() || keyword === keyword.toUpperCase())) ignoreCase = true 1190 | else if ((keyword === keyword.charAt(0).toUpperCase() + keyword.substring(1).toLowerCase())) ignoreCase = true 1191 | } 1192 | if (ignoreCase) type = 7 1193 | } 1194 | kHash.set(keyword, type) 1195 | } 1196 | if (type === 1) { 1197 | return title.includes(keyword) 1198 | } else if (type === 3) { 1199 | return (new RegExp(`\\b${keyword}\\b`)).test(title) 1200 | } else if (type === 7) { 1201 | return (new RegExp(`\\b${keyword}\\b`, 'i')).test(title) 1202 | } 1203 | return false 1204 | }) 1205 | } 1206 | 1207 | function makeKeyWords (keywords, songTitle) { 1208 | keywords = [...keywords] 1209 | songTitle.replace(/\[([^[\]]+)\]/g, (m, a) => { 1210 | if (a !== a.trim()) return 1211 | keywords.push(a) 1212 | }) 1213 | keywords.sort((a, b) => a.length - b.length) 1214 | let skipNexts = new Set() 1215 | let newKeyWords = [] 1216 | const upperSongTitle = songTitle.toUpperCase() 1217 | for (let keyword of keywords) { 1218 | if (skipNexts.has(keyword)) continue 1219 | keyword = keyword.replace(/[\t\r\n]+/g, ' ') 1220 | const upperKeyWord = keyword.toUpperCase() 1221 | const j = upperSongTitle.indexOf(upperKeyWord) 1222 | if (j < 0) continue 1223 | if (upperKeyWord === 'MV' || upperKeyWord === 'PV' || upperKeyWord === 'SONG' || upperKeyWord === 'MUSIC') continue 1224 | keyword = songTitle.substring(j, j + keyword.length) 1225 | const r = { keyword, upperKeyWord, splitLen: songTitle.split(keyword).length, isBracketed: false, foundAt: j } 1226 | if (j >= 1) { 1227 | r.isBracketed = songTitle.charAt(j - 1) === '[' && songTitle.charAt(j + keyword.length) === ']' 1228 | } 1229 | skipNexts.add(keyword) 1230 | newKeyWords.push(r) 1231 | } 1232 | skipNexts.clear() 1233 | skipNexts = null 1234 | let isSkipped = false 1235 | for (const keyword1 of newKeyWords) { 1236 | for (const keyword2 of newKeyWords) { 1237 | if (keyword1.keyword.length > keyword2.keyword.length) { 1238 | if (keyword1.splitLen !== keyword2.splitLen) continue 1239 | if (keyword1.upperKeyWord.includes(keyword2.upperKeyWord)) { 1240 | isSkipped = true 1241 | keyword2.skip = true 1242 | } 1243 | } 1244 | } 1245 | } 1246 | if (isSkipped) newKeyWords = newKeyWords.filter(entry => !entry.skip) 1247 | newKeyWords.sort((a, b) => a.foundAt - b.foundAt) 1248 | return newKeyWords 1249 | } 1250 | 1251 | function repeatReplace (text, searchValue, substring, count) { 1252 | while (count > 0) { 1253 | const text2 = text.replace(searchValue, substring) 1254 | if (text2 === text) return text 1255 | text = text2 1256 | count-- 1257 | } 1258 | return text 1259 | } 1260 | 1261 | async function traditionalYtdDescriptionInfo (videoTitle, videoDetails) { 1262 | let songArtists 1263 | let songTitle = videoTitle 1264 | 1265 | // song title text processing 1266 | songTitle = removeEmojis(songTitle) 1267 | songTitle = songTitle 1268 | .replace(/[\u180E\u200B-\u200D\u2060\uFEFF]+/g, '') // zero-spacing 1269 | .replace(/[\s\u0009-\u000D\u0020\u0085\u00A0\u1680\u2000-\u200A\u2028-\u2029\u202F\u205F\u3000\u00B7\u237D\u2420\u2422\u2423]+/g, ' ') /* spacing */ // eslint-disable-line no-control-regex 1270 | // .replace(/[\uFF01-\uFF0F\u0021-\u002F\u003A-\u0040\u005B-\u0060\u007B-\u007E\u3000\u3001-\u303F\u2000-\u206F]+/g, ' ') // Symbols and Punctuation 1271 | .replace(/│/g, '|') 1272 | .replace(/【([^【】]+)】/g, '[$1]') 1273 | .replace(/\(([^()]+)\)/g, '[$1]') 1274 | .replace(/『([^『』]+)』/g, '[$1]') 1275 | .replace(/「([^「」]+)」/g, '[$1]') 1276 | .replace(/\[(MV|PV)\]/g, '') 1277 | 1278 | const keywords = (videoDetails || 0).keywords 1279 | 1280 | let wSongTitle = null 1281 | if (videoDetails && keywords && keywords.length > 2) { 1282 | let variants = new Set() 1283 | variants.add(songTitle.trim()) 1284 | for (const s of songTitle.split('/')) { 1285 | variants.add(s.trim()) 1286 | } 1287 | for (const s of songTitle.split('|')) { 1288 | // 『チェンソーマン』第9話ノンクレジットエンディング / CHAINSAW MAN #9 Ending│Aimer「Deep down」 1289 | variants.add(s.trim()) 1290 | } 1291 | variants = [...variants.keys()] 1292 | let variantsX = new Map() 1293 | let kHash = new Map() 1294 | const mainwords = keywordProcess(songTitle, keywords, kHash) 1295 | kHash.clear() 1296 | kHash = null 1297 | if (mainwords.length > 2) { 1298 | const vKeywords = makeKeyWords(mainwords, songTitle) 1299 | console.log(vKeywords) 1300 | await Promise.all(variants.map(variant => { 1301 | return new Promise(resolve => { 1302 | const mainwords = keywordProcess(variant, vKeywords, null) 1303 | let kMatch = 0 1304 | let kBracket = 0 1305 | for (const keywordObj of mainwords) { 1306 | kMatch++ 1307 | if (keywordObj.isBracketed) kBracket++ 1308 | } 1309 | // console.log(22,variant,kMatch, kBracket, mainwords) 1310 | 1311 | // 【MV】迷星叫 / MyGO!!!!!【オリジナル楽曲】 1312 | // 【歌ってみた】大脳的なランデブー / Covered by 花鋏キョウ【Kanaria】 1313 | if (kMatch === 2 || kMatch - kBracket === 2) { 1314 | const m = kMatch === 2 ? mainwords : mainwords.filter(entry => !entry.isBracketed) 1315 | const p = `${m[0].keyword}\t${m[1].keyword}` 1316 | const lastAdded = variantsX.get(p) 1317 | if (!lastAdded || (lastAdded && lastAdded.variant.length > variant.length)) variantsX.set(p, { variant, kMatch, kBracket }) // store the shortest match 1318 | } 1319 | resolve(0) 1320 | }) 1321 | })) 1322 | } 1323 | 1324 | if (variantsX.size === 1) { 1325 | const values = [...variantsX.keys()] 1326 | wSongTitle = values[0] 1327 | } else if (variantsX.size > 1) { 1328 | const entries = [...variantsX.entries()] 1329 | entries.sort((a, b) => (b[1].kMatch * 100 + b[1].kBracket) - (a[1].kMatch * 100 + a[1].kBracket)) 1330 | if (entries[0][1].kMatch > entries[1][1].kMatch) { 1331 | wSongTitle = entries[0][0] 1332 | } 1333 | } 1334 | variantsX.clear() 1335 | variantsX = null 1336 | variants.length = 0 1337 | variants = null 1338 | } 1339 | 1340 | if (wSongTitle !== null) { 1341 | const m = wSongTitle.split('\t') 1342 | window.defaultSongTitle = `${m[0]} ${m[1]}` 1343 | return { songTitle: wSongTitle, songArtistsArr: null } 1344 | } 1345 | 1346 | // Symbols and Punctuation can be part of the artist name (e.g. &TEAM, milli-billi) 1347 | songTitle = simpleTextFixup(songTitle) 1348 | 1349 | songTitle = songTitle.replace(/(Official )?(Lyrics Video|Lyric Video|Music Video|Promotion Video|Video)/gi, '') 1350 | songTitle = songTitle.replace(/\b(PERFORMANCE VIDEO|official mv|karaoke mv|official|music mv|audio|music|video|karaoke)\b/gi, '') 1351 | songTitle = songTitle.replace(/\(\s*\)|\[\s*\]/g, '') 1352 | songTitle = songTitle.replace(/exclusive\s*-?/gi, '') 1353 | songTitle = songTitle.replace(/-\s*-/gi, ' - ') 1354 | songTitle = songTitle.replace(/([\uFF01-\uFF0F\u0021-\u002F\u003A-\u0040\u005B-\u0060\u007B-\u007E\u3000\u3001-\u303F\u2000-\u206F\s])(MV|PV)\s*$/g, '$1') 1355 | songTitle = songTitle.replace(/^\s*(MV|PV)([\uFF01-\uFF0F\u0021-\u002F\u003A-\u0040\u005B-\u0060\u007B-\u007E\u3000\u3001-\u303F\u2000-\u206F\s])/g, '$2') 1356 | songTitle = repeatReplace(songTitle, /\[\]/g, '', 8) 1357 | songTitle = songTitle.trim() 1358 | 1359 | // YOASOBI[祝福] [[機動戦士ガンダム 水星の魔女]オープニングテーマ] 1360 | // 結束バンド[星座になれたら]/ TVアニメ[ぼっち・ざ・ろっく!]第12話劇中曲 1361 | const exec1 = /^[^[\](){}]+\[[^[\](){}]+\]/.exec(songTitle) 1362 | if (exec1) { 1363 | let tmpSongTitle = songTitle 1364 | tmpSongTitle = tmpSongTitle.replace(/\[\[[^[\]{}()]+\](オープニングテーマ|オープニング|エンディングテーマ|エンディング|Opening\s?Song|Ending\s?Song|Opening|Ending)\]$/, ' ').trim() 1365 | tmpSongTitle = tmpSongTitle.replace(/\[[^[\]{}()]*\s*(オープニングテーマ|オープニング|エンディングテーマ|エンディング|Opening\s?Song|Ending\s?Song|Opening|Ending)\]$/, ' ').trim() 1366 | tmpSongTitle = tmpSongTitle.replace(/(TV)?\s*(アニメ|Anime)\[[^[\]{}()]+\][^[\]{}()]*$/, ' ').trim() 1367 | if (tmpSongTitle.includes(exec1[0])) { 1368 | songTitle = tmpSongTitle 1369 | } 1370 | } 1371 | 1372 | songTitle = repeatReplace(songTitle, /[//]\s*$/g, '', 8) 1373 | 1374 | // Pattern: Artist - Song title 1375 | songTitle = songTitle.split(/\s+[-–]\s+/) 1376 | 1377 | if (songTitle.length === 1) { 1378 | // Pattern: Artist[Song title] 1379 | const m = songTitle[0].match(/^([^[\]{}()]+)\[([^[\]{}()]+)\]$/) 1380 | if (m) { 1381 | songTitle = [m[1], m[2]] 1382 | } 1383 | } 1384 | 1385 | if (songTitle.length === 1) { 1386 | // Pattern: Artist | Song title 1387 | const m = songTitle[0].match(/(.+?)\s*\|\s*(.+)/) 1388 | if (m) { 1389 | songTitle = [m[1], m[2]] 1390 | } 1391 | } 1392 | 1393 | if (songTitle.length === 1) { 1394 | // Pattern: Artist "Song title" 1395 | const m = songTitle[0].match(/(.+?)\s*["“”'`´*]+(.+)["“”'`´*]+/) 1396 | if (m) { 1397 | songTitle = [m[1], m[2]] 1398 | } 1399 | } 1400 | 1401 | if (songTitle.length === 1) { 1402 | // Pattern: Songtitle by Artist 1403 | const m = songTitle[0].match(/(.+?)\s+by\s+(.+)/) 1404 | if (m) { 1405 | songTitle = [m[2], m[1]] 1406 | } 1407 | } 1408 | 1409 | if (songTitle.length === 1 && 'author' in videoDetails) { 1410 | // Fallback to video author name 1411 | songArtists = videoDetails.author 1412 | songArtists = songArtists.replace(/\b(vevo|official|music|channel)\b/gi, '') 1413 | songArtists = songArtists.replace(/-\s*topic/gi, '') 1414 | } else { 1415 | songArtists = songTitle.shift().trim() 1416 | } 1417 | 1418 | const songArtistsArr = songArtists.split(',').map(s => s.trim()) 1419 | songTitle = songTitle.join(' - ').trim() 1420 | songTitle = genius.f.cleanUpSongTitle(songTitle) 1421 | // return object result 1422 | return { songTitle, songArtistsArr } 1423 | } 1424 | 1425 | function newYtdDescriptionInfo (ytdDescriptionInfo) { 1426 | let song = ytdDescriptionInfo.song 1427 | const singer = ytdDescriptionInfo.singer 1428 | song = song.replace('(Karaoke)', '') 1429 | // return object result 1430 | return { songTitle: `${singer}\t${song}`, songArtistsArr: null } 1431 | } 1432 | 1433 | function getYtdAppData () { 1434 | const ytdApp = document.querySelector('ytd-app') 1435 | return (ytdApp.__data || 0).data || ytdApp.data || null 1436 | } 1437 | 1438 | function isYtdAppReady () { 1439 | let ytdAppData = null 1440 | let videoDetails = null 1441 | try { 1442 | ytdAppData = getYtdAppData() 1443 | if ('player' in ytdAppData && 'args' in ytdAppData.player && 'raw_player_response' in ytdAppData.player.args && 'videoDetails' in ytdAppData.player.args.raw_player_response) { 1444 | videoDetails = ytdAppData.player.args.raw_player_response.videoDetails 1445 | } else { 1446 | videoDetails = ytdAppData.playerResponse.videoDetails 1447 | } 1448 | } catch (e) { 1449 | } 1450 | return !!videoDetails 1451 | } 1452 | 1453 | function getVideoInfo (ytdAppData) { 1454 | let videoDetails = null 1455 | try { 1456 | if ('player' in ytdAppData && 'args' in ytdAppData.player && 'raw_player_response' in ytdAppData.player.args && 'videoDetails' in ytdAppData.player.args.raw_player_response) { 1457 | videoDetails = ytdAppData.player.args.raw_player_response.videoDetails || null 1458 | } else { 1459 | videoDetails = ytdAppData.playerResponse.videoDetails || null 1460 | } 1461 | } catch (e) { 1462 | console.warn(SCRIPT_NAME + ' addLyrics() Could not find videoDetails') 1463 | console.log(e) 1464 | const m = document.location.href.match(/v=(\w+)&?/) 1465 | videoDetails = { 1466 | videoId: (m && m[1] ? m[1] : ''), 1467 | keywords: [], 1468 | shortDescription: '' 1469 | } 1470 | } 1471 | return videoDetails // could be null 1472 | } 1473 | 1474 | async function getPageSongInfo (ytdAppData, videoDetails) { 1475 | let isMusic = false 1476 | let ytdDescriptionInfo = null 1477 | let videoTitle = null 1478 | let genre = null 1479 | let isFamilySafe = null 1480 | 1481 | // obtain the music info from modern meta panel 1482 | ytdDescriptionInfo = getMusicTitleAndAuthor(ytdAppData) 1483 | if (ytdDescriptionInfo !== null) { 1484 | isMusic = true 1485 | } 1486 | // videoTitle 1487 | try { 1488 | videoTitle = getSimpleText(ytdAppData.playerResponse.microformat.playerMicroformatRenderer.title) 1489 | } catch (e) { } 1490 | // genre 1491 | try { 1492 | genre = ytdAppData.playerResponse.microformat.playerMicroformatRenderer.category 1493 | } catch (e) { } 1494 | 1495 | if (typeof videoTitle !== 'string') { 1496 | return null 1497 | } 1498 | 1499 | console.log(`Youtube Genius Lyrics - Genre "${genre}" is found`) 1500 | if (ytdDescriptionInfo === null) { 1501 | if (genre === 'Music') { 1502 | isMusic = true 1503 | } 1504 | } 1505 | 1506 | // isFamilySafe 1507 | try { 1508 | isFamilySafe = ytdAppData.playerResponse.microformat.playerMicroformatRenderer.isFamilySafe 1509 | } catch (e) { } 1510 | if (isFamilySafe === false) return null // not suitable to load lyrics; isFamilySafe shall not be false for music 1511 | 1512 | window.defaultSongTitle = null 1513 | // traditionalYtdDescriptionInfo if ytdDescriptionInfo is not available 1514 | const { songTitle, songArtistsArr } = (ytdDescriptionInfo === null) 1515 | ? await traditionalYtdDescriptionInfo(videoTitle, videoDetails) 1516 | : newYtdDescriptionInfo(ytdDescriptionInfo) 1517 | 1518 | // console.log(window.defaultSongTitle) 1519 | // if (!isMusic && window.defaultSongTitle) isMusic = true 1520 | return { songTitle, songArtistsArr, isMusic } 1521 | } 1522 | 1523 | function setDisableShowLyricsButton (newValue) { 1524 | if (newValue === disableShowLyricsButton) return 1525 | disableShowLyricsButton = newValue 1526 | if (disableShowLyricsButton === true) { 1527 | removeLyricsButton() 1528 | } 1529 | // note: setting to false would not immediately generate the button 1530 | } 1531 | 1532 | let mPageSongInfoPromise = null 1533 | 1534 | async function addLyrics (force, beLessSpecific) { 1535 | const isMainCall = arguments.length === 0 1536 | if (isMainCall) setDisableShowLyricsButton(false) // reset to false for every addLyrics() 1537 | try { 1538 | const pRes = await Promise.race([mPageSongInfoPromise]) 1539 | if (!pRes) return // unknown error 1540 | switch (pRes.status) { 1541 | case -1: // rarely happen; only if addLyrics triggered when the page is still loading 1542 | return 1543 | case -2: // Not a video page, video page not visible, or any case that should disable the feature 1544 | lastVideoId = null 1545 | if (isMainCall) setDisableShowLyricsButton(true) // no button if the page is confirmed as non-video page like 'browse', 'search' 1546 | genius.f.hideLyricsWithMessage() 1547 | return 1548 | case -3: // no video details or videoId 1549 | lastVideoId = null 1550 | if (isMainCall) setDisableShowLyricsButton(false) // try to get page info again when user clicks the button 1551 | else if (force === true) setDisableShowLyricsButton(true) // no video details when the button is clicked 1552 | genius.f.hideLyricsWithMessage() 1553 | return 1554 | default: 1555 | // do nothing 1556 | } 1557 | const tmpVideoId = `${pRes.videoId}${genius.option.themeKey}${genius.option.fontSize}` 1558 | if (lastVideoId === tmpVideoId && document.getElementById('lyricscontainer')) { 1559 | // Same video id and same theme settings and lyrics are showing -> stop here 1560 | return 1561 | } 1562 | lastVideoId = tmpVideoId 1563 | 1564 | const pageSongInfoRes = pRes.pageSongInfoRes // can be null 1565 | // setDisableShowLyricsButton(true) might have called in getPageSongInfo 1566 | if (!pageSongInfoRes) { 1567 | // video id is known but the song info is unknown (or not suitable to show lyrics) 1568 | // do not load lyrics even if force = true 1569 | setDisableShowLyricsButton(true) // the page is loaded but no song info; disable the button 1570 | genius.f.hideLyricsWithMessage() 1571 | return 1572 | } 1573 | let { songTitle, songArtistsArr, isMusic } = pageSongInfoRes 1574 | if (force) { 1575 | isMusic = true 1576 | lastForceVideoId = lastVideoId 1577 | } else if (isMusic === false && (lastForceVideoId === null || lastForceVideoId !== lastVideoId)) { 1578 | // show button if not disabled 1579 | genius.f.hideLyricsWithMessage() 1580 | return 1581 | } 1582 | 1583 | const musicIsPlaying = isYoutubeVideoPlaying() 1584 | genius.f.loadLyrics(force, beLessSpecific, songTitle, songArtistsArr, musicIsPlaying) 1585 | } catch (e) { 1586 | console.warn(e) 1587 | } 1588 | } 1589 | 1590 | let lastPos = null 1591 | function cubicBezier (p1x, p1y, p2x, p2y) { 1592 | const p1 = { 1593 | x: p1x, 1594 | y: p1y 1595 | } 1596 | const p2 = { 1597 | x: p2x, 1598 | y: p2y 1599 | } 1600 | 1601 | function w (t, u0, u1) { 1602 | const f = 1 - t 1603 | return 3 * f * f * t * u0 + 3 * f * t * t * u1 + t * t * t 1604 | } 1605 | 1606 | function v (t, A, B, C) { 1607 | return A * t * t * t + B * t * t + C * t 1608 | } 1609 | 1610 | function vp (t, A, B, C) { 1611 | return 3 * A * t * t + 2 * B * t + C 1612 | } 1613 | 1614 | /* eslint-disable camelcase */ 1615 | const w_n1 = w(-1, p1.x, p2.x) 1616 | const w_p1 = w(1, p1.x, p2.x) 1617 | const w_p2 = w(2, p1.x, p2.x) 1618 | const w_B = (w_n1 + w_p1) / 2 1619 | const w_6A2B = w_p2 - 2 * w_p1 // 8-2; 4-2; 2-2 1620 | const w_A = (w_6A2B - 2 * w_B) / 6 1621 | const w_C = w_p1 - w_A - w_B 1622 | /* eslint-enable camelcase */ 1623 | 1624 | // Ax^3. Bx^2. Cx + 0 1625 | // -1: -A + B - C 1626 | // 1: A + B + C 1627 | // 2: 8A + 4B + 2C 1628 | 1629 | // Ax^3 + Bx^2 + Cx + 0 = s 1630 | // Ax^3 + Bx^2 + Cx - s = 0 1631 | 1632 | /* eslint-disable camelcase */ 1633 | let last_s = null 1634 | let last_t = null 1635 | let last_kvp = null 1636 | return function cbpt (s) { 1637 | if (s > 0 && s < 1) { 1638 | let t = s // guess t0=s instead of t0=0.5 1639 | if (last_s !== null) { 1640 | // t_n = t_n-1 - (kv - s) / kvp = t_n-1 - kv / kvp + s / kvp 1641 | // t'_0 = t_n-1 - (kv - s') / kvp = t_n-1 - kv / kvp + s' / kvp 1642 | // t'_0 = t_n - s / kvp + s' / kvp = t_n + (s' - s) / kvp 1643 | t = last_t + (s - last_s) / last_kvp 1644 | } 1645 | let u 1646 | let i = 0 1647 | let kvp = 0.0 1648 | while (i < 2) { 1649 | const kv = v(t, w_A, w_B, w_C) 1650 | kvp = vp(t, w_A, w_B, w_C) 1651 | const dt = (kv - s) / kvp 1652 | t -= dt 1653 | if (i > 0 && u < 0 && t < 0) { 1654 | // do nothing 1655 | } else if (i > 0 && u > 1 && t > 1) { 1656 | // do nothing 1657 | } else if (dt * dt < 0.00001) { 1658 | i++ 1659 | } 1660 | u = t 1661 | } 1662 | last_t = t 1663 | last_s = s 1664 | last_kvp = kvp 1665 | return w(t, p1.y, p2.y) 1666 | } else if (s >= 0 && s <= 1) { // avoid equal comparision for floating values 1667 | return s 1668 | } else { 1669 | return null 1670 | } 1671 | } 1672 | /* eslint-enable camelcase */ 1673 | } 1674 | 1675 | // https://cubic-bezier.com/# 1676 | const cbLyricsTime = cubicBezier(.21, .08, .42, .66) /* eslint-disable-line no-floating-decimal */ 1677 | // the adjustment is based on typical JPOP songs: 1678 | // 美波「カワキヲアメク」MV https://www.youtube.com/watch?v=0YF8vecQWYs 1679 | // GHOST / 星街すいせい(official) https://www.youtube.com/watch?v=IKKar5SS29E 1680 | 1681 | // at the begining, slower to suit either with or without verse. 1682 | // for verse at the beginning, the lyrics will be upshifted for the first sentence 1683 | // for without verse at the beginning, the singer would not sing in a very fast pace, so it can be slowed down 1684 | // it usually singing ends before the media ends. it might be pure music to make listeners relax the emotion. 1685 | // the lyrics shall be ahead the timeline a bit 1686 | 1687 | // verse at the middle would not affect much. It will be equvalent to ~3 lines scrolling. 1688 | // Usually there is blank line and new line with the word "[verse]" such that the scrolling will still match the lyrics 1689 | 1690 | let isUpdateAutoScrollBusy = false 1691 | async function updateAutoScroll (video, force) { 1692 | if (isUpdateAutoScrollBusy) return 1693 | if (isTriggered !== true) return // not ready 1694 | if (!genius.current.compoundTitle) return // not ready 1695 | if (!video) { 1696 | video = getYoutubeMainVideo() 1697 | if (!video) return 1698 | } 1699 | isUpdateAutoScrollBusy = true 1700 | const { currentTime, duration } = video 1701 | let pos = currentTime / duration 1702 | if (pos >= 0) { 1703 | // do nothing 1704 | } else { 1705 | isUpdateAutoScrollBusy = false 1706 | return // invalid currentTime or duration 1707 | } 1708 | if (`${lastPos}` !== `${pos}`) { 1709 | lastPos = pos 1710 | let ct = currentTime 1711 | if (force !== true) { 1712 | await new Promise(resolve => setTimeout(resolve, 30)) 1713 | const ct1 = video.currentTime 1714 | if (`${video.duration}` === `${duration}` && ((ct1 - ct < 50 / 1000 && ct1 > ct) || `${ct1}` === `${ct}`)) { 1715 | // if the video is playing or stopped, without change of media 1716 | ct = ct1 1717 | pos = ct / duration 1718 | } else { 1719 | isUpdateAutoScrollBusy = false 1720 | return // invalid timechange 1721 | } 1722 | } 1723 | if (duration > 15) { // skip for music <= 15s 1724 | let k = 1.95 // the scrollbar will just disappear at the end of music 1725 | if (duration > 80) { 1726 | k = 3.21 // the singer shall stop a bit eariler than the media ends 1727 | if (duration > 160) { 1728 | k = 4.82 1729 | } 1730 | } 1731 | // p0 = (d-k)/d 1732 | // p1 = p0 + (m/d)*p0 1733 | // p1 = d/d = 1 1734 | // 1 - (d-k)/d = (m/d) * p0 1735 | // k/d = m*p0/d 1736 | // m = k/p0 = kd/(d-k) 1737 | const m = k * duration / (duration - k) // offset at pos = 1.0 1738 | const timelineOffset = m * pos // end scrolling earlier than video end by ${k}s; the scrollbar will disappear at the end of music 1739 | ct += timelineOffset 1740 | if (ct < 0) ct = 0 1741 | if (ct > duration) ct = duration 1742 | // ct=0; ct'=0 1743 | // ct=y; ct'=y 1744 | let cbFactor = 1.0 1745 | if (ct > 0 && ct < duration) { 1746 | const s = ct / duration // (0,1) 1747 | const s1 = await cbLyricsTime(s) // (0,1) 1748 | cbFactor = s1 / s 1749 | } 1750 | pos = ct / duration * cbFactor 1751 | } 1752 | genius.f.scrollLyrics(pos) 1753 | } 1754 | await new Promise(requestAnimationFrame) /* eslint-disable-line no-new */ 1755 | isUpdateAutoScrollBusy = false 1756 | } 1757 | 1758 | function safeString (s) { 1759 | return (s || 0).length > 0 ? `${s}` : '' 1760 | } 1761 | 1762 | async function performSearch () { 1763 | try { 1764 | const container = document.querySelector('#lyricscontainer.youtube-genius-lyrics-search-container') 1765 | const input = document.querySelector('input.youtube-genius-lyrics-search-input') 1766 | if (!container || !input) return 1767 | 1768 | let inputValue = input.value 1769 | if (!input.value) { 1770 | inputValue = placeholderValue() 1771 | window.lastUserInput = null 1772 | } else { 1773 | window.lastUserInput = inputValue 1774 | } 1775 | if (inputValue) { 1776 | if (document.querySelector('.loadingspinnerholder') !== null) { 1777 | genius.f.cancelLoading() 1778 | } 1779 | if (typeof genius.current.compoundTitle === 'string') { 1780 | genius.f.forgetLyricsSelection(genius.current.compoundTitle, null) 1781 | } 1782 | try { 1783 | input.blur() 1784 | } catch (e) { } 1785 | await Promise.resolve(0) 1786 | container.classList.add('lyrics-searching') 1787 | genius.f.searchByQuery(inputValue, container, (res) => { 1788 | let c = document.querySelector('#lyricscontainer') 1789 | try { 1790 | if (res && res.status === 200) { 1791 | const hits = res.hits 1792 | if (!hits) return 1793 | if (hits.length > 0) { 1794 | listSongs(hits, container, inputValue) 1795 | } else { 1796 | input.classList.add('lyrics-input-noresult') 1797 | window.incorrectInputValue = inputValue 1798 | } 1799 | } 1800 | } catch (e) { } 1801 | if (c !== null) { 1802 | c.classList.remove('lyrics-searching') 1803 | } 1804 | c = null 1805 | }) 1806 | } else { 1807 | input.classList.add('lyrics-input-noresult') 1808 | window.incorrectInputValue = '' 1809 | } 1810 | } catch (e) { 1811 | console.warn(e) 1812 | } 1813 | } 1814 | 1815 | function onSearchLyricsKeyDown (ev) { 1816 | const input = this 1817 | if (typeof window.incorrectInputValue === 'string' && input.value !== window.incorrectInputValue) { 1818 | window.incorrectInputValue = null 1819 | input.classList.remove('lyrics-input-noresult') 1820 | } 1821 | } 1822 | 1823 | function onSearchLyricsKeyUp (ev) { 1824 | const input = this 1825 | if (ev.code === 'Escape') { 1826 | ev.preventDefault() 1827 | input.value = '' 1828 | } else if (ev.code === 'Enter' || ev.code === 'NumpadEnter') { 1829 | ev.preventDefault() 1830 | performSearch() 1831 | return 1832 | } 1833 | if (typeof window.incorrectInputValue === 'string' && input.value !== window.incorrectInputValue) { 1834 | window.incorrectInputValue = null 1835 | input.classList.remove('lyrics-input-noresult') 1836 | } 1837 | } 1838 | function onSearchLyricsSearchBtnClick (ev) { 1839 | ev.preventDefault() 1840 | performSearch() 1841 | } 1842 | 1843 | function hideLyricsWithMessageAndStopAutoShow () { 1844 | if (genius.option.autoShow === true) { 1845 | const isLyricsPanelShown = lyricsDisplayState === 'loading' || lyricsDisplayState === 'loaded' 1846 | if (isLyricsPanelShown) genius.option.autoShow = false // Temporarily disable showing lyrics automatically on song change 1847 | } 1848 | genius.f.hideLyricsWithMessage() 1849 | } 1850 | 1851 | function onSearchLyricsHideBtnClick (ev) { 1852 | hideLyricsWithMessageAndStopAutoShow() 1853 | } 1854 | 1855 | function placeholderValue () { 1856 | return safeString(window.lastUserInputConfirmed) || safeString(window.lastFetchedQuery) || safeString(window.defaultSongTitle) || '' 1857 | } 1858 | 1859 | function showSearchField (query) { 1860 | const spanLabel = document.createElement('span') 1861 | spanLabel.classList.add('youtube-genius-lyrics-search-label') 1862 | spanLabel.textContent = 'Search genius.com: ' 1863 | 1864 | const input = document.createElement('input') 1865 | input.classList.add('youtube-genius-lyrics-search-input') 1866 | // input.placeholder = 'Search genius.com...' 1867 | 1868 | const searchBtn = document.createElement('span') 1869 | searchBtn.classList.add('youtube-genius-lyrics-search-search-btn') 1870 | 1871 | searchBtn.appendChild(elmBuildNS('svg', 1872 | { 1873 | xmlns: 'http://www.w3.org/2000/svg' 1874 | }, 1875 | { 1876 | attr: { 1877 | width: '12', 1878 | height: '12', 1879 | preserveAspectRatio: 'xMidYMid meet', 1880 | viewBox: '0 0 342 342' 1881 | } 1882 | }, [ 1883 | 'path', { 1884 | attr: { 1885 | d: 'M337 317 239 219C259 196 270 166 270 134 270 60 210 0 135 0S0 60 0 134 61 268 135 268C167 268 196 257 219 239L317 337C323 343 331 343 337 337S343 323 337 317ZM29 134C29 76 76 29 135 29S241 76 241 134 194 239 135 239 29 192 29 134Z' 1886 | } 1887 | } 1888 | ])) 1889 | 1890 | // Hide button 1891 | const hideButton = document.createElement('span') 1892 | hideButton.classList.add('youtube-genius-lyrics-search-hide-btn') 1893 | hideButton.textContent = 'Hide' 1894 | hideButton.addEventListener('click', onSearchLyricsHideBtnClick, false) 1895 | 1896 | const configButton = createConfigBtn('youtube-genius-lyrics-search-config-btn') 1897 | 1898 | input.value = safeString(query) || '' 1899 | if (typeof window.lastUserInput === 'string' && !input.value) { 1900 | input.value = safeString(window.lastUserInput) || '' 1901 | } 1902 | const fetechQuery = placeholderValue() 1903 | input.placeholder = fetechQuery || `${genius.option.defaultPlaceholder}` 1904 | input.classList.toggle('placeholder-lastfetch', !!fetechQuery) 1905 | 1906 | let b = null // container 1907 | window.incorrectInputValue = null 1908 | 1909 | input.addEventListener('keydown', onSearchLyricsKeyDown, false) 1910 | input.addEventListener('keyup', onSearchLyricsKeyUp, false) 1911 | searchBtn.addEventListener('click', onSearchLyricsSearchBtnClick, false) 1912 | 1913 | // flush DOM 1914 | b = getCleanLyricsContainer() 1915 | 1916 | b.classList.add('youtube-genius-lyrics-search-container') 1917 | document.documentElement.setAttribute('youtube-genius-lyrics-container', 'search') 1918 | appendElements(b, [ 1919 | spanLabel, 1920 | input, 1921 | searchBtn, 1922 | configButton, 1923 | hideButton 1924 | ]) 1925 | document.body.appendChild(b) 1926 | 1927 | new Promise(() => { /* eslint-disable-line no-new */ 1928 | input.focus() 1929 | }) 1930 | } 1931 | 1932 | function createConfigBtn (cName) { 1933 | const configButton = document.createElement('span') 1934 | configButton.classList.add(cName) 1935 | configButton.textContent = 'Options' 1936 | configButton.addEventListener('click', function configButtonClick (ev) { 1937 | genius.f.config() 1938 | }) 1939 | return configButton 1940 | } 1941 | 1942 | function onLyricsFoundHideBtnClick (ev) { 1943 | hideLyricsWithMessageAndStopAutoShow() 1944 | } 1945 | 1946 | function onLyricsFoundBackToSearchClick (ev) { 1947 | showSearchField() 1948 | } 1949 | 1950 | function setupLyricsDisplayDOM (song, searchresultsLengths) { // eslint-disable-line no-unused-vars 1951 | // getCleanLyricsContainer 1952 | const container = getCleanLyricsContainer() 1953 | container.className = '' // custom.getCleanLyricsContainer might forget to clear the className if the element is reused 1954 | container.classList.add('youtube-genius-lyrics-found-container') 1955 | document.documentElement.setAttribute('youtube-genius-lyrics-container', 'found') 1956 | 1957 | if (typeof genius.f.isGreasemonkey === 'function' && genius.f.isGreasemonkey()) { 1958 | // container.textContent = ''; 1959 | elmBuild(container, 1960 | ['h2', 1961 | 'This script only works in ', 1962 | ['a', { 1963 | target: '_blank', 1964 | href: 'https://addons.mozilla.org/en-US/firefox/addon/tampermonkey/' 1965 | }, 'Tampermonkey'] 1966 | ], 1967 | 'Greasemonkey is no longer supported because of this ', 1968 | ['a', { 1969 | target: '_blank', 1970 | href: 'https://github.com/greasemonkey/greasemonkey/issues/2574' 1971 | }, 'bug greasemonkey/issues/2574'], 1972 | ' in Greasemonkey.' 1973 | ) 1974 | return 1975 | } 1976 | 1977 | let separator = document.createElement('span') 1978 | separator.classList.add('second-line-separator') 1979 | separator.classList.add('youtube-genius-lyrics-found-separator') 1980 | separator.textContent = '•' 1981 | 1982 | const bar = document.createElement('div') 1983 | bar.classList.add('lyricsnavbar') 1984 | 1985 | /* 1986 | // Resize button 1987 | if ('initResize' in custom) { 1988 | const resizeButton = document.createElement('span') 1989 | resizeButton.style.fontSize = '1.8em' 1990 | resizeButton.style.cursor = 'ew-resize' 1991 | resizeButton.textContent = '⇹' 1992 | resizeButton.addEventListener('mousedown', custom.initResize) 1993 | elementsToBeAppended.push(resizeButton, separator.cloneNode(true)) 1994 | } 1995 | */ 1996 | 1997 | // Hide button 1998 | const hideButton = document.createElement('span') 1999 | hideButton.classList.add('youtube-genius-lyrics-found-hide-btn') 2000 | hideButton.textContent = 'Hide' 2001 | hideButton.addEventListener('click', onLyricsFoundHideBtnClick, false) 2002 | 2003 | // Config button 2004 | const configButton = createConfigBtn('youtube-genius-lyrics-found-config-btn') 2005 | let goToSearchBtn = null 2006 | if (searchresultsLengths === 1) { 2007 | // Wrong lyrics button 2008 | const wrongLyricsButton = document.createElement('span') 2009 | wrongLyricsButton.classList.add('youtube-genius-lyrics-found-wonglyrics-btn') 2010 | wrongLyricsButton.textContent = 'Search lyrics' 2011 | wrongLyricsButton.addEventListener('click', onLyricsFoundBackToSearchClick, false) 2012 | goToSearchBtn = wrongLyricsButton 2013 | } else if (searchresultsLengths > 1) { 2014 | // Back button 2015 | const backbutton = document.createElement('span') 2016 | backbutton.classList.add('youtube-genius-lyrics-found-back-btn') 2017 | backbutton.textContent = `Back to search (${searchresultsLengths - 1} other result${searchresultsLengths === 2 ? '' : 's'})` 2018 | backbutton.addEventListener('click', onLyricsFoundBackToSearchClick, false) 2019 | goToSearchBtn = backbutton 2020 | } 2021 | 2022 | const iframe = document.createElement('iframe') 2023 | if (typeof webkitCancelAnimationFrame === 'function') { 2024 | iframe.src = (iframeBlankURL || (iframeBlankURL = URL.createObjectURL(new Blob([], { type: 'text/html' })))) // Brave 2025 | } 2026 | iframe.id = 'lyricsiframe' 2027 | iframe.style.opacity = 0.1 2028 | 2029 | // flush to DOM tree 2030 | appendElements(bar, [ 2031 | goToSearchBtn, 2032 | separator.cloneNode(true), 2033 | configButton, 2034 | separator.cloneNode(true), 2035 | hideButton 2036 | ]) 2037 | appendElements(container, [bar, iframe]) 2038 | 2039 | // clean up 2040 | separator = null 2041 | 2042 | return { 2043 | container, 2044 | bar, 2045 | iframe 2046 | } 2047 | } 2048 | 2049 | function getHitOfElement (li) { 2050 | if (!li || li.nodeType !== 1 || !hitMaps) { 2051 | return null 2052 | } 2053 | return hitMaps.get(li) || null 2054 | } 2055 | 2056 | // function formatPageViews (stats) { 2057 | // if (!stats) return null 2058 | // return 'pageviews' in stats && typeof stats.pageviews === 'number' ? genius.f.metricPrefix(stats.pageviews, 1) : ' - ' 2059 | // } 2060 | 2061 | async function rememberLyricsSelection (title, artists, hit) { 2062 | // in order to call "genius.f.rememberLyricsSelection(title, artists, jsonHit)", use async call to get jsonHit 2063 | const jsonHit = await new Promise(function (resolve) { /* eslint-disable-line no-new */ 2064 | // this is not a complete async function, but it helps not to block the scripting 2065 | resolve(JSON.stringify(hit)) 2066 | }) 2067 | genius.f.rememberLyricsSelection(title, artists, jsonHit) 2068 | } 2069 | 2070 | function onLyricsResultsBackBtnClick (ev) { 2071 | showSearchField() 2072 | } 2073 | 2074 | function onLyricsResultsHideBtnClick (ev) { 2075 | hideLyricsWithMessageAndStopAutoShow() 2076 | } 2077 | 2078 | function onLyricsResultsTrackListClick (ev) { 2079 | const tracklist = this 2080 | const element = ev.target 2081 | if (element.nodeName === 'LI') { 2082 | const hit = getHitOfElement(element) 2083 | if (hit !== null) { 2084 | if (typeof window.lastUserInput === 'string') { 2085 | window.lastUserInputConfirmed = window.lastUserInput 2086 | window.lastUserInput = null 2087 | } 2088 | const compoundTitle = genius.current.compoundTitle 2089 | const searchresultsLengths = tracklist.querySelectorAll('li').length 2090 | genius.f.showLyrics(hit, searchresultsLengths) 2091 | rememberLyricsSelection(compoundTitle, null, hit) 2092 | } 2093 | } 2094 | } 2095 | 2096 | function convertPageViewsToText (pageviews) { 2097 | if (!Number.isFinite(pageviews)) return 'NaN' 2098 | if (pageviews <= 999) { 2099 | return pageviews 2100 | } 2101 | if (pageviews <= 999949) { 2102 | return `${+(pageviews / 1000).toFixed(1)}K` 2103 | } 2104 | // if(pageviews<=999949999){ 2105 | return `${+(pageviews / 1000000).toFixed(1)}M` 2106 | // } 2107 | } 2108 | 2109 | function listSongs (hits, container, query) { 2110 | // Back to search button 2111 | const backToSearchButton = document.createElement('span') 2112 | backToSearchButton.classList.add('youtube-genius-lyrics-results-back-btn') 2113 | backToSearchButton.textContent = 'Back to search' 2114 | backToSearchButton.addEventListener('click', onLyricsResultsBackBtnClick, false) 2115 | 2116 | const separator = document.createElement('span') 2117 | separator.classList.add('second-line-separator') 2118 | separator.classList.add('youtube-genius-lyrics-results-line-separator') 2119 | separator.textContent = '•' 2120 | 2121 | // Hide button 2122 | const hideButton = document.createElement('span') 2123 | hideButton.classList.add('youtube-genius-lyrics-results-hide-btn') 2124 | hideButton.textContent = 'Hide' 2125 | hideButton.addEventListener('click', onLyricsResultsHideBtnClick, false) 2126 | 2127 | // Config button 2128 | const configButton = createConfigBtn('youtube-genius-lyrics-results-config-btn') 2129 | 2130 | // List search results 2131 | const tracklistOL = document.createElement('ol') 2132 | tracklistOL.classList.add('tracklist') 2133 | tracklistOL.classList.add('youtube-genius-lyrics-results-tracklist') 2134 | tracklistOL.addEventListener('click', onLyricsResultsTrackListClick, true) 2135 | 2136 | let autoHit = autoSelectLyrics(hits) // setup _matchSource 2137 | if (autoHit) autoHit = autoHit.hit 2138 | const isTopResultBeingAutoHit = autoHit === hits[0] 2139 | 2140 | // prepare results 2141 | const liArr = hits.map(function hitsMap (hit) { 2142 | const li = document.createElement('li') 2143 | li.classList.add('youtube-genius-lyrics-results-li') 2144 | const resultUrl = hit.result.url 2145 | const resultPageViews = (hit.result.stats || 0).pageviews 2146 | li.setAttribute('data-result-url', resultUrl) 2147 | li.setAttribute('data-result-pageviews', resultPageViews) 2148 | // li.setAttribute('title', `${Number.isFinite(resultPageViews) ? convertPageViewsToText(resultPageViews) + "\n" : ""}${resultUrl}`) 2149 | 2150 | if (isTopResultBeingAutoHit && hit._order === hits[0]._order && hit._matchScore === hits[0]._matchScore) { 2151 | li.classList.add('lyrics-major-result') 2152 | } else { 2153 | li.classList.add('lyrics-minor-result') 2154 | } 2155 | li.setAttribute('title', `${hit.result.title_with_featured}`) 2156 | 2157 | const showPageViews = true // no need to show this; pageviews usually NaN 2158 | const showLyricsState = true 2159 | 2160 | /* eslint-disable operator-linebreak, indent, multiline-ternary */ 2161 | elmBuild(li, 2162 | ['div', 2163 | ['div', { classList: ['onhover'] }, ['span', '🅖']], 2164 | ['div', { classList: ['onout'] }, ['span', '📄']] 2165 | ], 2166 | ['div', { classList: ['youtube-genius-lyrics-tracklist-info-container'] }, 2167 | ['p', { classList: ['youtube-genius-lyrics-tracklist-info-primary'] }, `${hit.result.primary_artist.name} • ${hit.result.title}`], 2168 | showPageViews && showLyricsState && Number.isFinite(resultPageViews) ? 2169 | ['p', { classList: ['youtube-genius-lyrics-tracklist-info-secondary'] }, 2170 | ['span', { style: { 'font-size': '0.7em' } }, 2171 | elmBuildNS('svg', { classList: ['svg-genius-pageviews'] }, { attr: { viewBox: '-38 -27 76 54' } }, 2172 | ['path', { attr: { d: 'M0-25C21-25 35 0 35 0S21 25 0 25-35 0-35 0-21-25 0-25zm0 7C-13-18-23-6-28 0c5 6 15 18 28 18S23 6 28 0C23-6 13-18 0-18M0-7a7 7 90 1 1-7 7 7 7 90 0 1 7-7m0-5A12 12 90 1 0 12 0 12 12 90 0 0 0-12z' } }] 2173 | ), 2174 | `${convertPageViewsToText(resultPageViews) || ''} ${hit.result.lyrics_state}` 2175 | ] 2176 | ] : '', 2177 | !showPageViews && showLyricsState ? ['p', { classList: ['youtube-genius-lyrics-tracklist-info-secondary'] }, ['span', { style: { 'font-size': '0.7em' } }, `${hit.result.lyrics_state}`]] : '' 2178 | ], 2179 | ['div', { style: { clear: 'left' } }] 2180 | ) 2181 | /* eslint-enable operator-linebreak, indent, multiline-ternary */ 2182 | 2183 | if (!hitMaps) { 2184 | hitMaps = new WeakMap() 2185 | } 2186 | hitMaps.set(li, hit) 2187 | return li 2188 | }) 2189 | appendElements(tracklistOL, liArr) 2190 | 2191 | // Flush DOM 2192 | if (!container) { 2193 | container = getCleanLyricsContainer() 2194 | } else { 2195 | container.className = '' 2196 | container.textContent = '' 2197 | } 2198 | container.classList.add('youtube-genius-lyrics-results-container') 2199 | document.documentElement.setAttribute('youtube-genius-lyrics-container', 'results') 2200 | appendElements(container, [ 2201 | backToSearchButton, 2202 | separator, 2203 | configButton, 2204 | separator.cloneNode(true), 2205 | hideButton, 2206 | tracklistOL 2207 | ]) 2208 | } 2209 | 2210 | function loremIpsum () { 2211 | const random = (x) => 1 + parseInt(Math.random() * x) 2212 | 2213 | // Create a container for the entire content 2214 | const container = document.createElement('div') 2215 | 2216 | for (let v = 0; v < Math.max(3, random(5)) + 4; v++) { 2217 | for (let b = 0; b < random(6); b++) { 2218 | const lineContainer = document.createElement('span') 2219 | lineContainer.classList.add('gray') 2220 | 2221 | for (let l = 0; l < random(9); l++) { 2222 | for (let w = 0; w < 1 + random(10); w++) { 2223 | for (let i = 0; i < 1 + random(7); i++) { 2224 | // Create and append 'x' text node 2225 | const xTextNode = document.createTextNode('x') 2226 | lineContainer.appendChild(xTextNode) 2227 | } 2228 | 2229 | // Add the whitespace span 2230 | const whiteSpaceSpan = document.createElement('span') 2231 | whiteSpaceSpan.classList.add('white') 2232 | whiteSpaceSpan.textContent = '\u00A0' // Non-breaking space 2233 | lineContainer.appendChild(whiteSpaceSpan) 2234 | } 2235 | 2236 | // Add line break (br) after each set 2237 | lineContainer.appendChild(document.createElement('br')) 2238 | } 2239 | 2240 | // Append the line container to the main container 2241 | container.appendChild(lineContainer) 2242 | 2243 | // Add a line break after each section 2244 | container.appendChild(document.createElement('br')) 2245 | } 2246 | } 2247 | 2248 | return container // Return the main container with all generated elements 2249 | } 2250 | 2251 | function createSpinner (spinnerHolder) { 2252 | lyricsDisplayState = 'loading' 2253 | const lyricscontainer = document.getElementById('lyricscontainer') 2254 | lyricscontainer.className = '' 2255 | lyricscontainer.classList.add('youtube-genius-lyrics-loading-container') 2256 | document.documentElement.setAttribute('youtube-genius-lyrics-container', 'loading') 2257 | 2258 | const spinner = spinnerHolder.appendChild(document.createElement('div')) 2259 | spinner.classList.add('loadingspinner') 2260 | 2261 | const lorem = loremIpsum() 2262 | lorem.classList.add('lorem', 'lorem-scroll') 2263 | spinnerHolder.appendChild(lorem) 2264 | 2265 | return spinner 2266 | } 2267 | 2268 | function customSpinnerDOM (container, bar, iframe) { 2269 | const spinnerDOM = { 2270 | createSpinnerHolder: () => { 2271 | const spinnerHolder = document.createElement('div') 2272 | spinnerHolder.classList.add('loadingspinnerholder') 2273 | spinnerDOM.spinnerHolder = spinnerHolder 2274 | }, 2275 | createSpinner: () => { 2276 | let spinner = null 2277 | const spinnerHolder = spinnerDOM.spinnerHolder 2278 | spinner = createSpinner(spinnerHolder) 2279 | spinnerDOM.spinner = spinner 2280 | }, 2281 | displaySpinnerHolder: () => { 2282 | container.appendChild(spinnerDOM.spinnerHolder) 2283 | }, 2284 | setStatusTitle: (title) => { 2285 | const spinnerHolder = spinnerDOM.spinnerHolder 2286 | spinnerHolder.title = title 2287 | }, 2288 | setSpinnerNum: (text) => { 2289 | const spinner = spinnerDOM.spinner 2290 | spinner.textContent = text 2291 | }, 2292 | remove: (text) => { 2293 | const spinnerHolder = spinnerDOM.spinnerHolder 2294 | spinnerHolder.remove() 2295 | } 2296 | } 2297 | return spinnerDOM 2298 | } 2299 | 2300 | function iframeLoadedCallback1 (res) { 2301 | lyricsDisplayState = 'loaded' 2302 | } 2303 | 2304 | function iframeLoadedCallback2 (res) { 2305 | // nothing 2306 | } 2307 | 2308 | function textSlash (text) { 2309 | // Create a set object which contains the information of the title 2310 | text = text 2311 | .replace(/\b([a-z0-9A-Z]+)[:~\-+]([a-z0-9A-Z]+)\b/, '$1$3') 2312 | .replace(/[\uFF01-\uFF5E]/g, (m) => { 2313 | // Halfwidth and Fullwidth Forms 2314 | return String.fromCharCode(m.charCodeAt(0) - 65248) 2315 | }) 2316 | .replace(/[\u180E\u200B-\u200D\u2060\uFEFF]+/g, '') // zero-spacing 2317 | .replace(/[\s\u0009-\u000D\u0020\u0085\u00A0\u1680\u2000-\u200A\u2028-\u2029\u202F\u205F\u3000\u00B7\u237D\u2420\u2422\u2423]+/g, '/') /* spacing */ // eslint-disable-line no-control-regex 2318 | .replace(/[\uFF01-\uFF0F\u0021-\u002F\u003A-\u0040\u005B-\u0060\u007B-\u007E\u3000\u3001-\u303F\u2000-\u206F]+/g, '/') // Symbols and Punctuation 2319 | .replace(/\/+/g, '/') 2320 | let s = text.split('/') 2321 | const r = new Set() 2322 | for (let t of s) { 2323 | if (t && t.length > 0) { 2324 | t = t.toLowerCase() 2325 | if (!r.has(t)) { 2326 | r.add(t) 2327 | } 2328 | } 2329 | } 2330 | s = null 2331 | return r 2332 | } 2333 | 2334 | function autoSelectLyrics (hits) { 2335 | // only do title matching (+channel name) 2336 | // to search the lyrics, use the short title 2337 | // to figure out which one is the most correct one, use full / featured title 2338 | 2339 | const ytdApp = document.querySelector('ytd-app') 2340 | let ytdAppData = null 2341 | let videoDetails = null 2342 | if (!ytdApp) return 2343 | 2344 | ytdAppData = getYtdAppData() 2345 | if ('player' in ytdAppData && 'args' in ytdAppData.player && 'raw_player_response' in ytdAppData.player.args && 'videoDetails' in ytdAppData.player.args.raw_player_response) { 2346 | videoDetails = ytdAppData.player.args.raw_player_response.videoDetails 2347 | } else { 2348 | videoDetails = ytdAppData.playerResponse.videoDetails 2349 | } 2350 | 2351 | const videoTitle = videoDetails.title 2352 | 2353 | if (typeof videoTitle !== 'string') return 2354 | 2355 | // console.log(videoDetails) 2356 | // console.log(videoTitle, textSlash(videoTitle)) 2357 | 2358 | const slashVideoTitle = textSlash(`${videoTitle}\n${videoDetails.author || ''}`) 2359 | let automaticHit = null 2360 | 2361 | for (const hit of hits) { 2362 | const result = hit.result || 0 2363 | const fTitle = result.full_title || result.title_with_featured || result.title 2364 | if (!fTitle || typeof fTitle !== 'string') continue 2365 | const slashFTitle = textSlash(`${fTitle}\n${result.artist_names || ''}`) 2366 | let score = 0 2367 | for (const key of slashFTitle.keys()) { 2368 | if (slashVideoTitle.has(key)) score++ 2369 | } 2370 | hit._matchScore = score 2371 | if (automaticHit === null || hit._matchScore > automaticHit._matchScore) { 2372 | automaticHit = hit 2373 | } 2374 | } 2375 | 2376 | // console.log(hits, automaticHit) 2377 | 2378 | if (automaticHit !== null) { 2379 | return { 2380 | hit: automaticHit 2381 | } 2382 | } 2383 | } 2384 | 2385 | function main () { 2386 | // do nothing 2387 | } 2388 | async function readPageSongInfo () { 2389 | mPageSongInfoPromise = null 2390 | 2391 | let ytdAppData = getYtdAppData() 2392 | if (!ytdAppData) { 2393 | // the status is unknown 2394 | return 2395 | } else if (ytdAppData.page !== 'watch' || !isYtdAppReady()) { 2396 | // ytdApp is initized but the pagetype or video info not exist 2397 | // (youtube web app page to 'search' or 'browse') 2398 | setDisableShowLyricsButton(true) 2399 | genius.f.hideLyricsWithMessage() 2400 | return 2401 | } 2402 | ytdAppData = null 2403 | 2404 | mPageSongInfoPromise = new Promise(resolve => { 2405 | // ytd application data 2406 | const ytdAppData = getYtdAppData() 2407 | if (!ytdAppData) return resolve({ status: -1 }) // rarely happen; only if addLyrics triggered when the page is still loading 2408 | if (ytdAppData.page !== 'watch') { 2409 | // Not a video page or video page not visible 2410 | return resolve({ status: -2 }) 2411 | } 2412 | 2413 | // ytd video data 2414 | const videoDetails = getVideoInfo(ytdAppData) 2415 | if (!videoDetails || !videoDetails.videoId) { 2416 | return resolve({ status: -3 }) 2417 | } 2418 | 2419 | const lengthSeconds = +videoDetails.lengthSeconds 2420 | if (Number.isFinite(lengthSeconds)) { 2421 | if (EXCLUDE_SHORT_LEN && lengthSeconds < 15) { // 15s 2422 | return resolve({ status: -3 }) 2423 | } 2424 | if (EXCLUDE_LIVE_VIDEO && videoDetails.isLiveContent && lengthSeconds > 1500) { // 25min 2425 | return resolve({ status: -3 }) 2426 | } 2427 | } 2428 | 2429 | getPageSongInfo(ytdAppData, videoDetails).then(pageSongInfoRes => { 2430 | // pageSongInfoRes can be null 2431 | setDisableShowLyricsButton(false) 2432 | resolve({ status: 1, pageSongInfoRes, videoId: videoDetails.videoId }) 2433 | }) 2434 | }) 2435 | } 2436 | async function actionAddLyricsOrButton () { 2437 | if (lyricsDisplayState === 'loading') { 2438 | // avoid iframe communcation error 2439 | return 2440 | } 2441 | if (isYouTubeLive) { 2442 | setDisableShowLyricsButton(true) 2443 | genius.f.hideLyricsWithMessage() 2444 | return 2445 | } 2446 | let mPageSongInfoRes = await mPageSongInfoPromise 2447 | if (mPageSongInfoRes && mPageSongInfoRes.status === 1) { 2448 | if (genius.option.autoShow) { 2449 | addLyrics() 2450 | } else { 2451 | addLyricsButton() 2452 | } 2453 | } 2454 | mPageSongInfoRes = null 2455 | } 2456 | 2457 | let isTriggered = false 2458 | async function executeMainWhenVisible (t, mPageLoadId) { 2459 | if (isTriggered || mPageLoadId !== pageLoadId) return 2460 | await new Promise(resolve => setTimeout(resolve, t)) /* eslint-disable-line no-new */ 2461 | if (isTriggered || mPageLoadId !== pageLoadId) return 2462 | isTriggered = true 2463 | actionAddLyricsOrButton() 2464 | } 2465 | function isYouTubeLiveFn () { 2466 | const ytpLive = document.querySelector('.ytp-live') 2467 | isYouTubeLive = ytpLive !== null && ytpLive.matches('[hidden] div.ytp-live') === false // just use simple DOM checking 2468 | const lyricsBtn = document.querySelector('#showlyricsbutton') 2469 | if (lyricsBtn !== null) lyricsBtn.classList.toggle('hide-during-ytlive', isYouTubeLive) 2470 | return isYouTubeLive 2471 | } 2472 | let pageLoadId = 0 2473 | function delayedMain () { 2474 | pageLoadId++ 2475 | if (pageLoadId > 1e9) pageLoadId = 9 2476 | if (genius && genius.current) { 2477 | genius.current.compoundTitle = null 2478 | } 2479 | isTriggered = false 2480 | // time allowed for other userscript(s) prepare the page 2481 | // and also not block the page 2482 | window.lastFetchedQuery = null // reset search when media changed 2483 | window.lastUserInput = null 2484 | window.lastUserInputConfirmed = null 2485 | window.defaultSongTitle = null 2486 | isYouTubeLiveFn() 2487 | const mPageLoadId = pageLoadId 2488 | requestAnimationFrame(() => { 2489 | if (mPageLoadId !== pageLoadId) return 2490 | // only execute in foreground tab 2491 | genius.f.hideLyricsWithMessage() 2492 | readPageSongInfo() 2493 | executeMainWhenVisible(200, mPageLoadId) 2494 | }) 2495 | } 2496 | 2497 | function newAppHint (status) { 2498 | // TODO should this be removed in favor of a README hint in the next version? 2499 | 2500 | if (document.getElementById('youtube-music-genius-lyrics-style')) { 2501 | // Other script already running 2502 | return GM.setValue('newapphint', -1) 2503 | } 2504 | 2505 | if (status % 10 === 0) { 2506 | let style = document.querySelector('style#newapphint785_style') 2507 | if (style === null) { 2508 | style = document.createElement('style') 2509 | style.id = 'newapphint785_style' 2510 | style.textContent = ` 2511 | #newapphint785 { 2512 | position:fixed; 2513 | top:0%; 2514 | left:0%; 2515 | padding:10px; 2516 | background-color:#202020; 2517 | color:#bbb; 2518 | font-size:large; 2519 | border:2px solid red; 2520 | border-radius: 5px; 2521 | box-shadow: red 1px 1px 10px; 2522 | transition:left 500ms, top 500ms; 2523 | z-index:2500 2524 | } 2525 | #newapphint785 a:link, #newapphint785 a:visited { 2526 | color:white; 2527 | text-decoration:none 2528 | } 2529 | #newapphint785 a:hover { 2530 | color:#b0ae10; 2531 | text-decoration:none 2532 | } 2533 | #newapphint785 button { 2534 | font-size: large; 2535 | background: #555; 2536 | border: 2px outset #555; 2537 | margin: 3px 10px; 2538 | padding: 2px; 2539 | color: #eee; 2540 | } 2541 | #newapphint785 button:hover { 2542 | border: 2px outset #fff; 2543 | color: #fff; 2544 | } 2545 | ` 2546 | document.head.appendChild(style) 2547 | } 2548 | 2549 | const container = document.createElement('div') 2550 | container.id = 'newapphint785' 2551 | document.body.appendChild(container) 2552 | 2553 | const h2 = container.appendChild(document.createElement('h2')) 2554 | h2.textContent = '⚠️ Youtube Genius Lyrics 🆕' 2555 | const p = container.appendChild(document.createElement('p')) 2556 | p.textContent = '▶️ The "Youtube Genius Lyrics" UserScript is only applied on youtube.com. To view Genius lyrics on music.youtube.com, please install the separate UserScript, "Youtube Music Genius Lyrics".' 2557 | p.appendChild(document.createElement('br')) 2558 | p.appendChild(document.createElement('br')) 2559 | 2560 | const aSource = p.appendChild(document.createElement('a')) 2561 | aSource.target = '_blank' 2562 | aSource.href = 'https://greasyfork.org/en/scripts/406892-youtube-music-genius-lyrics' 2563 | aSource.textContent = '📑 https://greasyfork.org/en/scripts/406892-youtube-music-genius-lyrics' 2564 | 2565 | p.appendChild(document.createElement('br')) 2566 | p.appendChild(document.createElement('br')) 2567 | 2568 | const aInstall = p.appendChild(document.createElement('a')) 2569 | aInstall.href = 'https://greasyfork.org/scripts/406892-youtube-music-genius-lyrics/code/Youtube%20Music%20Genius%20Lyrics.user.js' 2570 | aInstall.textContent = '💘 Click to install new script' 2571 | aInstall.addEventListener('click', function () { 2572 | GM.setValue('newapphint', -1).then(function () { 2573 | aInstall.textContent = 'ℹ️ Please reload (F5) the page after installing' 2574 | }) 2575 | }) 2576 | 2577 | p.appendChild(document.createElement('br')) 2578 | p.appendChild(document.createElement('br')) 2579 | 2580 | const remindMeLater = container.appendChild(document.createElement('button')) 2581 | remindMeLater.textContent = '🔜 Remind me later' 2582 | remindMeLater.addEventListener('click', function () { 2583 | GM.setValue('newapphint', 1).then(() => container.remove()) 2584 | }) 2585 | 2586 | container.appendChild(document.createElement('br')) 2587 | 2588 | const doNotShowAgain = container.appendChild(document.createElement('button')) 2589 | doNotShowAgain.textContent = '🆗🆒 Do not show again' 2590 | doNotShowAgain.addEventListener('click', function () { 2591 | GM.setValue('newapphint', -1).then(() => container.remove()) 2592 | }) 2593 | 2594 | setTimeout(function () { 2595 | container.style.left = `calc(50% - ${container.clientWidth / 2}px)` 2596 | container.style.top = `calc(50% - ${container.clientHeight / 2}px)` 2597 | }, 100) 2598 | } else if (status > 0) { 2599 | GM.setValue('newapphint', status + 1) 2600 | } 2601 | } 2602 | 2603 | function entryPoint () { 2604 | genius = null 2605 | let isInIframe = null 2606 | try { 2607 | isInIframe = top && window && top.constructor.name === 'Window' && window.constructor.name === 'Window' && top !== window 2608 | } catch (e) { } 2609 | const isRobotsTxt = document.location.href.indexOf('robots.txt') >= 0 2610 | if (document.location.hostname.startsWith('music')) { 2611 | if (isRobotsTxt || isInIframe) return 2612 | GM.getValue('newapphint', 0).then(function (status) { 2613 | setTimeout(() => newAppHint(status), 5000) 2614 | }) 2615 | } else { 2616 | const setupMain = isRobotsTxt 2617 | ? function setupMain () { 2618 | // do nothing 2619 | } 2620 | : function setupMain () { 2621 | const mPageLoadId = pageLoadId 2622 | requestAnimationFrame(() => { 2623 | if (mPageLoadId !== pageLoadId) return 2624 | executeMainWhenVisible(600, mPageLoadId) 2625 | }) 2626 | document.removeEventListener('yt-navigate-finish', delayedMain, false) 2627 | document.addEventListener('yt-navigate-finish', delayedMain, false) 2628 | isYouTubeLiveFn() 2629 | } 2630 | if (isInIframe && !isRobotsTxt) return 2631 | 2632 | let defaultOptions = null 2633 | try { 2634 | defaultOptions = sessionStorage[`geniusOptions_${SCRIPT_NAME}`] 2635 | if (defaultOptions) defaultOptions = JSON.parse(defaultOptions) 2636 | } catch (e) { } 2637 | 2638 | // should it be required for robots.txt as well?? can remove?? 2639 | genius = geniusLyrics({ 2640 | GM, 2641 | scriptName: SCRIPT_NAME, 2642 | scriptIssuesURL: 'https://github.com/cvzi/Youtube-Genius-Lyrics-userscript/issues', 2643 | scriptIssuesTitle: 'Report problem: github.com/cvzi/Youtube-Genius-Lyrics-userscript/issues', 2644 | domain: 'https://www.youtube.com/', 2645 | emptyURL: 'https://www.youtube.com/robots.txt', 2646 | main, 2647 | setupMain, 2648 | addCss, 2649 | getHitOfElement, 2650 | listSongs, 2651 | showSearchField, 2652 | setupLyricsDisplayDOM, 2653 | addLyrics, 2654 | hideLyrics, 2655 | getCleanLyricsContainer, 2656 | setFrameDimensions, 2657 | onResize, 2658 | createSpinner, 2659 | customSpinnerDOM, 2660 | iframeLoadedCallback1, 2661 | iframeLoadedCallback2, 2662 | autoSelectLyrics, 2663 | defaultOptions 2664 | }) 2665 | 2666 | if (isRobotsTxt !== false || genius === null || !genius.option) return 2667 | GM.registerMenuCommand(SCRIPT_NAME + ' - Show lyrics', () => addLyrics(true)) 2668 | 2669 | function videoTimeUpdate (ev) { 2670 | if (genius.f.isScrollLyricsCallable()) { 2671 | if ((ev || 0).target.nodeName === 'VIDEO') updateAutoScroll() 2672 | } 2673 | } 2674 | document.addEventListener('genius-lyrics-actor', (ev) => { 2675 | const detail = ((ev || 0).detail || 0) 2676 | const action = detail.action || '' 2677 | if (action === 'hideLyrics') { 2678 | hideLyricsWithMessageAndStopAutoShow() 2679 | } else if (action === 'showLyrics') { 2680 | showLyricsButtonClicked() 2681 | } else if (action === 'reloadCurrentLyrics') { 2682 | genius.f.reloadCurrentLyrics() 2683 | } else if (action === 'forgetCurrentLyricsSelection') { 2684 | genius.f.forgetCurrentLyricsSelection() 2685 | } else if (action === 'setOption' && typeof detail.prop === 'string' && 'value' in detail) { 2686 | genius.option[detail.prop] = detail.value 2687 | } 2688 | }) 2689 | window.addEventListener('message', function (e) { 2690 | const data = ((e || 0).data || 0) 2691 | if (data.iAm === SCRIPT_NAME && data.type === 'lyricsDisplayState') { 2692 | let isScrollLyricsEnabled = false 2693 | if (data.visibility !== 'loading') { 2694 | const c = document.querySelector('#lyricscontainer.youtube-genius-lyrics-loading-container') 2695 | if (c) { 2696 | c.classList.remove('youtube-genius-lyrics-loading-container') 2697 | if (data.visibility === 'loaded') { 2698 | c.classList.add('youtube-genius-lyrics-found-container') 2699 | document.documentElement.setAttribute('youtube-genius-lyrics-container', 'found') 2700 | if (genius.current.compoundTitle) { 2701 | window.lastFetchedQuery = `${genius.current.compoundTitle.replace('\t', ' ')}` 2702 | } 2703 | } else { 2704 | document.documentElement.removeAttribute('youtube-genius-lyrics-container') // ??? 2705 | } 2706 | } 2707 | } else { 2708 | window.lastFetchedQuery = null 2709 | } 2710 | if (data.visibility === 'loaded' && data.lyricsSuccess === true) { 2711 | isScrollLyricsEnabled = genius.f.isScrollLyricsEnabled() 2712 | // 'lyricsDisplayState:loaded' is after isPageAbleForAutoScroll setup in 'iframeContentRendered' 2713 | if (genius.f.isScrollLyricsCallable()) { 2714 | // update scroll position when the iframe is rendered 2715 | updateAutoScroll(null, true) 2716 | } 2717 | } 2718 | lyricsDisplayState = data.visibility 2719 | if (isScrollLyricsEnabled === true) { 2720 | document.addEventListener('timeupdate', videoTimeUpdate, true) 2721 | } else { 2722 | document.removeEventListener('timeupdate', videoTimeUpdate, true) 2723 | } 2724 | } 2725 | }) 2726 | 2727 | function isVideoPlaying (video) { 2728 | return video.currentTime > 0 && !video.paused && !video.ended && video.readyState > video.HAVE_CURRENT_DATA 2729 | } 2730 | document.addEventListener('play', function (ev) { 2731 | const statusCheck = () => isTriggered && lyricsDisplayState === 'hidden' && ((genius || 0).option || 0).autoShow 2732 | if (!statusCheck()) return 2733 | let video = ((ev || 0).target || 0) 2734 | if (video.nodeName === 'VIDEO' && video.matches('#movie_player video[src]')) { 2735 | const mPageLoadId = pageLoadId 2736 | requestAnimationFrame(() => { 2737 | if (mPageLoadId !== pageLoadId) { 2738 | video = null 2739 | return 2740 | } 2741 | setTimeout(() => { 2742 | if (mPageLoadId === pageLoadId) { 2743 | statusCheck() && isVideoPlaying(video) && actionAddLyricsOrButton() 2744 | } 2745 | video = null 2746 | }, 600) 2747 | }) 2748 | } 2749 | }, true) 2750 | 2751 | function autoscrollenabledChanged () { 2752 | // when value is configurated in any tab, this function will be triggered in all tabs by Userscript Manager 2753 | requestAnimationFrame(() => { 2754 | // not execute for all foreground and background tabs, only execute when the tab is visibile / when the tab shows 2755 | genius.f.updateAutoScrollEnabled().then(() => { 2756 | let isScrollLyricsEnabled = false 2757 | if (lyricsDisplayState === 'loaded') { 2758 | isScrollLyricsEnabled = genius.f.isScrollLyricsEnabled() 2759 | } 2760 | if (isScrollLyricsEnabled === true) { 2761 | document.addEventListener('timeupdate', videoTimeUpdate, true) 2762 | } else { 2763 | document.removeEventListener('timeupdate', videoTimeUpdate, true) 2764 | } 2765 | }) 2766 | }) 2767 | } 2768 | 2769 | if (typeof GM_addValueChangeListener === 'function') { 2770 | GM_addValueChangeListener('autoscrollenabled', autoscrollenabledChanged) 2771 | } 2772 | 2773 | function styleIframeContent () { 2774 | if (genius.option.themeKey === 'genius' || genius.option.themeKey === 'geniusReact') { 2775 | genius.style.enabled = true 2776 | genius.style.setup = () => { 2777 | genius.style.setup = null // run once; set variables to genius.styleProps 2778 | 2779 | if (genius.option.themeKey !== 'genius' && genius.option.themeKey !== 'geniusReact') return false 2780 | 2781 | const ytdApp = document.querySelector('ytd-app') 2782 | if (!ytdApp) return 2783 | 2784 | const cStyle = window.getComputedStyle(ytdApp) 2785 | let background = cStyle.getPropertyValue('--yt-spec-base-background') 2786 | let color = cStyle.getPropertyValue('--yt-spec-text-primary') 2787 | // let bbp = cStyle.getPropertyValue('--yt-spec-brand-background-primary') 2788 | // let cfs = cStyle.getPropertyValue('--yt-caption-font-size') 2789 | let slbc = cStyle.getPropertyValue('--ytd-searchbox-legacy-button-color') 2790 | const linkColor = cStyle.getPropertyValue('--yt-spec-call-to-action') || '' 2791 | const annotatedSpanBgColor = cStyle.getPropertyValue('--yt-live-chat-automod-button-background-color') || '' 2792 | const annotatedSpanBgColorActive = cStyle.getPropertyValue('--yt-live-chat-automod-button-background-color-hover') || '' 2793 | 2794 | let fontSize = genius.option.fontSize 2795 | if (genius.option.fontSize) { 2796 | fontSize = `${genius.option.fontSize}px` 2797 | } else { 2798 | const expander = document.querySelector('ytd-expander') 2799 | const menuItem = document.querySelector('ytd-guide-entry-renderer yt-formatted-string') 2800 | if (expander) { 2801 | fontSize = window.getComputedStyle(expander).fontSize 2802 | } else if (menuItem) { 2803 | fontSize = window.getComputedStyle(menuItem).fontSize 2804 | } else { 2805 | fontSize = cStyle.fontSize 2806 | } 2807 | } 2808 | 2809 | if (typeof background === 'string' && typeof color === 'string' && background.length > 3 && color.length > 3) { 2810 | // do nothing 2811 | } else { 2812 | background = null 2813 | color = null 2814 | } 2815 | 2816 | if (typeof fontSize === 'string' && fontSize.length > 2) { 2817 | // do nothing 2818 | } else { 2819 | fontSize = null 2820 | } 2821 | if (typeof slbc === 'string') { 2822 | // do nothing 2823 | } else { 2824 | slbc = null 2825 | } 2826 | 2827 | Object.assign(genius.styleProps, { 2828 | '--egl-background': (background === null ? '' : `${background}`), 2829 | '--egl-color': (color === null ? '' : `${color}`), 2830 | '--egl-font-size': (fontSize === null ? '' : `${fontSize}`), 2831 | '--egl-infobox-background': (slbc === null ? '' : `${slbc}`), 2832 | '--egl-link-color': (`${linkColor}`), 2833 | '--egl-annotated-span-bgcolor': (`${annotatedSpanBgColor}`), 2834 | '--egl-annotated-span-bgcolor-active': (`${annotatedSpanBgColorActive}`) 2835 | }) 2836 | return true 2837 | } 2838 | } else { 2839 | genius.style.enabled = false 2840 | genius.style.setup = null 2841 | } 2842 | } 2843 | 2844 | genius.onThemeChanged.push(styleIframeContent) 2845 | 2846 | Object.assign(genius.minimizeHit, { 2847 | noImageURL: true, 2848 | noFeaturedArtists: true, 2849 | simpleReleaseDate: true, 2850 | noRawReleaseDate: true, 2851 | shortenArtistName: true, 2852 | fixArtistName: true, 2853 | removeStats: false, 2854 | noRelatedLinks: true, 2855 | onlyCompleteLyrics: false 2856 | }) 2857 | genius.option.enableStyleSubstitution = true 2858 | genius.option.normalizeClassV2 = true 2859 | genius.option.cacheHTMLRequest = true // 1 lyrics page consume 2XX KB [OR 25 ~ 50KB under ] 2860 | 2861 | // prepare the shared options for the iframe 2862 | try { 2863 | const defaultOptions = Object.fromEntries(Object.entries(genius.option).filter(e => typeof e[1] === 'boolean')) 2864 | sessionStorage[`geniusOptions_${SCRIPT_NAME}`] = JSON.stringify(defaultOptions) 2865 | } catch (e) { } 2866 | document.documentElement.classList.add('youtube-genius-lyrics') 2867 | } 2868 | } 2869 | entryPoint() 2870 | -------------------------------------------------------------------------------- /screenshot-2022-light.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cvzi/Youtube-Genius-Lyrics-userscript/ebc8b9edc9c4b08653f470d6e8cdd0cbdbd08a16/screenshot-2022-light.png -------------------------------------------------------------------------------- /screenshot-2022-tabview-youtube.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cvzi/Youtube-Genius-Lyrics-userscript/ebc8b9edc9c4b08653f470d6e8cdd0cbdbd08a16/screenshot-2022-tabview-youtube.png -------------------------------------------------------------------------------- /screenshot-2022.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cvzi/Youtube-Genius-Lyrics-userscript/ebc8b9edc9c4b08653f470d6e8cdd0cbdbd08a16/screenshot-2022.png -------------------------------------------------------------------------------- /screenshot-dark(spotify).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cvzi/Youtube-Genius-Lyrics-userscript/ebc8b9edc9c4b08653f470d6e8cdd0cbdbd08a16/screenshot-dark(spotify).png -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cvzi/Youtube-Genius-Lyrics-userscript/ebc8b9edc9c4b08653f470d6e8cdd0cbdbd08a16/screenshot.png --------------------------------------------------------------------------------