沉冰浮水

沉冰浮水

做最终到的事,成为最终成为的人!
github
bilibili
mastodon
zhihu
douban

"Experimenting" with writing GM scripts using rollup.js module.

It's May again, which means I can get B coins as a big member. However, Bilibili has made some changes, which means I need to modify the reminder script I wrote before.

"- It's really difficult to determine how detailed the instructions should be -"

Script acquisition and instructions can be found at:

GM Script: Big Member B Coin Reminder_Computer Networking_Chen Bing Fu Shui


2022-09-12:

I created a rollup plugin:

wdssmq/rollup-plugin-monkey: Develop GM Scripts using rollup.js:

Video demonstration:

"Small Code" rollup.js Development of GM Scripts Demonstration_Bilibili:

[https://www.bilibili.com/video/BV1qe4y1d7ZM](https://www.bilibili.com/video/BV1qe4y1d7ZM "Small Code" rollup.js Development of GM Scripts Demonstration_Bilibili")


Until now, I used to put functional scripts for the same website into one file. For example, the script for Bilibili used to have 330 lines, and it was really painful to maintain and modify.

"It seems more convenient to split it into smaller files and automatically concatenate them!" ← Although I think so, I'm just a lazy person...

Fortunately, I finally started to fill this gap not long ago, using the "rollup.js" solution.

The tutorial for rollup.js itself can be found at the end of this article. In fact, the reason I decided to write this article at this time is because Ruan Yifeng happened to write an introduction.


If you also want to use rollup.js to build GM Scripts, you can refer to my usage method:

  • The application environment for GM Scripts is a browser, so the corresponding output format is format: 'iife'.
  • GM Scripts need to include the ==UserScript== …… ==/UserScript== comment at the beginning, which can be concatenated by rollup.js as a banner.
  • The configuration definition file rollup.config.js supports importing content from external sources as parameters, so the value of the banner can be written in a separate file, such as src/__info.js. The name of the script can also be provided by this file.
  • Therefore, different script projects can use the same rollup.config.js content, and only need to modify the definition in src/__info.js.
  • I created an empty_def as the initial project, which includes src/__info.js and src/_base.js, encapsulating various "initial constants or functions". "- It just feels like the style is not very consistent -"
  • In src/main.js, you can use import _bcoin from './_bcoin'; to simply concatenate different files together. Although you will get a yellow line saying "Import of non-existent exports", that's exactly how we want to use it.

userscript/empty_def: https://github.com/wdssmq/userscript/tree/master/empty_def

userscript/bilibili: https://github.com/wdssmq/userscript/tree/master/bilibili "- Due to historical reasons, the exported file is still later.user.js. Should I change it?"

Latest B Coin Reminder: https://github.com/wdssmq/userscript/blob/master/bilibili/src/_bcoin.js "- It's just a reminder and cannot automatically claim the coins"


Getting Started with Rollup.js - Ruan Yifeng's Blog:

http://www.ruanyifeng.com/blog/2022/05/rollup.html

Module Syntax - ES6 Tutorial - WangDoc:

https://wangdoc.com/es6/module.html

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.