post-build.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. const { readFile, writeFile } = require("fs/promises");
  2. const package = require("../package.json");
  3. const userscriptName = "BetterYTM.user.js";
  4. const url = package.repository.url.replace("git+", "").replace(".git", "");
  5. const scriptUrl = package.repository.url.replace("git+", "").replace(".git", "") + "/raw/main/" + userscriptName;
  6. const header = `// ==UserScript==
  7. // @name BetterYTM
  8. // @homepageURL ${package.homepage}
  9. // @namespace ${url}
  10. // @version ${package.version}
  11. // @description Improvements for YouTube Music
  12. // @description:de Verbesserungen für YouTube Music
  13. // @license ${package.license}
  14. // @author ${package.author.name}
  15. // @copyright ${package.author.name} <${package.author.email}>
  16. // @match https://music.youtube.com/*
  17. // @match https://www.youtube.com/*
  18. // @icon https://raw.githubusercontent.com/Sv443/BetterYTM/main/resources/icon/v2.1_200.png
  19. // @run-at document-start
  20. // @grant GM.getValue
  21. // @grant GM.setValue
  22. // @connect self
  23. // @connect youtube.com
  24. // @connect github.com
  25. // @connect githubusercontent.com
  26. // @downloadURL ${scriptUrl}
  27. // @updateURL ${scriptUrl}
  28. // ==/UserScript==
  29. /*
  30. ▄▄▄ ▄ ▄▄▄▄▄▄ ▄
  31. █ █ ▄▄▄ █ █ ▄▄▄ ▄ ▄█ █ █ █▀▄▀█
  32. █▀▀▄ █▄█ █▀ █▀ █▄█ █▀ █ █ █ █
  33. █▄▄▀ █▄▄ █▄▄ █▄▄ █▄▄ █ █ █ █ █
  34. Made with ❤️ by Sv443
  35. I welcome every contribution on GitHub! */
  36. /* Disclaimer: I am not affiliated with YouTube, Google, Alphabet, Genius or anyone else */
  37. /* C&D this 🖕 */
  38. `;
  39. (async () => {
  40. try {
  41. const path = `./${userscriptName}`;
  42. const input = String(await readFile(path));
  43. await writeFile(path, `${header}\n${input}${input.endsWith("\n") ? "" : "\n"}`);
  44. console.info("Successfully added the userscript header!");
  45. }
  46. catch(err) {
  47. console.error("Error while adding userscript header:");
  48. console.error(err);
  49. process.exit(1);
  50. }
  51. })();