ACTCD / userscripts-lab

An open-source userscript manager for Safari
https://quoid.github.io/userscripts/
GNU General Public License v3.0
23 stars 0 forks source link

Userscripts Safari

An open-source userscript editor for Safari

Userscripts Safari

Table of Contents

Installation

Userscripts is available for iOS (+ipadOS) and macOS. For all versions, installation is done through Apple's App Store. On macOS, versions prior to 4.x were made available to download and install directly from the repository, but due to changes in the way Apple allows developers to distribute apps built with the WebExtension API, that is no longer an option.

To run Userscripts on iOS you should be on iOS 15.1 or higher.

To run Userscripts on macOS you should running macOS 12 or higher, along with Safari 14.1 or higher.

App Store Link

Development Progress

Usage

It's recommend to read this documentation and, if you have time, watch the following video overviews to familiarize yourself with the app and extension.

Once the app is downloaded and installed the following steps should be taken:

iOS

macOS

After installing Userscripts on macOS, you do not need to select a userscripts directory if you do not plan on syncing your userscripts between multiple devices. Instead you can choose to use the default directory, which is located at ~/User/Library/Containers/Userscripts/Data/Documents/scripts - again, this is default (and automatic) behavior. You only need to select a new location if you want to store your userscripts elsewhere, which is especially useful if you are using an external code editor such as Sublime Text or VSCode.

Here's a short clip showing how to easily create/add a userscript in Safari using this extension on macOS

UI Overview

Browser Page:

Userscripts Safari Main Application Window

  1. Extension button - click this button to open the extension interface
  2. Filter bar - use this input to filter items in the sidebar, by name
  3. Sort button - changes the order of the items in the sidebar by name or modified time
  4. Sidebar buttons - described left to right
    • The settings button (represented by a cog) displays the settings modal (discussed below)
    • The plus button allows users to add new items
      • New CSS is a "userscript" that expects CSS code
      • New Javascript is a prototypical userscript that expects Javascript code
      • New Remote allows the user to add a remote hosted userscript (or style) by inputting the web address (ex: https://www.k21p.com/example.user.js)
  5. Item toggle - this toggle enables or disables an item
  6. Item - this is the userscript (or style), clicking on it will load it's contents into the editor - you can hide descriptions in the settings area!
  7. Editor buttons (top) - described left to right
    • Update button - this button allows you to update userscripts that meet the following conditions
      • metadata contains @version tag
      • metadata contains @updateURL tag
    • Download button - click this button to download a copy of your userscript
      • Note: every userscript that is displayed in the interface is already present on your local machine, at your save location - the download button offers a quick way to retrieve a copy of that file, without needing to click the settings button, and then the save location link within the settings modal
    • Trash button - moves the currently loaded userscript to the trash bin - it will subsequently be removed from the interface and save location
  8. Editor buttons (bottom)
    • Discard - while editing, reverts any unsaved changes you've made to a userscript
    • Save - while editing, saves all changes you've made to a userscript
      • Command + S is the keyboard shortcut for the action

Settings Modal:

Userscripts Safari Settings Window

Popup:

  1. Open Page Link - macOS only, opens the extension browser page
  2. Enable Injection toggle - turns on/off page script injection (on/off switch)
  3. Refresh View - refreshes the popup view
  4. Available Updates View - the extension periodically checks all userscripts in your save location for updates and when an update is found, it is shown in this view
  5. Folder Button - on macOS this button opens your save location directory in Finder, on iOS this button displays the "all scripts view" where you can see every script that found in your save location directory, the "all scripts view" allows you to toggle individual userscript scripts on/off regardless of the current page being displayed in the browser
  6. Install Prompt - when a userscript is displayed in the browser, this alert displays, giving the user the option to install the userscript into their save location directory, tapping the prompt will take them through the installation steps
  7. Matched Userscripts List - this list shows the currently matched userscripts relative to the current page being displayed in the browser, all userscripts that match to the domain will be showed, whether they are active or not. Users can click/tap the userscript to the toggle them on/off. If a userscript is active for the domain through a subframe a sub tag will be show next the to the file type indicator

Metadata

Userscripts Safari currently supports the following userscript metadata:

All userscripts need at least 1 @match or @include to run!

API

Userscripts currently supports the following api methods. All methods are asynchronous unless otherwise noted. Users must @grant these methods in order to use them in a userscript. When using API methods, it's only possible to inject into the content script scope due to security concerns.

Scripts Directory

This is the directory where the app/extension will read from and write to. This directory is changed by opening the containing app and clicking the respective "change location" button.

Script Directory Notes

Getting Help

If you encounter a problem while using this app/extension or are in need of some assistance, please open an issue here in the repository. When doing so, please provide as much detail as possible. This includes listing system specs and what website and script you are trying to execute. Please follow the issue template!

FAQs

"Refused to execute a script" error(s), what should I do!?

You are seeing this error because of the website's Content Security Policy. Currently there is no way to allow extension content scripts to bypass CSPs in Safari.

Automatically, the extension will attempt to circumvent strict CSPs, but if you are still experiencing issues, trying setting the userscript metadata key/val // @inject-into auto or // @inject-into content.

You can read more about this in this issue.

Do I need to use the extension's editor to create new userscripts or to edit existing?

You can use your own editor to update and manage your files. As long as you are saving the files to the save location, and they are properly formatted, they should be injected. However, you must open the extension popup beforehand. That means, if you create a new or edit an existing userscript with an external editor and save it to the save location, before injection will occur properly, the extension popup must be opened and the popup must load completely.

What are the keyboard shortcuts?

Whilst using the included editor, clicking ⌘ + s will save the file. While working the editor, clicking ⌘ + f will bring up the search bar and esc will hide it.

When I use @require, where are the required files stored?

All required files are saved as Javascript files in the extension container folder in macOS 11.x. That folder is located in the default save location, at: ~/Library/Containers/Userscripts/Data/Documents/require/.

If you move files from the require folder or manually edit the manifest.json file, you will likely break app/extension functionality.

Contributing

Code level contributions are welcome. I prefer to collaborate directly with contributors rather than receiving spontaneous pull requests. If you feel you can improve the project in some way, please reach out to me by email or by opening an issue with your improvement/feature request.

Further, any issue marked "help wanted" is actively seeking assistance. Please respond to those issues with feedback, guidance or offers of coding assistance.

Notes:

Please ensure your contributions align with the project's license before committing anything.

Support

The quickest and easiest way to support the project is by leaving a positive review on the App Store if you enjoy the extension and want to see future improvements. Seeing these reviews let me know I am doing something right, or wrong, and motivates me to continue working on the project.

The second best way to help out is to sign up to beta test new versions of the app. Since this extension values your privacy, and does not collect any data from users, it is difficult to gauge how the extension is being used. By signing up to be a beta tester it not only allows you to test upcoming features, but also gives me the opportunity to elicit direct feedback from real users.

iOS Beta Sign Up Form

macOS Beta Sign Up Form

Privacy Policy

Userscripts does not collect any data from its users nor monitor activities or actions you perform within the application and extension. This means everything that you do with the application and extension is private to you and is never shared with the developers or third parties. Since there is no data collection, there is no data retention of any kind.

License

Copyright (c) 2022 Justin Wasack

Licensed under the GNU General Public License v3.0 license for all open source applications. A commercial license is required for all other applications.