-1

I'm currently developing a userscript that could be in use for a few years after I've left the company. The target audience has basic computer literacy--enough to fill out a simple configuration menu.

I worry that the scripts could break because the IT department could move the webpages I have listed in the @include. I can document how to fix the scripts, but I want to defensively program against IT departments that I know are incredibly incompetent. I know I can do the following:

  • Allow the user to specify URLs in a configuration page.
  • Set the @include to be very generic as https://*.edu/* and use an if statement to determine we're on the user-specified URL using window.location.href before executing commands.

A few concerns about this solution: I want the script to be easily reusable between institutions, which is why I have the *.edu mentioned instead of specificschool.edu. The above configuration would have the script execute on literally every page of any .edu website, but the actions would only occur if they're on the webpage due to the if statement. This seems horribly inefficient, but I understand this may be a tradeoff between ease of portability for efficiency.

Is there any better way to do this?

Decaf-Math
  • 349
  • 3
  • 10
  • *This seems horribly inefficient* Not really - that's exactly what I'd do. (that's what I already do for a few of my userscripts) Given the loads of junk JS that sites already often try to get your machine to run, an extra `if` statement on every pageload is *nothing* to worry about. Easy readability and maintainability is worth far more than optimizing away a fraction of a microsecond. – CertainPerformance Mar 28 '20 at 05:40
  • 1
    All major userscript managers (Tampermonkey, Greasemonkey, Violentmonkey) allow the users to add their own includes/excludes and even override the script's built-in ones. – wOxxOm Mar 28 '20 at 05:44
  • Please, see [Why is “Is it possible to…” a poorly worded question?](https://softwareengineering.meta.stackexchange.com/a/7274/1352) on the meta site of our sister site [softwareengineering.se] as well as [Question closed because yes/no answer](https://meta.stackexchange.com/a/183183/2988) on the overall Stack Exchange meta site to understand why "Yes/No" questions are typically off-topic and what you can do to improve it. Also, questions asking about a "better way" are off-topic for being opinion-based, unless they contain an objectively quantifiable, precise definition of "better". – Jörg W Mittag Mar 28 '20 at 06:14

1 Answers1

0

Allow the user to specify URLs in a configuration page.

As mentioned by wOxxOm, user-script manager e.g. TamperMonkey, GreaseMonkey, ViolentMonkey & FireMoneky (Firefox only), have user settings that users can enter, although that often requires some prior knowledge.

Set the @include to be very generic as https://.edu/ and use an if statement to determine we're on the user-specified URL using window.location.href before executing commands.

That is also possible (although inefficient) but may run into the same issues if the web site changes in such a way that would make the 'if statement' obsolete.

Is there any better way to do this?

Yes...script update system.

If the script is placed on an accessible server (GreasyFork, Github, etc) then an update URL can be set and then script can be automatically or manually updated by the users wherever it fails to function or an update is required.

erosman
  • 7,094
  • 7
  • 27
  • 46