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

Make the background script insert custom CSS #72

Open
astral-sa opened this issue Jan 27, 2018 · 1 comment
Open

Make the background script insert custom CSS #72

astral-sa opened this issue Jan 27, 2018 · 1 comment
Assignees

Comments

@astral-sa
Copy link
Collaborator

astral-sa commented Jan 27, 2018

A lot of the javascript logic, preference checking, and expensive individual element style setting that executes every page load (for every post) can be converted to some CSS that we generate once in the background page and insert into tabs as necessary with tabs.insertCSS().

Ideally I'd like to configure the background page to be persistent rather than event (event pages aren't even supported on Firefox, so on Firefox it's already persistent). It may even be acting as persistent on Chrome with the way it's listening for messages. If we make the background page officially persistent, it could generate the CSS once on extension load (and, subsequently, if any preference that would affect styles is modified in the settings) and keep a copy of it in memory. Then, when an SA forum page is loaded, it can inject the relevant CSS immediately. There would be separate CSS sets for different forum contexts (showthread and forumdisplay+usercp would be the two main ones)

Another option could be to store the computed CSS strings somewhere else, perhaps storage.local, but there it would count against the 5MB limit and have to get loaded out of storage each page load, which would slow things down somewhat.

Yet another option is for the background page to compute it on page load, but this, too, is less than ideal.

This feature will also helpfully reduce the amount of stuff that needs to be converted from jQuery in the main part of the extension. It will make things nicer for the users with SALR's style changes applying more quickly and with fewer reflows. The result of this feature will be most noticeable for options like thread highlighting where a lot of CSS is applied.

@astral-sa
Copy link
Collaborator Author

Doing it this way will require adding a host permission to the manifest for *://forums.somethingawful.com/*.

This will result in a dialog requesting additional permissions when the extension updates; not sure how big a deal that is, but it'd be worth it for the performance gains.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant