You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Right now, the script works by a very large chain of if blocks. This results in decent performance, but it could be improved, and it can get rather frustrating to debug issues.
Rewriting the script manually would be next to impossible. Instead, since the vast majority of the rules are written in more or less the same way, they could be automatically parsed. The rest would be done manually.
Naively loading the resulting object and parsing it in the script would likely result in a performance nightmare. Instead, it would be compiled in a format similar to this:
switch(domain[0]) {
case 'a':
switch (domain[1]) {
case 'a':
// ...
}
break;
case 'b':
switch (domain[1]) {
case 'a':
// ...
}
break;
// ...
}
Each of the rules could be functions stored in an array.
Problems so far:
Test cases. Not only is it important for the test cases to remain intact, it's also important they remain intact relative to where they were (especially important for larger rules). If they are added as comments, they should somehow still remain near the sites. If they are added as an object (which would allow for automatic tests), they should remain close to the domains, possibly following a format similar to this:
The actual format. How exactly should it be structured?
Ease of development. Right now, the development is quite simple. Adding a layer of compilation would require extra time (unless it was somehow done automatically?). On top of this, the structured format would be more verbose, and therefore require more time to develop for. Alternatively, a custom format could be created, akin to Adblock.
Usefulness. Is the outcome really worth all this effort? While it would be undeniably better, this is quite a simple script. The current method is acceptably fast (it can process a couple thousand different URLs in a matter of seconds), and development is quite efficient.
2MB Limit. This might make the userscript go over the 2MB limit imposed by Greasyfork. One way to get around this could be to download and compile rules on the fly.
Right now, the script works by a very large chain of if blocks. This results in decent performance, but it could be improved, and it can get rather frustrating to debug issues.
Rewriting the script manually would be next to impossible. Instead, since the vast majority of the rules are written in more or less the same way, they could be automatically parsed. The rest would be done manually.
Naively loading the resulting object and parsing it in the script would likely result in a performance nightmare. Instead, it would be compiled in a format similar to this:
Each of the rules could be functions stored in an array.
Problems so far:
If you're curious, this is a quick explanation as to why it was written the way it was.
The text was updated successfully, but these errors were encountered: