How to add JavaScript code in Hexo without modifying theme files

I use the next theme, but I don’t want to modify the source files, so I use git submodule to check out the next theme. However, I want to add some JavaScript code to the page.

Actually, if you look at _config.next.yml, you will find out how to change it.

  • Create a _data folder under source
  • Create a footer.swig file under the _data folder
  • Add your JavaScript code to the footer.swig file
  • Change custom_file_path in _config.next.yml and add the footer.swig file to it

Done~
I simply added the coinimp code, and it was blocked by AdBlock as expected. Anyway, it is only for testing. Adjusted the throttle to 0.1 and turned on the prompt. If it’s blocked, let it be blocked…