post-build.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. /* Disclaimer: I am not affiliated with YouTube, Google, Alphabet, Genius or anyone else */
  30. /* C&D this 🖕 */
  31. `;
  32. (async () => {
  33. try {
  34. const path = `./${userscriptName}`;
  35. const input = String(await readFile(path));
  36. await writeFile(path, `${header}\n${input}${input.endsWith("\n") ? "" : "\n"}`);
  37. console.info("Successfully added the userscript header!");
  38. }
  39. catch(err) {
  40. console.error("Error while adding userscript header:");
  41. console.error(err);
  42. process.exit(1);
  43. }
  44. })();