From 48c75915e2f640a0f1a6cb508246f01c444fff2f Mon Sep 17 00:00:00 2001 From: quoid Date: Mon, 14 Jun 2021 22:01:00 -0400 Subject: [PATCH 01/17] bump version and build numbers --- extension/Userscripts.xcodeproj/project.pbxproj | 16 ++++++++-------- src/dev.js | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/extension/Userscripts.xcodeproj/project.pbxproj b/extension/Userscripts.xcodeproj/project.pbxproj index 87c4dbe6..b324e051 100644 --- a/extension/Userscripts.xcodeproj/project.pbxproj +++ b/extension/Userscripts.xcodeproj/project.pbxproj @@ -417,7 +417,7 @@ CODE_SIGN_ENTITLEMENTS = "Userscripts Extension/Userscripts Extension.entitlements"; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 27; + CURRENT_PROJECT_VERSION = 28; DEVELOPMENT_TEAM = J74Q8V8V8N; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = "Userscripts Extension/Info.plist"; @@ -426,7 +426,7 @@ "@executable_path/../Frameworks", "@executable_path/../../../../Frameworks", ); - MARKETING_VERSION = 3.2.1; + MARKETING_VERSION = 3.2.2; PRODUCT_BUNDLE_IDENTIFIER = "com.userscripts.macos.Userscripts-Extension"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; @@ -440,7 +440,7 @@ CODE_SIGN_ENTITLEMENTS = "Userscripts Extension/Userscripts Extension.entitlements"; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 27; + CURRENT_PROJECT_VERSION = 28; DEVELOPMENT_TEAM = J74Q8V8V8N; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = "Userscripts Extension/Info.plist"; @@ -449,7 +449,7 @@ "@executable_path/../Frameworks", "@executable_path/../../../../Frameworks", ); - MARKETING_VERSION = 3.2.1; + MARKETING_VERSION = 3.2.2; PRODUCT_BUNDLE_IDENTIFIER = "com.userscripts.macos.Userscripts-Extension"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; @@ -466,7 +466,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 27; + CURRENT_PROJECT_VERSION = 28; DEVELOPMENT_TEAM = J74Q8V8V8N; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = Userscripts/Info.plist; @@ -474,7 +474,7 @@ "$(inherited)", "@executable_path/../Frameworks", ); - MARKETING_VERSION = 3.2.1; + MARKETING_VERSION = 3.2.2; PRODUCT_BUNDLE_IDENTIFIER = com.userscripts.macos; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; @@ -490,7 +490,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 27; + CURRENT_PROJECT_VERSION = 28; DEVELOPMENT_TEAM = J74Q8V8V8N; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = Userscripts/Info.plist; @@ -498,7 +498,7 @@ "$(inherited)", "@executable_path/../Frameworks", ); - MARKETING_VERSION = 3.2.1; + MARKETING_VERSION = 3.2.2; PRODUCT_BUNDLE_IDENTIFIER = com.userscripts.macos; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; diff --git a/src/dev.js b/src/dev.js index 207621e4..55a2cdb6 100644 --- a/src/dev.js +++ b/src/dev.js @@ -18,7 +18,7 @@ const defaultSettings = { showCount: "false", sortOrder: "lastModifiedDesc", tabSize: "4", - version: "3.2.1" + version: "3.2.2" }; // example file contents From ccc85b428e480f34ea52677e673bd69f1009894a Mon Sep 17 00:00:00 2001 From: quoid Date: Mon, 14 Jun 2021 22:01:52 -0400 Subject: [PATCH 02/17] update new defaults #142 --- src/utils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils.js b/src/utils.js index b3639b2f..c295a781 100644 --- a/src/utils.js +++ b/src/utils.js @@ -63,9 +63,9 @@ export function validateURL(url) { export function newScriptDefault(description, name, type) { if (type === "css") { - return `/* ==UserStyle==\n@name ${name}\n@description ${description}\n@match *://*.*\n==/UserStyle== */`; + return `/* ==UserStyle==\n@name ${name}\n@description ${description}\n@match \n==/UserStyle== */`; } else if (type === "js") { - return `// ==UserScript==\n// @name ${name}\n// @description ${description}\n// @match *://*.*\n// ==/UserScript==`; + return `// ==UserScript==\n// @name ${name}\n// @description ${description}\n// @match *://*/*\n// ==/UserScript==`; } } From 84b167b8fad07cdac9c07d6ed165032e3ae328d8 Mon Sep 17 00:00:00 2001 From: quoid Date: Tue, 15 Jun 2021 11:56:28 -0400 Subject: [PATCH 03/17] rebuild for #142 --- extension/Userscripts Extension/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension/Userscripts Extension/index.html b/extension/Userscripts Extension/index.html index 2ca4472c..2541a4f5 100644 --- a/extension/Userscripts Extension/index.html +++ b/extension/Userscripts Extension/index.html @@ -1 +1 @@ -Userscripts Safari
\ No newline at end of file +Userscripts Safari
\ No newline at end of file From 8f691c61fc6a11f8938f4130c2d2c3b8c585e28a Mon Sep 17 00:00:00 2001 From: quoid Date: Tue, 15 Jun 2021 11:56:46 -0400 Subject: [PATCH 04/17] update version numbers --- extension/Userscripts.xcodeproj/project.pbxproj | 8 ++++---- src/dev.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/extension/Userscripts.xcodeproj/project.pbxproj b/extension/Userscripts.xcodeproj/project.pbxproj index b324e051..34b951d1 100644 --- a/extension/Userscripts.xcodeproj/project.pbxproj +++ b/extension/Userscripts.xcodeproj/project.pbxproj @@ -426,7 +426,7 @@ "@executable_path/../Frameworks", "@executable_path/../../../../Frameworks", ); - MARKETING_VERSION = 3.2.2; + MARKETING_VERSION = 3.3.0; PRODUCT_BUNDLE_IDENTIFIER = "com.userscripts.macos.Userscripts-Extension"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; @@ -449,7 +449,7 @@ "@executable_path/../Frameworks", "@executable_path/../../../../Frameworks", ); - MARKETING_VERSION = 3.2.2; + MARKETING_VERSION = 3.3.0; PRODUCT_BUNDLE_IDENTIFIER = "com.userscripts.macos.Userscripts-Extension"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; @@ -474,7 +474,7 @@ "$(inherited)", "@executable_path/../Frameworks", ); - MARKETING_VERSION = 3.2.2; + MARKETING_VERSION = 3.3.0; PRODUCT_BUNDLE_IDENTIFIER = com.userscripts.macos; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; @@ -498,7 +498,7 @@ "$(inherited)", "@executable_path/../Frameworks", ); - MARKETING_VERSION = 3.2.2; + MARKETING_VERSION = 3.3.0; PRODUCT_BUNDLE_IDENTIFIER = com.userscripts.macos; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; diff --git a/src/dev.js b/src/dev.js index 55a2cdb6..d952d1f2 100644 --- a/src/dev.js +++ b/src/dev.js @@ -18,7 +18,7 @@ const defaultSettings = { showCount: "false", sortOrder: "lastModifiedDesc", tabSize: "4", - version: "3.2.2" + version: "3.3.0" }; // example file contents From 9aed9d0f510fdec59f9518226be46f450ec7c081 Mon Sep 17 00:00:00 2001 From: quoid Date: Tue, 15 Jun 2021 12:05:44 -0400 Subject: [PATCH 05/17] include func #143 --- .../Userscripts Extension/Functions.swift | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/extension/Userscripts Extension/Functions.swift b/extension/Userscripts Extension/Functions.swift index fbe62b0f..4ea8107a 100644 --- a/extension/Userscripts Extension/Functions.swift +++ b/extension/Userscripts Extension/Functions.swift @@ -1281,6 +1281,28 @@ func match(_ ptcl: String,_ host: String,_ path: String,_ matchPattern: String) return true } +func include(_ url: String,_ pattern: String) -> Bool { + var regex:NSRegularExpression + if pattern.hasPrefix("/") && pattern.hasSuffix("/") { + let p = String(pattern.dropFirst().dropLast()) + guard let exp = try? NSRegularExpression(pattern: p, options: .caseInsensitive) else { + err("invalid regex in include func") + return false + } + regex = exp + } else { + guard let exp = stringToRegex(pattern) else { + err("coudn't convert string to regex in include func") + return false + } + regex = exp + } + if (regex.firstMatch(in: url, options: [], range: NSMakeRange(0, url.utf16.count)) == nil) { + return false + } + return true +} + // popover func updateBadgeCount(_ frames: [[String : Any]]) { guard From 00be8fb6117aa28bdcaa49e8d795ee3715b02803 Mon Sep 17 00:00:00 2001 From: quoid Date: Tue, 15 Jun 2021 12:23:21 -0400 Subject: [PATCH 06/17] update issue template --- ISSUE_TEMPLATE.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md index e5136edf..8228b3d8 100644 --- a/ISSUE_TEMPLATE.md +++ b/ISSUE_TEMPLATE.md @@ -1,14 +1,16 @@ - _System Information:_ From 25bf63e261d921896251a3097d15dab737d0d34d Mon Sep 17 00:00:00 2001 From: quoid Date: Tue, 15 Jun 2021 12:25:43 -0400 Subject: [PATCH 07/17] add sidebar text to display when no description provided --- extension/Userscripts Extension/index.html | 2 +- src/Components/Sidebar/Item.svelte | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/extension/Userscripts Extension/index.html b/extension/Userscripts Extension/index.html index 2541a4f5..822f068a 100644 --- a/extension/Userscripts Extension/index.html +++ b/extension/Userscripts Extension/index.html @@ -1 +1 @@ -Userscripts Safari
\ No newline at end of file +Userscripts Safari
\ No newline at end of file diff --git a/src/Components/Sidebar/Item.svelte b/src/Components/Sidebar/Item.svelte index a7f8ecd6..c242e9e6 100644 --- a/src/Components/Sidebar/Item.svelte +++ b/src/Components/Sidebar/Item.svelte @@ -85,5 +85,5 @@ on:click={e => toggle(e, data)} /> -
{data.description}
+
{data.description || "No description provided"}
From cfa44bb6675a953ca730c2ca08fb77735e8089a0 Mon Sep 17 00:00:00 2001 From: quoid Date: Tue, 15 Jun 2021 12:27:56 -0400 Subject: [PATCH 08/17] rename all references to exclude-match --- .../Userscripts Extension/Functions.swift | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/extension/Userscripts Extension/Functions.swift b/extension/Userscripts Extension/Functions.swift index 4ea8107a..2d33cc7a 100644 --- a/extension/Userscripts Extension/Functions.swift +++ b/extension/Userscripts Extension/Functions.swift @@ -238,12 +238,12 @@ func parse(_ content: String) -> [String: Any]? { struct Manifest: Codable { var blacklist:[String] var disabled:[String] - var exclude: [String: [String]] + var excludeMatch: [String: [String]] var match: [String: [String]] var require: [String: [String]] var settings: [String: String] private enum CodingKeys : String, CodingKey { - case blacklist, disabled, exclude = "exclude-match", match, require, settings + case blacklist, disabled, excludeMatch = "exclude-match", match, require, settings } } @@ -265,7 +265,7 @@ func getManifestKeys() -> Manifest? { let url = getDocumentsDirectory().appendingPathComponent("manifest.json") // if manifest doesn't exist, create new one if !FileManager.default.fileExists(atPath: url.path) { - let manifest = Manifest(blacklist: [], disabled: [], exclude: [:], match: [:], require: [:], settings: [:]) + let manifest = Manifest(blacklist: [], disabled: [], excludeMatch: [:], match: [:], require: [:], settings: [:]) _ = updateManifest(with: manifest) } guard @@ -417,7 +417,7 @@ func updateExcludesAndMatches(_ filename: String,_ excludePatterns: [String],_ m // get updated data for exclude-match and match patternsInFile = excludePatterns - manifestKeys.exclude = updatePatternDict(manifestKeys.exclude) + manifestKeys.excludeMatch = updatePatternDict(manifestKeys.excludeMatch) patternsInFile = matchPatterns manifestKeys.match = updatePatternDict(manifestKeys.match) @@ -482,19 +482,19 @@ func purgeManifest() -> Bool { } } // iterate through manifest excludes - for (pattern, filenames) in manifestKeys.exclude { + for (pattern, filenames) in manifestKeys.excludeMatch { for filename in filenames { if !allSaveLocationFilenames.contains(filename) { - if let index = manifestKeys.exclude[pattern]?.firstIndex(of: filename) { - manifestKeys.exclude[pattern]?.remove(at: index) + if let index = manifestKeys.excludeMatch[pattern]?.firstIndex(of: filename) { + manifestKeys.excludeMatch[pattern]?.remove(at: index) update = true NSLog("Could not find \(filename) in save location, removed from exclude-match pattern - \(pattern)") } } // if there are no more filenames in pattern, remove pattern from manifest - if let length = manifestKeys.exclude[pattern]?.count { - if length < 1, let ind = manifestKeys.exclude.index(forKey: pattern) { - manifestKeys.exclude.remove(at: ind) + if let length = manifestKeys.excludeMatch[pattern]?.count { + if length < 1, let ind = manifestKeys.excludeMatch.index(forKey: pattern) { + manifestKeys.excludeMatch.remove(at: ind) NSLog("No more files for \(pattern) exclude-match pattern, removed from manifest") } } @@ -613,7 +613,7 @@ func getInitData() -> [String: Any]? { var manifestKeys = getManifestKeys() // if manifest missing, improperly formatted or key missing it will be nil, create new manifest if manifestKeys == nil { - manifestKeys = Manifest(blacklist: [], disabled: [], exclude: [:], match: [:], require: [:], settings: [:]) + manifestKeys = Manifest(blacklist: [], disabled: [], excludeMatch: [:], match: [:], require: [:], settings: [:]) if !updateManifest(with: manifestKeys!) { // force unwrap since it was assigned in above line err("manifest had issues that could not be resolved while getting init data") return nil @@ -1041,7 +1041,7 @@ func getMatchedFiles(_ location: [String: Any]) -> [String]? { // when code is loaded from a file, it's filename will be populated in the below array, to avoid duplication var matchedFilenames:[String] = [] // all exclude patterns from manifest - let excludePatterns = manifestKeys.exclude.keys + let excludePatterns = manifestKeys.excludeMatch.keys // all match patterns from manifest let matchPatterns = manifestKeys.match.keys @@ -1065,7 +1065,7 @@ func getMatchedFiles(_ location: [String: Any]) -> [String]? { for pattern in excludePatterns { // if pattern matches page url, add filenames from page url to excludes array, code from those filenames won't be loaded if match(ptcl, host, path, pattern) { - guard let filenames = manifestKeys.exclude[pattern] else { + guard let filenames = manifestKeys.excludeMatch[pattern] else { err("error parsing manifest.keys when attempting to get code for injected script") continue } From 9020a138533371b5d5aa7219424839b9831286e8 Mon Sep 17 00:00:00 2001 From: quoid Date: Tue, 15 Jun 2021 12:32:11 -0400 Subject: [PATCH 09/17] add exclude and include keys to manifest --- extension/Userscripts Extension/Functions.swift | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/extension/Userscripts Extension/Functions.swift b/extension/Userscripts Extension/Functions.swift index 2d33cc7a..391ff7b0 100644 --- a/extension/Userscripts Extension/Functions.swift +++ b/extension/Userscripts Extension/Functions.swift @@ -238,12 +238,14 @@ func parse(_ content: String) -> [String: Any]? { struct Manifest: Codable { var blacklist:[String] var disabled:[String] + var exclude: [String: [String]] var excludeMatch: [String: [String]] + var include: [String: [String]] var match: [String: [String]] var require: [String: [String]] var settings: [String: String] private enum CodingKeys : String, CodingKey { - case blacklist, disabled, excludeMatch = "exclude-match", match, require, settings + case blacklist, disabled, exclude, excludeMatch = "exclude-match", include, match, require, settings } } @@ -265,7 +267,7 @@ func getManifestKeys() -> Manifest? { let url = getDocumentsDirectory().appendingPathComponent("manifest.json") // if manifest doesn't exist, create new one if !FileManager.default.fileExists(atPath: url.path) { - let manifest = Manifest(blacklist: [], disabled: [], excludeMatch: [:], match: [:], require: [:], settings: [:]) + let manifest = Manifest(blacklist: [], disabled: [], exclude: [:], excludeMatch: [:], include: [:], match: [:], require: [:], settings: [:]) _ = updateManifest(with: manifest) } guard @@ -613,7 +615,7 @@ func getInitData() -> [String: Any]? { var manifestKeys = getManifestKeys() // if manifest missing, improperly formatted or key missing it will be nil, create new manifest if manifestKeys == nil { - manifestKeys = Manifest(blacklist: [], disabled: [], excludeMatch: [:], match: [:], require: [:], settings: [:]) + manifestKeys = Manifest(blacklist: [], disabled: [], exclude: [:], excludeMatch: [:], include: [:], match: [:], require: [:], settings: [:]) if !updateManifest(with: manifestKeys!) { // force unwrap since it was assigned in above line err("manifest had issues that could not be resolved while getting init data") return nil From b645c6f67f92cab2c511ec970b1ec48f20be880c Mon Sep 17 00:00:00 2001 From: quoid Date: Tue, 15 Jun 2021 14:43:16 -0400 Subject: [PATCH 10/17] refactor updateExcludesAndMatches and associated calls #143 --- .../Userscripts Extension/Functions.swift | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/extension/Userscripts Extension/Functions.swift b/extension/Userscripts Extension/Functions.swift index 391ff7b0..f99a3bc7 100644 --- a/extension/Userscripts Extension/Functions.swift +++ b/extension/Userscripts Extension/Functions.swift @@ -344,7 +344,7 @@ func toggleFile(_ filename: String,_ action: String) -> Bool { return true } -func updateExcludesAndMatches(_ filename: String,_ excludePatterns: [String],_ matchPatterns: [String]) -> Bool { +func updateExcludesAndMatches(_ filename: String,_ excludeMatchPatterns: [String],_ matchPatterns: [String],_ excludePatterns: [String],_ includePatterns: [String]) -> Bool { guard var manifestKeys = getManifestKeys() else { err("failed to get manifest keys when attempting to update excludes and matches") return false @@ -418,10 +418,14 @@ func updateExcludesAndMatches(_ filename: String,_ excludePatterns: [String],_ m } // get updated data for exclude-match and match - patternsInFile = excludePatterns + patternsInFile = excludeMatchPatterns manifestKeys.excludeMatch = updatePatternDict(manifestKeys.excludeMatch) patternsInFile = matchPatterns manifestKeys.match = updatePatternDict(manifestKeys.match) + patternsInFile = excludePatterns + manifestKeys.exclude = updatePatternDict(manifestKeys.exclude) + patternsInFile = includePatterns + manifestKeys.include = updatePatternDict(manifestKeys.include) // save updated data to manifest if updateManifest(with: manifestKeys) != true { @@ -710,22 +714,23 @@ func getAllFilesData() -> [[String: Any]]? { fileData["disabled"] = true } // update excludes & matches - var excluded = [String]() + var excludeMatched = [String]() var matched = [String]() + var excluded = [String]() + var included = [String]() if metadata["exclude-match"] != nil { - excluded.append(contentsOf: metadata["exclude-match"]!) + excludeMatched.append(contentsOf: metadata["exclude-match"]!) } if metadata["match"] != nil { matched.append(contentsOf: metadata["match"]!) } - // check for legacy include & exclude if metadata["include"] != nil { - matched.append(contentsOf: metadata["include"]!) + included.append(contentsOf: metadata["include"]!) } if metadata["exclude"] != nil { excluded.append(contentsOf: metadata["exclude"]!) } - if !updateExcludesAndMatches(filename, excluded, matched) { + if !updateExcludesAndMatches(filename, excludeMatched, matched, excluded, included) { err("error updating excludes & matches while getting all files data") } @@ -855,18 +860,15 @@ func saveFile(_ data: [String: Any]) -> [String: Any] { try? FileManager.default.trashItem(at: oldFileUrl, resultingItemURL: nil) // updateExcludesAndMatches for old file - _ = updateExcludesAndMatches(oldFilename, [], []) + _ = updateExcludesAndMatches(oldFilename, [], [], [], []) } // update new excludes and matches for new file - var excludes = metadata["exclude-match"] ?? [] - var matches = metadata["match"] ?? [] - // check for legacy include & exclude - let includeLegacy = metadata["include"] ?? [] - let excludeLegacy = metadata["exclude"] ?? [] - matches.append(contentsOf: includeLegacy) - excludes.append(contentsOf: excludeLegacy) - _ = updateExcludesAndMatches(newFilename, excludes, matches) + let excludeMatches = metadata["exclude-match"] ?? [] + let matches = metadata["match"] ?? [] + let includes = metadata["include"] ?? [] + let excludes = metadata["exclude"] ?? [] + _ = updateExcludesAndMatches(newFilename, excludeMatches, matches, excludes, includes) // un-santized name name = unsanitize(name) @@ -891,7 +893,7 @@ func trashFile(_ filename: String) -> Bool { // remove file from manifest guard toggleFile(filename, "enable"), - updateExcludesAndMatches(filename, [], []), + updateExcludesAndMatches(filename, [], [], [], []), let type = filename.components(separatedBy: ".").last, getRequiredCode(filename, [], type), let saveLocation = getSaveLocation() From 506fb392ba0bbea5240aaf78efa8fef3490112bf Mon Sep 17 00:00:00 2001 From: quoid Date: Tue, 15 Jun 2021 14:48:21 -0400 Subject: [PATCH 11/17] update purgeManifest for exclude & include #143 --- .../Userscripts Extension/Functions.swift | 52 ++++++++++++++++--- 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/extension/Userscripts Extension/Functions.swift b/extension/Userscripts Extension/Functions.swift index f99a3bc7..fa80c9b2 100644 --- a/extension/Userscripts Extension/Functions.swift +++ b/extension/Userscripts Extension/Functions.swift @@ -487,7 +487,7 @@ func purgeManifest() -> Bool { } } } - // iterate through manifest excludes + // iterate through manifest excludeMatch patterns for (pattern, filenames) in manifestKeys.excludeMatch { for filename in filenames { if !allSaveLocationFilenames.contains(filename) { @@ -497,15 +497,54 @@ func purgeManifest() -> Bool { NSLog("Could not find \(filename) in save location, removed from exclude-match pattern - \(pattern)") } } - // if there are no more filenames in pattern, remove pattern from manifest - if let length = manifestKeys.excludeMatch[pattern]?.count { - if length < 1, let ind = manifestKeys.excludeMatch.index(forKey: pattern) { - manifestKeys.excludeMatch.remove(at: ind) - NSLog("No more files for \(pattern) exclude-match pattern, removed from manifest") + } + // if there are no more filenames in pattern, remove pattern from manifest + if let length = manifestKeys.excludeMatch[pattern]?.count { + if length < 1, let ind = manifestKeys.excludeMatch.index(forKey: pattern) { + manifestKeys.excludeMatch.remove(at: ind) + NSLog("No more files for \(pattern) exclude-match pattern, removed from manifest") + } + } + } + // iterate through manifest exclude patterns + for (pattern, filenames) in manifestKeys.exclude { + for filename in filenames { + if !allSaveLocationFilenames.contains(filename) { + if let index = manifestKeys.exclude[pattern]?.firstIndex(of: filename) { + manifestKeys.exclude[pattern]?.remove(at: index) + update = true + NSLog("Could not find \(filename) in save location, removed from exclude pattern - \(pattern)") } } } + // if there are no more filenames in pattern, remove pattern from manifest + if let length = manifestKeys.exclude[pattern]?.count { + if length < 1, let ind = manifestKeys.exclude.index(forKey: pattern) { + manifestKeys.exclude.remove(at: ind) + NSLog("No more files for \(pattern) exclude pattern, removed from manifest") + } + } } + // iterate through manifest include patterns + for (pattern, filenames) in manifestKeys.include { + for filename in filenames { + if !allSaveLocationFilenames.contains(filename) { + if let index = manifestKeys.include[pattern]?.firstIndex(of: filename) { + manifestKeys.include[pattern]?.remove(at: index) + update = true + NSLog("Could not find \(filename) in save location, removed from exclude pattern - \(pattern)") + } + } + } + // if there are no more filenames in pattern, remove pattern from manifest + if let length = manifestKeys.include[pattern]?.count { + if length < 1, let ind = manifestKeys.include.index(forKey: pattern) { + manifestKeys.include.remove(at: ind) + NSLog("No more files for \(pattern) exclude pattern, removed from manifest") + } + } + } + // iterate through manifest disabled for filename in manifestKeys.disabled { if !allSaveLocationFilenames.contains(filename) { @@ -524,6 +563,7 @@ func purgeManifest() -> Bool { NSLog("Removed obsolete setting - \(setting.key)") } } + // update manifest if update, updateManifest(with: manifestKeys) != true { err("failed to purge manifest") From b7510d2ee3734ff810bc76c4b9f4f8da938d0070 Mon Sep 17 00:00:00 2001 From: quoid Date: Tue, 15 Jun 2021 14:58:59 -0400 Subject: [PATCH 12/17] clean up required when purging manifest --- .../Userscripts Extension/Functions.swift | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/extension/Userscripts Extension/Functions.swift b/extension/Userscripts Extension/Functions.swift index fa80c9b2..00b6b617 100644 --- a/extension/Userscripts Extension/Functions.swift +++ b/extension/Userscripts Extension/Functions.swift @@ -487,6 +487,7 @@ func purgeManifest() -> Bool { } } } + // iterate through manifest excludeMatch patterns for (pattern, filenames) in manifestKeys.excludeMatch { for filename in filenames { @@ -506,6 +507,7 @@ func purgeManifest() -> Bool { } } } + // iterate through manifest exclude patterns for (pattern, filenames) in manifestKeys.exclude { for filename in filenames { @@ -525,6 +527,7 @@ func purgeManifest() -> Bool { } } } + // iterate through manifest include patterns for (pattern, filenames) in manifestKeys.include { for filename in filenames { @@ -545,6 +548,21 @@ func purgeManifest() -> Bool { } } + // iterate through manifest required + for (filename, _) in manifestKeys.require { + if !allSaveLocationFilenames.contains(filename) { + if let index = manifestKeys.require.index(forKey: filename) { + manifestKeys.require.remove(at: index) + // remove associated resources + if !getRequiredCode(filename, [], (filename as NSString).pathExtension) { + err("failed to remove required resources when purging \(filename) from manifest required records") + } + update = true + NSLog("No more required resources for \(filename), removed from manifest along with resource folder") + } + } + } + // iterate through manifest disabled for filename in manifestKeys.disabled { if !allSaveLocationFilenames.contains(filename) { @@ -555,6 +573,7 @@ func purgeManifest() -> Bool { } } } + // remove obsolete settings for setting in manifestKeys.settings { if !defaultSettings.keys.contains(setting.key) { From f9d331fdfcc69e32479ee814b4bdd99e2892c499 Mon Sep 17 00:00:00 2001 From: quoid Date: Tue, 15 Jun 2021 15:30:00 -0400 Subject: [PATCH 13/17] rework getMatchedFiles func for include and exclude #143 --- .../Userscripts Extension/Functions.swift | 44 +++++++++++++++++-- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/extension/Userscripts Extension/Functions.swift b/extension/Userscripts Extension/Functions.swift index 00b6b617..89ecfa01 100644 --- a/extension/Userscripts Extension/Functions.swift +++ b/extension/Userscripts Extension/Functions.swift @@ -1093,7 +1093,8 @@ func getMatchedFiles(_ location: [String: Any]) -> [String]? { guard let ptcl = location["protocol"] as? String, let host = location["host"] as? String, - let path = location["pathname"] as? String + let path = location["pathname"] as? String, + let href = location["href"] as? String else { err("could not get values from location object when attempting to get matched files") return nil @@ -1103,10 +1104,14 @@ func getMatchedFiles(_ location: [String: Any]) -> [String]? { var excludedFilenames:[String] = [] // when code is loaded from a file, it's filename will be populated in the below array, to avoid duplication var matchedFilenames:[String] = [] - // all exclude patterns from manifest - let excludePatterns = manifestKeys.excludeMatch.keys + // all exclude-match patterns from manifest + let excludeMatchPatterns = manifestKeys.excludeMatch.keys // all match patterns from manifest let matchPatterns = manifestKeys.match.keys + // all include patterns from manifest + let includeExpressions = manifestKeys.include.keys + // all exclude patterns from manifest + let excludeExpressions = manifestKeys.exclude.keys // if injection is disabled, return empty array if active != "true" { @@ -1125,7 +1130,7 @@ func getMatchedFiles(_ location: [String: Any]) -> [String]? { excludedFilenames.append(contentsOf: manifestKeys.disabled) // loop through exclude patterns and see if any match against page url - for pattern in excludePatterns { + for pattern in excludeMatchPatterns { // if pattern matches page url, add filenames from page url to excludes array, code from those filenames won't be loaded if match(ptcl, host, path, pattern) { guard let filenames = manifestKeys.excludeMatch[pattern] else { @@ -1140,6 +1145,21 @@ func getMatchedFiles(_ location: [String: Any]) -> [String]? { } } + // loop through exclude expressions and check for matches + for exp in excludeExpressions { + if include(href, exp) { + guard let filenames = manifestKeys.exclude[exp] else { + err("error parsing manifest when attempting to get code, excludeExpressions") + continue + } + for filename in filenames { + if !excludedFilenames.contains(filename) { + excludedFilenames.append(filename) + } + } + } + } + // loop through all match patterns from manifest to see if they match against the current page url for pattern in matchPatterns { if match(ptcl, host, path, pattern) { @@ -1158,6 +1178,22 @@ func getMatchedFiles(_ location: [String: Any]) -> [String]? { } } + + // loop through include expressions and check for matches + for exp in includeExpressions { + if include(href, exp) { + guard let filenames = manifestKeys.include[exp] else { + err("error parsing manifest when attempting to get code, includeExpressions") + continue + } + for filename in filenames { + if !excludedFilenames.contains(filename) && !matchedFilenames.contains(filename) { + matchedFilenames.append(filename) + } + } + } + } + return matchedFilenames } From 912b4d4140c2b75dc82782a4987f14ce597bce48 Mon Sep 17 00:00:00 2001 From: quoid Date: Tue, 15 Jun 2021 15:32:54 -0400 Subject: [PATCH 14/17] update getURLProps to include original url in return #143 --- extension/Userscripts Extension/Functions.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension/Userscripts Extension/Functions.swift b/extension/Userscripts Extension/Functions.swift index 89ecfa01..e86c9e54 100644 --- a/extension/Userscripts Extension/Functions.swift +++ b/extension/Userscripts Extension/Functions.swift @@ -1326,7 +1326,7 @@ func getURLProps(_ url: String) -> [String: String]? { if let pathRange = Range(result.range(at: 3), in: url) { path = String(url[pathRange]) } - return ["protocol": ptcl, "host": host, "pathname": path] + return ["protocol": ptcl, "host": host, "pathname": path, "href": url] } func stringToRegex(_ stringPattern: String) -> NSRegularExpression? { From f099f1fdca08c0a5cef5416b2d342054a2fcaa9f Mon Sep 17 00:00:00 2001 From: quoid Date: Tue, 15 Jun 2021 15:43:51 -0400 Subject: [PATCH 15/17] readme update --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 218b22a4..bba662b1 100644 --- a/README.md +++ b/README.md @@ -91,8 +91,8 @@ Userscripts Safari currently supports the following userscript metadata: - `@match` - Domain match patterns - you can use several instances of this field if you'd like multiple domain matches - view [this article for more information on constructing patterns](https://developer.chrome.com/extensions/match_patterns) - **Note:** this extension only supports `http/s` - `@exclude-match` - Domain patterns where you do *not* want the script to run -- `@include` - An alias for `@match` - functions exactly like `@match` -- `@exclude` - An alias for `@exclude-match` - functions exactly like `@exclude-match` +- `@include` - Used to match against urls for injection, globs and regular expressions are allowed, [read more here](https://wiki.greasespot.net/Include_and_exclude_rules) +- `@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 From 315387dc24f6e30ca1b11c011330d06fe04f17f7 Mon Sep 17 00:00:00 2001 From: quoid Date: Tue, 15 Jun 2021 23:04:21 -0400 Subject: [PATCH 16/17] update issue template --- ISSUE_TEMPLATE.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md index 8228b3d8..3a91a329 100644 --- a/ISSUE_TEMPLATE.md +++ b/ISSUE_TEMPLATE.md @@ -3,9 +3,9 @@ Please fill out the below information before submitting your issue If you are having issues with script injection, please include examples of what is not working and try the userscript below: // ==UserScript== -// @name TestScript -// @description This is your new file, start writing code -// @include *://*/* +// @name TestScript +// @description This is your new file, start writing code +// @match // @exclude-match *://*.google.com/* // @noframes // ==/UserScript== From c52d887e942f95c67c5732e878bb55cb4e2d2a9f Mon Sep 17 00:00:00 2001 From: quoid Date: Tue, 22 Jun 2021 12:39:43 -0400 Subject: [PATCH 17/17] update issue template --- ISSUE_TEMPLATE.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md index 3a91a329..e9b83f1e 100644 --- a/ISSUE_TEMPLATE.md +++ b/ISSUE_TEMPLATE.md @@ -1,6 +1,7 @@