Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite in a structured manner #12

Open
qsniyg opened this issue Sep 7, 2018 · 0 comments
Open

Rewrite in a structured manner #12

qsniyg opened this issue Sep 7, 2018 · 0 comments
Labels
enhancement New feature or request topic:userscript
Milestone

Comments

@qsniyg
Copy link
Owner

qsniyg commented Sep 7, 2018

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:
{
    domain: "abc.com",
    tests: [
        {start: "...", end: "..."}
    ]
}
  • 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.

If you're curious, this is a quick explanation as to why it was written the way it was.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request topic:userscript
Projects
None yet
Development

No branches or pull requests

1 participant