quoid / userscripts

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

URLs to local network machine + port number #301

Closed robinwit closed 2 years ago

robinwit commented 2 years ago

System Information:

macOS version: 12.5 (21G72) Userscripts version: 4.2.2 Safari version: 15.6 (17613.3.9.1.5) Is this issue related to script injection? I think so Did the test script (pasted above) successfully run on your machine? Yes

Injection doesn't seem to work for url's pointing to a machine on the local network, could be related to the port number as well. This is the output from the script:

This is a test script - http://syno:8112/

My user stylesheet:

/* ==UserStyle==
@name        Deluge
@description 
@match       http://syno:8112/*
==/UserStyle== */
@import "https://theme-park.dev/css/base/deluge/organizr.css";

Combinations I tried for @match:

The only thing that works is <all_urls> .

quoid commented 2 years ago

@robinwit ports are ignored with match patterns, meaning you get access to all ports

http://syno.local/* should work

if it doesn't let me know and alternatively you could use a regex pattern with @include

robinwit commented 2 years ago

@include works with http://syno:8112/*, thanks! Could have found that, thanks for taking the time to reply. @match didn't work with either of these:

quoid commented 2 years ago

@robinwit

What was the url of the page you were trying to match to?

Ports should simply be ignored with @match. The url props for http://syno.local:8112/foo would be:

["href": "http://syno.local:8112/foo", "pathname": "/foo", "protocol": "http:", "host": "syno.local"]

which should match against the following pattern: http://syno.local/*

robinwit commented 2 years ago

Oh… It gets more interesting… :D

@match http://syno.local/* works when visiting http://syno.local:8112 (I must have visited the url without .local before) @match http://syno/* does not work when visiting http://syno:8112

But actually, I have other services running on other ports, so I really need to be able to include the port.

quoid commented 2 years ago

@match http://syno/* does not work when visiting http://syno:8112

In the current implementation, you can only omit the .tld if you are using a singular wildcard *. Examples of valid match patterns:

Something like http://syno/* would be seen as an invalid pattern with the current implementation. I believe the change would be marginal to allow for patterns like that or, say, *://localhost/* - however ports will always be ignored with @match.

You can see the regex for the match parts here: ^(http:|https:|\*:)\/\/((?:\*\.)?(?:[a-z0-9-]+\.)+(?:[a-z0-9]+)|\*\.[a-z]+|\*)(\/[^\s]*)$

Changing that to the following, should allow for hosts without .tld: ^(http:|https:|\*:)\/\/((?:\*\.)?(?:[a-z0-9-]+\.)+(?:[a-z0-9]+)|\*\.[a-z]+|\*|[a-z0-9]+)(\/[^\s]*)$ - this would give us the following host patterns:

We probably should allow hosts without .tld

quoid commented 2 years ago

updates in beta build ^