Scratchaddons: Userscript autorefresh

Created on 18 Nov 2020  路  10Comments  路  Source: ScratchAddons/ScratchAddons

In the same way theme userstyles (most times) autorefresh, it would be cool if userscripts could do that too, specially theme userscripts. This would mean users could instantly try themes like "colored context menus" without refreshing the page.
Together with this, it would be nice to allow any userscript to be aware if they were disabled (for example, the "discuss button" addon could remove it from the navbar after being disabled, and the "editor stage left" could remove its "share the love" fix dynamically, meaning toggling the addon wouldn't need a refresh)

core enhancement

Most helpful comment

as then the addon api would need to figure out how to undo all the changes

This is not what I suggested. Addons are the one in charge of undoing their own changes.

All 10 comments

So part of the userscript would need to tell it how to undo its changes?

This would be useful for #415, so it could automatically determine if onprimary needs to be light or dark based on the primary color.

I think rather than autorefreshing - as then the addon api would need to figure out how to undo all the changes, I think it would be better to encourage the use of the settings change event, and add enable/disable events, and encourage the use of those.

as then the addon api would need to figure out how to undo all the changes

This is not what I suggested. Addons are the one in charge of undoing their own changes.

Many addons can try to do this, but some addons remove elements from the page so that might be a bit tricky.

Many addons can try to do this, but some addons remove elements from the page so that might be a bit tricky.

They could save the removed elements.

Anyway, enable/disable events @pufferfish101007 suggested would be functionally equivalent so maybe also consider those?

@mxmou Kind of - disable events would work just fine, something like addon.self.addEventListener("disabled", () => {}). However, I think userscripts should opt in into being injected after the page has loaded, not opt out. This is specially important for addons with "runAtComplete": false.

However, I think userscripts should opt in into being injected after the page has loaded, not opt out. This is specially important for addons with "runAtComplete": false.

Isn't listening for an "enable" event opting in?

Isn't listening for an "enable" event opting in?

If a userscript registered an event, then it is already running, so not really. By enable, I mean running userscripts that weren't run on page load. If a user disables an addon, then reenables it, the userscript will simply be ran again - no need to have an "enable" event for those cases.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Touchcreator picture Touchcreator  路  3Comments

scratchusernamemrtbts picture scratchusernamemrtbts  路  9Comments

jeffalo picture jeffalo  路  4Comments

WorldLanguages picture WorldLanguages  路  8Comments

Hans5958 picture Hans5958  路  10Comments