post-build.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. const { readFile, writeFile, stat } = 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("\nSuccessfully added the userscript header");
  45. console.info(`\nFinal size is ${((await stat(path)).size / 1000).toFixed(2)} KB`);
  46. }
  47. catch(err) {
  48. console.error("Error while adding userscript header:");
  49. console.error(err);
  50. setImmediate(() => process.exit(1));
  51. }
  52. })();