Skip to content
Merged

4.2.1 #289

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ Userscripts Safari currently supports the following userscript metadata:
- `@exclude` - Functions in a similar way as `@include` but rather than injecting, a match against this key's value will prevent injection
- `@inject-into` - allows the user to choose which context to inject the script into
- allows the user to choose which context to inject the script into
- values: `auto` (default), `content`, `page`
- values: `auto`, `content` (default), `page`
- `GM` apis are only available when using `content`
- works like [violentmonkey](https://violentmonkey.github.io/api/metadata-block/#inject-into)
- `@run-at`
- allows the user to choose the injection timing
Expand Down
49 changes: 33 additions & 16 deletions etc/app_ios/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 30 additions & 13 deletions extension/Userscripts Extension/Functions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,34 @@ func openSaveLocation() -> Bool {
}

func validateUrl(_ urlString: String) -> Bool {
var urlChecked = urlString
// if the url is already encoded, decode it
if isEncoded(urlChecked) {
if let decodedUrl = urlChecked.removingPercentEncoding {
urlChecked = decodedUrl
} else {
err("validateUrl failed at (1), couldn't decode url, \(urlString)")
return false
}
}
// encode all urls strings
if let encodedUrl = urlChecked.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) {
urlChecked = encodedUrl
} else {
err("validateUrl failed at (2), couldn't percent encode url, \(urlString)")
return false
}
guard
let parts = getUrlProps(urlChecked),
let ptcl = parts["protocol"],
let path = parts["pathname"]
else {
err("validateUrl failed at (3) for \(urlString)")
return false
}
if
(!urlString.hasPrefix("https://") && !urlString.hasPrefix("http://"))
|| (!urlString.hasSuffix(".css") && !urlString.hasSuffix(".js"))
(ptcl != "https:" && ptcl != "http:")
|| (!path.hasSuffix(".css") && !path.hasSuffix(".js"))
{
return false
}
Expand Down Expand Up @@ -520,8 +545,6 @@ func updateManifestDeclarativeNetRequests(_ optionalFilesArray: [[String: Any]]
if fn == filename, let index = manifest.match[pattern]?.firstIndex(of: filename) {
manifest.match[pattern]?.remove(at: index)
update = true
} else {
err("updateManifestDeclarativeNetRequests failed at (2), \(filename)")
}
}
}
Expand All @@ -530,8 +553,6 @@ func updateManifestDeclarativeNetRequests(_ optionalFilesArray: [[String: Any]]
if fn == filename, let index = manifest.excludeMatch[pattern]?.firstIndex(of: filename) {
manifest.excludeMatch[pattern]?.remove(at: index)
update = true
} else {
err("updateManifestDeclarativeNetRequests failed at (3), \(filename)")
}
}
}
Expand All @@ -540,8 +561,6 @@ func updateManifestDeclarativeNetRequests(_ optionalFilesArray: [[String: Any]]
if fn == filename, let index = manifest.include[pattern]?.firstIndex(of: filename) {
manifest.include[pattern]?.remove(at: index)
update = true
} else {
err("updateManifestDeclarativeNetRequests failed at (4), \(filename)")
}
}
}
Expand All @@ -550,13 +569,11 @@ func updateManifestDeclarativeNetRequests(_ optionalFilesArray: [[String: Any]]
if fn == filename, let index = manifest.exclude[pattern]?.firstIndex(of: filename) {
manifest.exclude[pattern]?.remove(at: index)
update = true
} else {
err("updateManifestDeclarativeNetRequests failed at (5), \(filename)")
}
}
}
if update, !updateManifest(with: manifest) {
err("updateManifestDeclarativeNetRequests failed at (6)")
err("updateManifestDeclarativeNetRequests failed at (2)")
return false
}
}
Expand Down Expand Up @@ -1255,12 +1272,12 @@ func getCode(_ filenames: [String], _ isTop: Bool)-> [String: Any]? {
weight = normalizeWeight(weight)

// get inject-into and set default if missing
var injectInto = metadata["inject-into"]?[0] ?? "auto"
var injectInto = metadata["inject-into"]?[0] ?? "content"
let injectVals: Set<String> = ["auto", "content", "page"]
let runAtVals: Set<String> = ["context-menu", "document-start", "document-end", "document-idle"]
// if either is invalid use default value
if !injectVals.contains(injectInto) {
injectInto = "auto"
injectInto = "content"
}
if !runAtVals.contains(runAt) {
runAt = "document-end"
Expand Down
27 changes: 26 additions & 1 deletion extension/Userscripts Extension/Resources/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ browser.runtime.sendMessage({name: "REQ_USERSCRIPTS", uid: uid}, response => {
data = response;
for (let i = 0; i < data.files.js.length; i++) {
const userscript = data.files.js[i];
if (
userscript.scriptObject?.grants?.length
&& (
userscript.scriptObject["inject-into"] === "auto"
|| userscript.scriptObject["inject-into"] === "page"
)
) {
userscript.scriptObject["inject-into"] = "content";
console.warn(`${userscript.scriptObject.filename} had it's @inject-value automatically set to "content" because it has @grant values - see: https://github.com/quoid/userscripts/issues/252#issuecomment-1136637700`);
}
processJS(
userscript.scriptObject.name,
userscript.scriptObject.filename,
Expand Down Expand Up @@ -90,7 +100,22 @@ function injectJS(name, filename, code, scope, fallback) {

function injectCSS(name, code) {
console.info(`Injecting ${name} %c(css)`, "color: #60f36c");
browser.runtime.sendMessage({name: "API_ADD_STYLE_SYNC", css: code});
// Safari lacks full support for tabs.insertCSS
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/insertCSS
// specifically frameId and cssOrigin
// if support for those details keys arrives, the method below can be used
// NOTE: manifest V3 does support frameId, but not origin
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/scripting/insertCSS

// browser.runtime.sendMessage({name: "API_ADD_STYLE_SYNC", css: code});

// write the css code to head of the document
let wrapper = "const tag = document.createElement(\"style\");\n";
wrapper += `tag.textContent = \`${code}\`;`;
wrapper += "\ndocument.head.appendChild(tag);";
// eval the code directly into the context of the content script (not page context)
// wrapper += "console.log(window.browser)"; // this validates the execution env
eval(wrapper);
}

function cspFallback(e) {
Expand Down
2 changes: 1 addition & 1 deletion extension/Userscripts Extension/Resources/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"default_locale": "en",
"name": "__MSG_extension_name__",
"description": "__MSG_extension_description__",
"version": "4.2.0",
"version": "4.2.1",
"icons": {
"48": "images/icon-48.png",
"96": "images/icon-96.png",
Expand Down
32 changes: 16 additions & 16 deletions extension/Userscripts.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@
CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
CODE_SIGN_ENTITLEMENTS = "Userscripts-iOS/Userscripts-iOS.entitlements";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 24;
CURRENT_PROJECT_VERSION = 26;
DEVELOPMENT_TEAM = J74Q8V8V8N;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "Userscripts-iOS/Info.plist";
Expand All @@ -679,7 +679,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.2;
MARKETING_VERSION = 1.2.1;
OTHER_LDFLAGS = (
"-framework",
SafariServices,
Expand All @@ -704,7 +704,7 @@
CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
CODE_SIGN_ENTITLEMENTS = "Userscripts-iOS/Userscripts-iOS.entitlements";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 24;
CURRENT_PROJECT_VERSION = 26;
DEVELOPMENT_TEAM = J74Q8V8V8N;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "Userscripts-iOS/Info.plist";
Expand All @@ -720,7 +720,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.2;
MARKETING_VERSION = 1.2.1;
OTHER_LDFLAGS = (
"-framework",
SafariServices,
Expand All @@ -743,7 +743,7 @@
CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
CODE_SIGN_ENTITLEMENTS = "Userscripts-iOS Extension/Userscripts-iOS Extension.entitlements";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 24;
CURRENT_PROJECT_VERSION = 26;
DEVELOPMENT_TEAM = J74Q8V8V8N;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "Userscripts-iOS Extension/Info.plist";
Expand All @@ -755,7 +755,7 @@
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 1.2;
MARKETING_VERSION = 1.2.1;
OTHER_LDFLAGS = (
"-framework",
SafariServices,
Expand All @@ -776,7 +776,7 @@
CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
CODE_SIGN_ENTITLEMENTS = "Userscripts-iOS Extension/Userscripts-iOS Extension.entitlements";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 24;
CURRENT_PROJECT_VERSION = 26;
DEVELOPMENT_TEAM = J74Q8V8V8N;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "Userscripts-iOS Extension/Info.plist";
Expand All @@ -788,7 +788,7 @@
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 1.2;
MARKETING_VERSION = 1.2.1;
OTHER_LDFLAGS = (
"-framework",
SafariServices,
Expand Down Expand Up @@ -929,7 +929,7 @@
CODE_SIGN_ENTITLEMENTS = "Userscripts Extension/Userscripts Extension.entitlements";
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 52;
CURRENT_PROJECT_VERSION = 54;
DEVELOPMENT_TEAM = J74Q8V8V8N;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = "Userscripts Extension/Info.plist";
Expand All @@ -939,7 +939,7 @@
"@executable_path/../../../../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 4.2.0;
MARKETING_VERSION = 4.2.1;
PRODUCT_BUNDLE_IDENTIFIER = "com.userscripts.macos.Userscripts-Extension";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
Expand All @@ -953,7 +953,7 @@
CODE_SIGN_ENTITLEMENTS = "Userscripts Extension/Userscripts Extension.entitlements";
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 52;
CURRENT_PROJECT_VERSION = 54;
DEVELOPMENT_TEAM = J74Q8V8V8N;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = "Userscripts Extension/Info.plist";
Expand All @@ -963,7 +963,7 @@
"@executable_path/../../../../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 4.2.0;
MARKETING_VERSION = 4.2.1;
PRODUCT_BUNDLE_IDENTIFIER = "com.userscripts.macos.Userscripts-Extension";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
Expand All @@ -980,7 +980,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 52;
CURRENT_PROJECT_VERSION = 54;
DEVELOPMENT_TEAM = J74Q8V8V8N;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = Userscripts/Info.plist;
Expand All @@ -989,7 +989,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 4.2.0;
MARKETING_VERSION = 4.2.1;
PRODUCT_BUNDLE_IDENTIFIER = com.userscripts.macos;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand All @@ -1005,7 +1005,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 52;
CURRENT_PROJECT_VERSION = 54;
DEVELOPMENT_TEAM = J74Q8V8V8N;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = Userscripts/Info.plist;
Expand All @@ -1014,7 +1014,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 4.2.0;
MARKETING_VERSION = 4.2.1;
PRODUCT_BUNDLE_IDENTIFIER = com.userscripts.macos;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand Down
Loading