From 32b1dea1fdb44531b98b1880761ec3fe1b570fe2 Mon Sep 17 00:00:00 2001 From: Weijie Zhao Date: Thu, 4 Aug 2022 18:47:03 +0800 Subject: [PATCH 01/22] add GM.getTab and GM.saveTab --- README.md | 5 ++ .../Resources/background.js | 80 +++++++++++++++++++ .../Resources/content.js | 27 +++++++ .../Userscripts Extension/Resources/page.js | 4 +- 4 files changed, 115 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f0f51a5c..64bece08 100644 --- a/README.md +++ b/README.md @@ -191,6 +191,11 @@ Userscripts currently supports the following api methods. All methods are asynch - on success returns a promise resolved with an object indicating success - `GM.listValues()` - on success returns a promise resolved with an array of the key names of **presently set** values +- `GM.getTab()` + - on success returns a promise resolved with a object that is persistent as long as this tab is open +- `GM.saveTab(tabObj)` + - `tabObj: Any` + - on success returns a promise resolved with an object indicating success - `GM.openInTab(url, openInBackground)` - `url: String`, `openInBackground: Bool` - on success returns a promise resolved with the [tab data](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/Tab) for the tab just opened diff --git a/extension/Userscripts Extension/Resources/background.js b/extension/Userscripts Extension/Resources/background.js index f6290b83..22362075 100644 --- a/extension/Userscripts Extension/Resources/background.js +++ b/extension/Userscripts Extension/Resources/background.js @@ -5,6 +5,7 @@ // xhrs are only kept in this array when active, otherwise array is empty // that means it's ok that this var gets reset when the bg page unloads let xhrs = []; +let US_tabs = {}; /* global US_filename, US_uid */ // filename and uid will be available to functions at runtime @@ -158,6 +159,53 @@ const apis = { window.postMessage({id: US_uid, name: "API_SET_CLIPBOARD", data: data, type: type}); return undefined; }, + US_getTab() { + const pid = Math.random().toString(36).substring(1, 9); + return new Promise(resolve => { + const callback = e => { + if ( + e.data.pid !== pid + || e.data.id !== US_uid + || e.data.name !== "RESP_GET_TAB" + || e.data.filename !== US_filename + ) return; + const response = e.data.response; + resolve(response); + window.removeEventListener("message", callback); + }; + window.addEventListener("message", callback); + window.postMessage({ + id: US_uid, + pid: pid, + name: "API_GET_TAB", + filename: US_filename, + }); + }); + }, + US_saveTab(tab) { + const pid = Math.random().toString(36).substring(1, 9); + return new Promise(resolve => { + const callback = e => { + if ( + e.data.pid !== pid + || e.data.id !== US_uid + || e.data.name !== "RESP_SAVE_TAB" + || e.data.filename !== US_filename + ) return; + const response = e.data.response; + resolve(response); + window.removeEventListener("message", callback); + }; + window.addEventListener("message", callback); + window.postMessage({ + id: US_uid, + pid: pid, + name: "API_SAVE_TAB", + filename: US_filename, + tab: tab + }); + }); + }, // when xhr is called it sends a message to the content script // and adds it's own event listener to get responses from content script // each xhr has a unique id so it won't respond to different xhr @@ -405,6 +453,14 @@ function addApis({userscripts, uid, scriptHandler, scriptHandlerVersion}) { api += `\n${apis.US_setClipboardSync}`; api += "\nconst GM_setClipboard = US_setClipboardSync;"; break; + case "GM.getTab": + api += `\n${apis.US_getTab}`; + gmMethods.push("getTab: US_getTab"); + break; + case "GM.saveTab": + api += `\n${apis.US_saveTab}`; + gmMethods.push("saveTab: US_saveTab"); + break; case "GM_xmlhttpRequest": case "GM.xmlHttpRequest": if (!includedMethods.includes("xhr")) { @@ -713,6 +769,30 @@ browser.runtime.onMessage.addListener((request, sender, sendResponse) => { } break; } + case "API_GET_TAB": { + if (typeof sender.tab != 'undefined') { + if (typeof US_tabs[sender.tab.id] == 'undefined') US_tabs[sender.tab.id] = { storage: {} }; + let tab = US_tabs[sender.tab.id]; + sendResponse(tab); + } else { + console.error("unable to deliver tab due to empty tab id"); + sendResponse(null); + } + break; + } + case "API_SAVE_TAB": { + if (typeof sender.tab != 'undefined') { + let tab = {}; + for (let k in request.tab) { + tab[k] = request.tab[k]; + }; + US_tabs[sender.tab.id] = tab; + } else { + console.error("unable to save tab due to empty tab id"); + } + sendResponse({}); + break; + } case "USERSCRIPT_INSTALL_00": case "USERSCRIPT_INSTALL_01": case "USERSCRIPT_INSTALL_02": { diff --git a/extension/Userscripts Extension/Resources/content.js b/extension/Userscripts Extension/Resources/content.js index ffc483e7..b08207a6 100644 --- a/extension/Userscripts Extension/Resources/content.js +++ b/extension/Userscripts Extension/Resources/content.js @@ -245,6 +245,33 @@ function handleApiMessages(e) { window.postMessage(respMessage); }); break; + case "API_GET_TAB": + message = { + name: name, + filename: e.data.filename, + pid: pid, + }; + browser.runtime.sendMessage(message, response => { + const undef = response === `undefined--${pid}`; + respMessage.response = undef ? undefined : response; + respMessage.filename = e.data.filename; + window.postMessage(respMessage); + }); + break; + case "API_SAVE_TAB": + message = { + name: name, + filename: e.data.filename, + pid: pid, + tab: e.data.tab + }; + browser.runtime.sendMessage(message, response => { + const undef = response === `undefined--${pid}`; + respMessage.response = undef ? undefined : response; + respMessage.filename = e.data.filename; + window.postMessage(respMessage); + }); + break; case "API_XHR_ABORT_INJ": message = {name: "API_XHR_ABORT_CS", xhrId: e.data.xhrId}; browser.runtime.sendMessage(message); diff --git a/extension/Userscripts Extension/Resources/page.js b/extension/Userscripts Extension/Resources/page.js index ada155d3..9c3ff103 100644 --- a/extension/Userscripts Extension/Resources/page.js +++ b/extension/Userscripts Extension/Resources/page.js @@ -1067,7 +1067,9 @@ var JSHINT;"undefined"==typeof window&&(window={}),function(){var f=function u(o "GM_addStyle", "GM_info", "GM_setClipboard", - "GM_xmlhttpRequest" + "GM_xmlhttpRequest", + "GM.getTab", + "GM.saveTab" ]); const validKeys = new Set([ From d99a16b054b7145238bf1ee39df089c14c8da1d2 Mon Sep 17 00:00:00 2001 From: quoid Date: Sat, 6 Aug 2022 11:59:36 -0400 Subject: [PATCH 02/22] update getTab and saveTab to use sessionStorage --- .../Resources/background.js | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/extension/Userscripts Extension/Resources/background.js b/extension/Userscripts Extension/Resources/background.js index 22362075..7a3efee1 100644 --- a/extension/Userscripts Extension/Resources/background.js +++ b/extension/Userscripts Extension/Resources/background.js @@ -5,7 +5,6 @@ // xhrs are only kept in this array when active, otherwise array is empty // that means it's ok that this var gets reset when the bg page unloads let xhrs = []; -let US_tabs = {}; /* global US_filename, US_uid */ // filename and uid will be available to functions at runtime @@ -178,7 +177,7 @@ const apis = { id: US_uid, pid: pid, name: "API_GET_TAB", - filename: US_filename, + filename: US_filename }); }); }, @@ -770,9 +769,15 @@ browser.runtime.onMessage.addListener((request, sender, sendResponse) => { break; } case "API_GET_TAB": { - if (typeof sender.tab != 'undefined') { - if (typeof US_tabs[sender.tab.id] == 'undefined') US_tabs[sender.tab.id] = { storage: {} }; - let tab = US_tabs[sender.tab.id]; + if (typeof sender.tab !== "undefined") { + let tab = null; + const tabData = sessionStorage.getItem(`tab-${sender.tab.id}`); + try { + // if tabData is null, can still parse it and return that + tab = JSON.parse(tabData); + } catch (error) { + console.error("failed to parse tab data for getTab"); + } sendResponse(tab); } else { console.error("unable to deliver tab due to empty tab id"); @@ -781,16 +786,13 @@ browser.runtime.onMessage.addListener((request, sender, sendResponse) => { break; } case "API_SAVE_TAB": { - if (typeof sender.tab != 'undefined') { - let tab = {}; - for (let k in request.tab) { - tab[k] = request.tab[k]; - }; - US_tabs[sender.tab.id] = tab; + if (typeof sender.tab !== "undefined" && request.tab) { + sessionStorage.setItem(`tab-${sender.tab.id}`, JSON.stringify(request.tab)); + sendResponse({success: true}); } else { - console.error("unable to save tab due to empty tab id"); + console.error("unable to save tab due to empty tab id or bad arg"); + sendResponse(null); } - sendResponse({}); break; } case "USERSCRIPT_INSTALL_00": From b32b6dd5b3d12c1dd51faee1d8af2a05332cb7d5 Mon Sep 17 00:00:00 2001 From: quoid Date: Sat, 6 Aug 2022 12:00:00 -0400 Subject: [PATCH 03/22] update readme to note that getTab can return `Any` --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 64bece08..2d58d885 100644 --- a/README.md +++ b/README.md @@ -192,7 +192,7 @@ Userscripts currently supports the following api methods. All methods are asynch - `GM.listValues()` - on success returns a promise resolved with an array of the key names of **presently set** values - `GM.getTab()` - - on success returns a promise resolved with a object that is persistent as long as this tab is open + - on success returns a promise resolved with `Any` data that is persistent as long as this tab is open - `GM.saveTab(tabObj)` - `tabObj: Any` - on success returns a promise resolved with an object indicating success From 0c98e91276a451d76b8cfa68a9ce3aa9eba3493d Mon Sep 17 00:00:00 2001 From: quoid Date: Sat, 6 Aug 2022 12:00:08 -0400 Subject: [PATCH 04/22] formatting --- extension/Userscripts Extension/Resources/content.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension/Userscripts Extension/Resources/content.js b/extension/Userscripts Extension/Resources/content.js index b08207a6..4046397c 100644 --- a/extension/Userscripts Extension/Resources/content.js +++ b/extension/Userscripts Extension/Resources/content.js @@ -249,7 +249,7 @@ function handleApiMessages(e) { message = { name: name, filename: e.data.filename, - pid: pid, + pid: pid }; browser.runtime.sendMessage(message, response => { const undef = response === `undefined--${pid}`; From 87d692a83e0f5394262d6097afea28a55e025b75 Mon Sep 17 00:00:00 2001 From: quoid Date: Sat, 6 Aug 2022 12:00:50 -0400 Subject: [PATCH 05/22] add new methods to utils --- src/page/utils.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/page/utils.js b/src/page/utils.js index c8ff9225..34b886c6 100644 --- a/src/page/utils.js +++ b/src/page/utils.js @@ -152,7 +152,9 @@ export const validGrants = new Set([ "GM_addStyle", "GM_info", "GM_setClipboard", - "GM_xmlhttpRequest" + "GM_xmlhttpRequest", + "GM.getTab", + "GM.saveTab" ]); export const validKeys = new Set([ From ec6c52b5abf07cdbb4515030ca22b538bc13c390 Mon Sep 17 00:00:00 2001 From: Weijie Zhao Date: Thu, 4 Aug 2022 18:47:03 +0800 Subject: [PATCH 06/22] add GM.getTab and GM.saveTab --- README.md | 5 ++ .../Resources/background.js | 83 +++++++++++++++++++ .../Resources/content.js | 27 ++++++ .../Userscripts Extension/Resources/page.js | 4 +- 4 files changed, 118 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f0f51a5c..64bece08 100644 --- a/README.md +++ b/README.md @@ -191,6 +191,11 @@ Userscripts currently supports the following api methods. All methods are asynch - on success returns a promise resolved with an object indicating success - `GM.listValues()` - on success returns a promise resolved with an array of the key names of **presently set** values +- `GM.getTab()` + - on success returns a promise resolved with a object that is persistent as long as this tab is open +- `GM.saveTab(tabObj)` + - `tabObj: Any` + - on success returns a promise resolved with an object indicating success - `GM.openInTab(url, openInBackground)` - `url: String`, `openInBackground: Bool` - on success returns a promise resolved with the [tab data](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/Tab) for the tab just opened diff --git a/extension/Userscripts Extension/Resources/background.js b/extension/Userscripts Extension/Resources/background.js index f6290b83..34dff048 100644 --- a/extension/Userscripts Extension/Resources/background.js +++ b/extension/Userscripts Extension/Resources/background.js @@ -158,6 +158,53 @@ const apis = { window.postMessage({id: US_uid, name: "API_SET_CLIPBOARD", data: data, type: type}); return undefined; }, + US_getTab() { + const pid = Math.random().toString(36).substring(1, 9); + return new Promise(resolve => { + const callback = e => { + if ( + e.data.pid !== pid + || e.data.id !== US_uid + || e.data.name !== "RESP_GET_TAB" + || e.data.filename !== US_filename + ) return; + const response = e.data.response; + resolve(response); + window.removeEventListener("message", callback); + }; + window.addEventListener("message", callback); + window.postMessage({ + id: US_uid, + pid: pid, + name: "API_GET_TAB", + filename: US_filename, + }); + }); + }, + US_saveTab(tab) { + const pid = Math.random().toString(36).substring(1, 9); + return new Promise(resolve => { + const callback = e => { + if ( + e.data.pid !== pid + || e.data.id !== US_uid + || e.data.name !== "RESP_SAVE_TAB" + || e.data.filename !== US_filename + ) return; + const response = e.data.response; + resolve(response); + window.removeEventListener("message", callback); + }; + window.addEventListener("message", callback); + window.postMessage({ + id: US_uid, + pid: pid, + name: "API_SAVE_TAB", + filename: US_filename, + tab: tab + }); + }); + }, // when xhr is called it sends a message to the content script // and adds it's own event listener to get responses from content script // each xhr has a unique id so it won't respond to different xhr @@ -405,6 +452,14 @@ function addApis({userscripts, uid, scriptHandler, scriptHandlerVersion}) { api += `\n${apis.US_setClipboardSync}`; api += "\nconst GM_setClipboard = US_setClipboardSync;"; break; + case "GM.getTab": + api += `\n${apis.US_getTab}`; + gmMethods.push("getTab: US_getTab"); + break; + case "GM.saveTab": + api += `\n${apis.US_saveTab}`; + gmMethods.push("saveTab: US_saveTab"); + break; case "GM_xmlhttpRequest": case "GM.xmlHttpRequest": if (!includedMethods.includes("xhr")) { @@ -713,6 +768,34 @@ browser.runtime.onMessage.addListener((request, sender, sendResponse) => { } break; } + case "API_GET_TAB": { + if (typeof sender.tab != 'undefined') { + let tabSessionKey = "tab_" + sender.tab.id; + if (sessionStorage[tabSessionKey] == null || typeof sessionStorage[tabSessionKey] == 'undefined') { + sessionStorage[tabSessionKey] = JSON.stringify({ storage: {} }); + }; + let tab = JSON.parse(sessionStorage[tabSessionKey]); + sendResponse(tab); + } else { + console.error("unable to deliver tab due to empty tab id"); + sendResponse(null); + } + break; + } + case "API_SAVE_TAB": { + if (typeof sender.tab != 'undefined') { + let tabSessionKey = "tab_" + sender.tab.id; + let tab = {}; + for (let k in request.tab) { + tab[k] = request.tab[k]; + }; + sessionStorage[tabSessionKey] = JSON.stringify(tab); + } else { + console.error("unable to save tab due to empty tab id"); + } + sendResponse({}); + break; + } case "USERSCRIPT_INSTALL_00": case "USERSCRIPT_INSTALL_01": case "USERSCRIPT_INSTALL_02": { diff --git a/extension/Userscripts Extension/Resources/content.js b/extension/Userscripts Extension/Resources/content.js index ffc483e7..b08207a6 100644 --- a/extension/Userscripts Extension/Resources/content.js +++ b/extension/Userscripts Extension/Resources/content.js @@ -245,6 +245,33 @@ function handleApiMessages(e) { window.postMessage(respMessage); }); break; + case "API_GET_TAB": + message = { + name: name, + filename: e.data.filename, + pid: pid, + }; + browser.runtime.sendMessage(message, response => { + const undef = response === `undefined--${pid}`; + respMessage.response = undef ? undefined : response; + respMessage.filename = e.data.filename; + window.postMessage(respMessage); + }); + break; + case "API_SAVE_TAB": + message = { + name: name, + filename: e.data.filename, + pid: pid, + tab: e.data.tab + }; + browser.runtime.sendMessage(message, response => { + const undef = response === `undefined--${pid}`; + respMessage.response = undef ? undefined : response; + respMessage.filename = e.data.filename; + window.postMessage(respMessage); + }); + break; case "API_XHR_ABORT_INJ": message = {name: "API_XHR_ABORT_CS", xhrId: e.data.xhrId}; browser.runtime.sendMessage(message); diff --git a/extension/Userscripts Extension/Resources/page.js b/extension/Userscripts Extension/Resources/page.js index ada155d3..9c3ff103 100644 --- a/extension/Userscripts Extension/Resources/page.js +++ b/extension/Userscripts Extension/Resources/page.js @@ -1067,7 +1067,9 @@ var JSHINT;"undefined"==typeof window&&(window={}),function(){var f=function u(o "GM_addStyle", "GM_info", "GM_setClipboard", - "GM_xmlhttpRequest" + "GM_xmlhttpRequest", + "GM.getTab", + "GM.saveTab" ]); const validKeys = new Set([ From ea6c6a24775b4d83eb1f79be8c78b166ccd9e743 Mon Sep 17 00:00:00 2001 From: quoid Date: Sat, 6 Aug 2022 13:08:35 -0400 Subject: [PATCH 07/22] remove duplicate case --- extension/Userscripts Extension/Resources/background.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/extension/Userscripts Extension/Resources/background.js b/extension/Userscripts Extension/Resources/background.js index 0755a464..7a3efee1 100644 --- a/extension/Userscripts Extension/Resources/background.js +++ b/extension/Userscripts Extension/Resources/background.js @@ -460,14 +460,6 @@ function addApis({userscripts, uid, scriptHandler, scriptHandlerVersion}) { api += `\n${apis.US_saveTab}`; gmMethods.push("saveTab: US_saveTab"); break; - case "GM.getTab": - api += `\n${apis.US_getTab}`; - gmMethods.push("getTab: US_getTab"); - break; - case "GM.saveTab": - api += `\n${apis.US_saveTab}`; - gmMethods.push("saveTab: US_saveTab"); - break; case "GM_xmlhttpRequest": case "GM.xmlHttpRequest": if (!includedMethods.includes("xhr")) { From 5218b85bda15e484c25f058dec19a3e04cc47d15 Mon Sep 17 00:00:00 2001 From: quoid Date: Sat, 6 Aug 2022 13:09:03 -0400 Subject: [PATCH 08/22] update api responses --- extension/Userscripts Extension/Resources/content.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/extension/Userscripts Extension/Resources/content.js b/extension/Userscripts Extension/Resources/content.js index 4046397c..5a443735 100644 --- a/extension/Userscripts Extension/Resources/content.js +++ b/extension/Userscripts Extension/Resources/content.js @@ -252,8 +252,7 @@ function handleApiMessages(e) { pid: pid }; browser.runtime.sendMessage(message, response => { - const undef = response === `undefined--${pid}`; - respMessage.response = undef ? undefined : response; + respMessage.response = response; respMessage.filename = e.data.filename; window.postMessage(respMessage); }); @@ -266,8 +265,7 @@ function handleApiMessages(e) { tab: e.data.tab }; browser.runtime.sendMessage(message, response => { - const undef = response === `undefined--${pid}`; - respMessage.response = undef ? undefined : response; + respMessage.response = response; respMessage.filename = e.data.filename; window.postMessage(respMessage); }); From 5ea47883a9544c59cd89f055114d246c663e1c2e Mon Sep 17 00:00:00 2001 From: quoid Date: Sat, 6 Aug 2022 13:12:02 -0400 Subject: [PATCH 09/22] bump build and version --- .../Resources/manifest.json | 2 +- .../Userscripts.xcodeproj/project.pbxproj | 32 +++++++++---------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/extension/Userscripts Extension/Resources/manifest.json b/extension/Userscripts Extension/Resources/manifest.json index abfb293a..fa2e3d25 100644 --- a/extension/Userscripts Extension/Resources/manifest.json +++ b/extension/Userscripts Extension/Resources/manifest.json @@ -4,7 +4,7 @@ "default_locale": "en", "name": "__MSG_extension_name__", "description": "__MSG_extension_description__", - "version": "4.2.2", + "version": "4.2.3", "icons": { "48": "images/icon-48.png", "96": "images/icon-96.png", diff --git a/extension/Userscripts.xcodeproj/project.pbxproj b/extension/Userscripts.xcodeproj/project.pbxproj index 43933c31..b34a79cc 100644 --- a/extension/Userscripts.xcodeproj/project.pbxproj +++ b/extension/Userscripts.xcodeproj/project.pbxproj @@ -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 = 27; + CURRENT_PROJECT_VERSION = 28; DEVELOPMENT_TEAM = J74Q8V8V8N; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "Userscripts-iOS/Info.plist"; @@ -679,7 +679,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.2.2; + MARKETING_VERSION = 1.2.3; OTHER_LDFLAGS = ( "-framework", SafariServices, @@ -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 = 27; + CURRENT_PROJECT_VERSION = 28; DEVELOPMENT_TEAM = J74Q8V8V8N; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "Userscripts-iOS/Info.plist"; @@ -720,7 +720,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.2.2; + MARKETING_VERSION = 1.2.3; OTHER_LDFLAGS = ( "-framework", SafariServices, @@ -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 = 27; + CURRENT_PROJECT_VERSION = 28; DEVELOPMENT_TEAM = J74Q8V8V8N; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "Userscripts-iOS Extension/Info.plist"; @@ -755,7 +755,7 @@ "@executable_path/Frameworks", "@executable_path/../../Frameworks", ); - MARKETING_VERSION = 1.2.2; + MARKETING_VERSION = 1.2.3; OTHER_LDFLAGS = ( "-framework", SafariServices, @@ -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 = 27; + CURRENT_PROJECT_VERSION = 28; DEVELOPMENT_TEAM = J74Q8V8V8N; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "Userscripts-iOS Extension/Info.plist"; @@ -788,7 +788,7 @@ "@executable_path/Frameworks", "@executable_path/../../Frameworks", ); - MARKETING_VERSION = 1.2.2; + MARKETING_VERSION = 1.2.3; OTHER_LDFLAGS = ( "-framework", SafariServices, @@ -929,7 +929,7 @@ CODE_SIGN_ENTITLEMENTS = "Userscripts Extension/Userscripts Extension.entitlements"; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 55; + CURRENT_PROJECT_VERSION = 56; DEVELOPMENT_TEAM = J74Q8V8V8N; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = "Userscripts Extension/Info.plist"; @@ -939,7 +939,7 @@ "@executable_path/../../../../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 11.0; - MARKETING_VERSION = 4.2.2; + MARKETING_VERSION = 4.2.3; PRODUCT_BUNDLE_IDENTIFIER = "com.userscripts.macos.Userscripts-Extension"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; @@ -953,7 +953,7 @@ CODE_SIGN_ENTITLEMENTS = "Userscripts Extension/Userscripts Extension.entitlements"; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 55; + CURRENT_PROJECT_VERSION = 56; DEVELOPMENT_TEAM = J74Q8V8V8N; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = "Userscripts Extension/Info.plist"; @@ -963,7 +963,7 @@ "@executable_path/../../../../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 11.0; - MARKETING_VERSION = 4.2.2; + MARKETING_VERSION = 4.2.3; PRODUCT_BUNDLE_IDENTIFIER = "com.userscripts.macos.Userscripts-Extension"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; @@ -980,7 +980,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 55; + CURRENT_PROJECT_VERSION = 56; DEVELOPMENT_TEAM = J74Q8V8V8N; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = Userscripts/Info.plist; @@ -989,7 +989,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 11.0; - MARKETING_VERSION = 4.2.2; + MARKETING_VERSION = 4.2.3; PRODUCT_BUNDLE_IDENTIFIER = com.userscripts.macos; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; @@ -1005,7 +1005,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 55; + CURRENT_PROJECT_VERSION = 56; DEVELOPMENT_TEAM = J74Q8V8V8N; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = Userscripts/Info.plist; @@ -1014,7 +1014,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 11.0; - MARKETING_VERSION = 4.2.2; + MARKETING_VERSION = 4.2.3; PRODUCT_BUNDLE_IDENTIFIER = com.userscripts.macos; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; From 5f7b96963a14bf3e44efd3ef2274f72862aa5b04 Mon Sep 17 00:00:00 2001 From: quoid Date: Wed, 10 Aug 2022 08:24:10 -0400 Subject: [PATCH 10/22] userscriptInstall should only check top frame #295 --- extension/Userscripts Extension/Resources/content.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/extension/Userscripts Extension/Resources/content.js b/extension/Userscripts Extension/Resources/content.js index 5a443735..fff0f94d 100644 --- a/extension/Userscripts Extension/Resources/content.js +++ b/extension/Userscripts Extension/Resources/content.js @@ -325,6 +325,8 @@ browser.runtime.onMessage.addListener((request, sender, sendResponse) => { || name === "USERSCRIPT_INSTALL_01" || name === "USERSCRIPT_INSTALL_02" ) { + // only response to top frame messages + if (window !== window.top) return; const types = [ "text/plain", "application/ecmascript", From a2c401e08b64dde11b77be8620f53d88298a88d6 Mon Sep 17 00:00:00 2001 From: quoid Date: Wed, 10 Aug 2022 08:27:46 -0400 Subject: [PATCH 11/22] get pre tag contents rather than all innerText #295 --- extension/Userscripts Extension/Resources/content.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/extension/Userscripts Extension/Resources/content.js b/extension/Userscripts Extension/Resources/content.js index fff0f94d..def23e25 100644 --- a/extension/Userscripts Extension/Resources/content.js +++ b/extension/Userscripts Extension/Resources/content.js @@ -334,10 +334,14 @@ browser.runtime.onMessage.addListener((request, sender, sendResponse) => { "text/ecmascript", "text/javascript" ]; - if (!document.contentType || types.indexOf(document.contentType) === -1) { + if ( + !document.contentType + || types.indexOf(document.contentType) === -1 + || !document.querySelector("pre") + ) { sendResponse({invalid: true}); } else { - const message = {name: name, content: document.body.innerText}; + const message = {name: name, content: document.querySelector("pre").innerText}; browser.runtime.sendMessage(message, response => { sendResponse(response); }); From 2e18fc39c6727baa209ecbabd36e536c889985eb Mon Sep 17 00:00:00 2001 From: quoid Date: Fri, 12 Aug 2022 16:48:31 -0400 Subject: [PATCH 12/22] further changes to `@grant` and `@inject-into` interactions #265 --- .../Resources/background.js | 19 ++++++++++++++++++- .../Resources/content.js | 2 ++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/extension/Userscripts Extension/Resources/background.js b/extension/Userscripts Extension/Resources/background.js index 7a3efee1..2eca9eb3 100644 --- a/extension/Userscripts Extension/Resources/background.js +++ b/extension/Userscripts Extension/Resources/background.js @@ -395,6 +395,7 @@ function addApis({userscripts, uid, scriptHandler, scriptHandlerVersion}) { const userscript = userscripts[i]; const filename = userscript.scriptObject.filename; const grants = userscript.scriptObject.grants; + const injectInto = userscript.scriptObject["inject-into"]; // prepare the api string let api = `const US_uid = "${uid}";\nconst US_filename = "${filename}";`; // all scripts get access to US_info / GM./GM_info, prepare that object @@ -408,7 +409,23 @@ function addApis({userscripts, uid, scriptHandler, scriptHandlerVersion}) { api += "\nconst GM_info = US_info;"; gmMethods.push("info: US_info"); // if @grant explicitly set to none, empty grants array - if (grants.includes("none")) grants.length = 0; + if (grants.includes("none")) { + grants.length = 0; + } + // @grant exist for page scoped userscript + if (grants.length && injectInto === "page") { + // remove grants + grants.length = 0; + // provide warning for content script + userscript.warning = `${filename} @grant values changed due to @inject-into value`; + } + // @grant exist for auto scoped userscript + if (grants.length && injectInto === "auto") { + // change scope + userscript.scriptObject["inject-into"] = "content"; + // provide warning for content script + userscript.warning = `${filename} @inject-into value changed due to @grant values`; + } // loop through each @grant for the userscript, add methods as needed for (let j = 0; j < grants.length; j++) { const grant = grants[j]; diff --git a/extension/Userscripts Extension/Resources/content.js b/extension/Userscripts Extension/Resources/content.js index def23e25..543d7433 100644 --- a/extension/Userscripts Extension/Resources/content.js +++ b/extension/Userscripts Extension/Resources/content.js @@ -29,6 +29,8 @@ browser.runtime.sendMessage({name: "REQ_USERSCRIPTS", uid: uid}, response => { 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`); } + // log warning if provided + if (userscript.warning) console.warn(userscript.warning); processJS( userscript.scriptObject.name, userscript.scriptObject.filename, From dd2df9e62a627b01d78d685a7b687598ca57cf3c Mon Sep 17 00:00:00 2001 From: quoid Date: Fri, 12 Aug 2022 17:04:28 -0400 Subject: [PATCH 13/22] rebuild extension page #283 --- extension/Userscripts Extension/Resources/page.html | 2 +- extension/Userscripts Extension/Resources/page.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/extension/Userscripts Extension/Resources/page.html b/extension/Userscripts Extension/Resources/page.html index d0a7c906..7761b95e 100644 --- a/extension/Userscripts Extension/Resources/page.html +++ b/extension/Userscripts Extension/Resources/page.html @@ -1 +1 @@ -Userscripts Safari
\ No newline at end of file +Userscripts Safari
\ No newline at end of file diff --git a/extension/Userscripts Extension/Resources/page.js b/extension/Userscripts Extension/Resources/page.js index 9c3ff103..4f7345c9 100644 --- a/extension/Userscripts Extension/Resources/page.js +++ b/extension/Userscripts Extension/Resources/page.js @@ -19622,7 +19622,7 @@ var JSHINT;"undefined"==typeof window&&(window={}),function(){var f=function u(o attr(div22, "class", "truncate svelte-9f6q4c"); attr(div23, "class", "modal__row saveLocation svelte-9f6q4c"); attr(div24, "class", "blacklist svelte-9f6q4c"); - attr(textarea, "placeholder", "Comma separated domain patterns"); + attr(textarea, "placeholder", "Comma separated list of @match patterns"); attr(textarea, "spellcheck", "false"); textarea.value = /*blacklisted*/ ctx[2]; textarea.disabled = textarea_disabled_value = /*$state*/ ctx[4].includes("blacklist-saving") || /*blacklistSaving*/ ctx[1]; From 369b1bf949aaa7cae65cd4512c9d82e96a027deb Mon Sep 17 00:00:00 2001 From: quoid Date: Wed, 17 Aug 2022 20:13:27 -0400 Subject: [PATCH 14/22] update match func to allow for hosts without .tld & fix protocol matching #301 --- extension/Userscripts Extension/Functions.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/extension/Userscripts Extension/Functions.swift b/extension/Userscripts Extension/Functions.swift index 85d08bd4..3e69911b 100644 --- a/extension/Userscripts Extension/Functions.swift +++ b/extension/Userscripts Extension/Functions.swift @@ -1094,13 +1094,18 @@ func match(_ ptcl: String,_ host: String,_ path: String,_ matchPattern: String) if (ptcl != "http:" && ptcl != "https:") { return false } - let partsPattern = #"^(http:|https:|\*:)\/\/((?:\*\.)?(?:[a-z0-9-]+\.)+(?:[a-z0-9]+)|\*\.[a-z]+|\*)(\/[^\s]*)$"# + let partsPattern = #"^(http:|https:|\*:)\/\/((?:\*\.)?(?:[a-z0-9-]+\.)+(?:[a-z0-9]+)|\*\.[a-z]+|\*|[a-z0-9]+)(\/[^\s]*)$"# let partsPatternReg = try! NSRegularExpression(pattern: partsPattern, options: .caseInsensitive) let range = NSMakeRange(0, matchPattern.utf16.count) guard let parts = partsPatternReg.firstMatch(in: matchPattern, options: [], range: range) else { err("malformed regex match pattern") return false } + // ensure url protocol matches pattern protocol + let protocolPattern = matchPattern[Range(parts.range(at: 1), in: matchPattern)!] + if (protocolPattern != "*:" && ptcl != protocolPattern) { + return false + } // construct host regex from matchPattern let matchPatternHost = matchPattern[Range(parts.range(at: 2), in: matchPattern)!] var hostPattern = "^\(matchPatternHost.replacingOccurrences(of: ".", with: "\\."))$" From 125f16cb0560de38e7ec04704976565ff69101a2 Mon Sep 17 00:00:00 2001 From: quoid Date: Wed, 17 Aug 2022 20:13:44 -0400 Subject: [PATCH 15/22] update matching test --- .../UserscriptsTests/UserscriptsTests.swift | 93 +++++++++++++++---- 1 file changed, 76 insertions(+), 17 deletions(-) diff --git a/extension/UserscriptsTests/UserscriptsTests.swift b/extension/UserscriptsTests/UserscriptsTests.swift index c3e1a608..e708ecc9 100644 --- a/extension/UserscriptsTests/UserscriptsTests.swift +++ b/extension/UserscriptsTests/UserscriptsTests.swift @@ -118,27 +118,86 @@ class UserscriptsTests: XCTestCase { } func testMatching() throws { - let pattern = "*://www.google.com/*" - let urls = [ - "https://www.google.com/://aa", - "https://www.google.com/preferences?prev=https://www.google.com/", - "https://www.google.com/preferences?prev=", - "https://www.google.com/" - ] + var count = 0 var result = [String]() - for url in urls { - if - let parts = getUrlProps(url), - let ptcl = parts["protocol"], - let host = parts["host"], - let path = parts["pathname"] - { - if match(ptcl, host, path, pattern) { - result.append("1") + let patternDict = [ + "*://*/*": [ + "https://www.bing.com/", + "https://example.org/foo/bar.html", + "https://a.org/some/path/" + ], + "*://*.mozilla.org/*": [ + "http://mozilla.org/", + "https://mozilla.org/", + "https://b.mozilla.org/path/" + ], + "*://www.google.com/*": [ + "https://www.google.com/://aa", + "https://www.google.com/preferences?prev=https://www.google.com/", + "https://www.google.com/preferences?prev=", + "https://www.google.com/" + ], + "*://localhost/*": [ + "http://localhost:8000/", + "https://localhost:3000/foo.html" + ], + "http://127.0.0.1/*": [ + "http://127.0.0.1/", + "http://127.0.0.1/foo/bar.html" + ] + ] + let patternDictFails = [ + "https://www.example.com/*": [ + "file://www.example.com/", + "ftp://www.example.com/", + "ws://www.example.com/", + "http://www.example.com/" + ], + "http://www.example.com/index.html": [ + "http://www.example.com/", + "https://www.example.com/index.html" + ], + "*://localhost/*": [ + "https://localhost.com/", + "ftp://localhost:8080/" + ], + "https://www.example*/*": [ + "https://www.example.com/" + ] + ] + for (pattern, urls) in patternDict { + count = count + urls.count + for url in urls { + if + let parts = getUrlProps(url), + let ptcl = parts["protocol"], + let host = parts["host"], + let path = parts["pathname"] + { + if match(ptcl, host, path, pattern) { + result.append("1") + } } } } - XCTAssert(result.count == urls.count) + for (pattern, urls) in patternDictFails { + // don't increment count since these tests should fail + for url in urls { + if + let parts = getUrlProps(url), + let ptcl = parts["protocol"], + let host = parts["host"], + let path = parts["pathname"] + { + if match(ptcl, host, path, pattern) { + // if these match, results will get an extra element + // and then the test will fail + result.append("1") + } + } + } + } + XCTAssert(result.count == count) } func testPerformanceExample() throws { From 7bd1a588efce3fed1e834379d5e374cd2074913c Mon Sep 17 00:00:00 2001 From: quoid Date: Wed, 17 Aug 2022 20:15:10 -0400 Subject: [PATCH 16/22] bump build --- extension/Userscripts.xcodeproj/project.pbxproj | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/extension/Userscripts.xcodeproj/project.pbxproj b/extension/Userscripts.xcodeproj/project.pbxproj index b34a79cc..1bf9ba3b 100644 --- a/extension/Userscripts.xcodeproj/project.pbxproj +++ b/extension/Userscripts.xcodeproj/project.pbxproj @@ -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 = 28; + CURRENT_PROJECT_VERSION = 29; DEVELOPMENT_TEAM = J74Q8V8V8N; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "Userscripts-iOS/Info.plist"; @@ -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 = 28; + CURRENT_PROJECT_VERSION = 29; DEVELOPMENT_TEAM = J74Q8V8V8N; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "Userscripts-iOS/Info.plist"; @@ -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 = 28; + CURRENT_PROJECT_VERSION = 29; DEVELOPMENT_TEAM = J74Q8V8V8N; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "Userscripts-iOS Extension/Info.plist"; @@ -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 = 28; + CURRENT_PROJECT_VERSION = 29; DEVELOPMENT_TEAM = J74Q8V8V8N; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "Userscripts-iOS Extension/Info.plist"; @@ -929,7 +929,7 @@ CODE_SIGN_ENTITLEMENTS = "Userscripts Extension/Userscripts Extension.entitlements"; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 56; + CURRENT_PROJECT_VERSION = 57; DEVELOPMENT_TEAM = J74Q8V8V8N; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = "Userscripts Extension/Info.plist"; @@ -953,7 +953,7 @@ CODE_SIGN_ENTITLEMENTS = "Userscripts Extension/Userscripts Extension.entitlements"; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 56; + CURRENT_PROJECT_VERSION = 57; DEVELOPMENT_TEAM = J74Q8V8V8N; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = "Userscripts Extension/Info.plist"; @@ -980,7 +980,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 56; + CURRENT_PROJECT_VERSION = 57; DEVELOPMENT_TEAM = J74Q8V8V8N; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = Userscripts/Info.plist; @@ -1005,7 +1005,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 56; + CURRENT_PROJECT_VERSION = 57; DEVELOPMENT_TEAM = J74Q8V8V8N; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = Userscripts/Info.plist; From 22379562eaffb9be2a7e93c2e5c50b37099cd4c9 Mon Sep 17 00:00:00 2001 From: quoid Date: Thu, 18 Aug 2022 17:37:22 -0400 Subject: [PATCH 17/22] support for GM_info.script.icon #302 --- README.md | 1 + extension/Userscripts Extension/Functions.swift | 2 ++ extension/Userscripts Extension/Resources/page.html | 2 +- extension/Userscripts Extension/Resources/page.js | 1 + src/page/utils.js | 1 + 5 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2d58d885..95adc967 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,7 @@ Userscripts Safari currently supports the following userscript metadata: - `@name` - This will be the name that displays in the sidebar and be used as the filename - you can *not* use the same name for multiple files of the same type - `@description`- Use this to describe what your userscript does - this will be displayed in the sidebar - there is a setting to hide descriptions +- `@icon` - This doesn't have a function in this userscript managers, but the **first value** provided in the metadata will be accessible in the `GM_/GM.info` - `@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 diff --git a/extension/Userscripts Extension/Functions.swift b/extension/Userscripts Extension/Functions.swift index 3e69911b..2e25b6ba 100644 --- a/extension/Userscripts Extension/Functions.swift +++ b/extension/Userscripts Extension/Functions.swift @@ -1299,6 +1299,7 @@ func getCode(_ filenames: [String], _ isTop: Bool)-> [String: Any]? { let description = metadata["description"]?[0] ?? "" let excludes = metadata["exclude"] ?? [] let excludeMatches = metadata["exclude-match"] ?? [] + let icon = metadata["icon"]?[0] ?? "" let includes = metadata["include"] ?? [] let matches = metadata["match"] ?? [] let requires = metadata["require"] ?? [] @@ -1310,6 +1311,7 @@ func getCode(_ filenames: [String], _ isTop: Bool)-> [String: Any]? { "exclude-match": excludeMatches, "filename": filename, "grants": grants, + "icon": icon, "includes": includes, "inject-into": injectInto, "matches": matches, diff --git a/extension/Userscripts Extension/Resources/page.html b/extension/Userscripts Extension/Resources/page.html index 7761b95e..d0a7c906 100644 --- a/extension/Userscripts Extension/Resources/page.html +++ b/extension/Userscripts Extension/Resources/page.html @@ -1 +1 @@ -Userscripts Safari
\ No newline at end of file +Userscripts Safari
\ No newline at end of file diff --git a/extension/Userscripts Extension/Resources/page.js b/extension/Userscripts Extension/Resources/page.js index 4f7345c9..0b1358ff 100644 --- a/extension/Userscripts Extension/Resources/page.js +++ b/extension/Userscripts Extension/Resources/page.js @@ -1079,6 +1079,7 @@ var JSHINT;"undefined"==typeof window&&(window={}),function(){var f=function u(o "exclude", "exclude-match", "grant", + "icon", "include", "inject-into", "match", diff --git a/src/page/utils.js b/src/page/utils.js index 34b886c6..b2d0b660 100644 --- a/src/page/utils.js +++ b/src/page/utils.js @@ -164,6 +164,7 @@ export const validKeys = new Set([ "exclude", "exclude-match", "grant", + "icon", "include", "inject-into", "match", From 690875bc668aa0d75197574ca22eab5919b346c4 Mon Sep 17 00:00:00 2001 From: quoid Date: Thu, 18 Aug 2022 17:37:28 -0400 Subject: [PATCH 18/22] bump build --- extension/Userscripts.xcodeproj/project.pbxproj | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/extension/Userscripts.xcodeproj/project.pbxproj b/extension/Userscripts.xcodeproj/project.pbxproj index 1bf9ba3b..b0566c3a 100644 --- a/extension/Userscripts.xcodeproj/project.pbxproj +++ b/extension/Userscripts.xcodeproj/project.pbxproj @@ -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 = 29; + CURRENT_PROJECT_VERSION = 30; DEVELOPMENT_TEAM = J74Q8V8V8N; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "Userscripts-iOS/Info.plist"; @@ -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 = 29; + CURRENT_PROJECT_VERSION = 30; DEVELOPMENT_TEAM = J74Q8V8V8N; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "Userscripts-iOS/Info.plist"; @@ -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 = 29; + CURRENT_PROJECT_VERSION = 30; DEVELOPMENT_TEAM = J74Q8V8V8N; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "Userscripts-iOS Extension/Info.plist"; @@ -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 = 29; + CURRENT_PROJECT_VERSION = 30; DEVELOPMENT_TEAM = J74Q8V8V8N; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "Userscripts-iOS Extension/Info.plist"; @@ -929,7 +929,7 @@ CODE_SIGN_ENTITLEMENTS = "Userscripts Extension/Userscripts Extension.entitlements"; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 57; + CURRENT_PROJECT_VERSION = 58; DEVELOPMENT_TEAM = J74Q8V8V8N; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = "Userscripts Extension/Info.plist"; @@ -953,7 +953,7 @@ CODE_SIGN_ENTITLEMENTS = "Userscripts Extension/Userscripts Extension.entitlements"; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 57; + CURRENT_PROJECT_VERSION = 58; DEVELOPMENT_TEAM = J74Q8V8V8N; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = "Userscripts Extension/Info.plist"; @@ -980,7 +980,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 57; + CURRENT_PROJECT_VERSION = 58; DEVELOPMENT_TEAM = J74Q8V8V8N; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = Userscripts/Info.plist; @@ -1005,7 +1005,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 57; + CURRENT_PROJECT_VERSION = 58; DEVELOPMENT_TEAM = J74Q8V8V8N; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = Userscripts/Info.plist; From ae29d17d248b420b80be83ad3581088bd2cb5d3a Mon Sep 17 00:00:00 2001 From: quoid Date: Thu, 18 Aug 2022 17:38:31 -0400 Subject: [PATCH 19/22] grammar fix #302 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 95adc967..2c145c10 100644 --- a/README.md +++ b/README.md @@ -123,7 +123,7 @@ Userscripts Safari currently supports the following userscript metadata: - `@name` - This will be the name that displays in the sidebar and be used as the filename - you can *not* use the same name for multiple files of the same type - `@description`- Use this to describe what your userscript does - this will be displayed in the sidebar - there is a setting to hide descriptions -- `@icon` - This doesn't have a function in this userscript managers, but the **first value** provided in the metadata will be accessible in the `GM_/GM.info` +- `@icon` - This doesn't have a function with this userscript manager, but the **first value** provided in the metadata will be accessible in the `GM_/GM.info` object - `@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 From 125ef461f94615fc597503d17d546aeffb83acb7 Mon Sep 17 00:00:00 2001 From: spd2last Date: Tue, 23 Aug 2022 22:35:48 -0400 Subject: [PATCH 20/22] Fixing type on 'onloadstart' in line 210 --- extension/Userscripts Extension/Resources/background.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension/Userscripts Extension/Resources/background.js b/extension/Userscripts Extension/Resources/background.js index f6290b83..6b7190f6 100644 --- a/extension/Userscripts Extension/Resources/background.js +++ b/extension/Userscripts Extension/Resources/background.js @@ -207,7 +207,7 @@ const apis = { } else if (name.includes("READYSTATECHANGE") && details.onreadystatechange) { details.onreadystatechange(response); } else if (name.includes("LOADSTART") && details.onloadstart) { - details.onloadtstart(response); + details.onloadstart(response); } else if (name.includes("ABORT") && details.onabort) { details.onabort(response); } else if (name.includes("ERROR") && details.onerror) { From dffdc117b9a6e6b3081b755be6166965c73c4ff2 Mon Sep 17 00:00:00 2001 From: Weijie Zhao Date: Thu, 25 Aug 2022 21:34:10 +0800 Subject: [PATCH 21/22] return empty tab obj instead of null --- extension/Userscripts Extension/Resources/background.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension/Userscripts Extension/Resources/background.js b/extension/Userscripts Extension/Resources/background.js index beb10372..c0b10409 100644 --- a/extension/Userscripts Extension/Resources/background.js +++ b/extension/Userscripts Extension/Resources/background.js @@ -795,7 +795,7 @@ browser.runtime.onMessage.addListener((request, sender, sendResponse) => { } catch (error) { console.error("failed to parse tab data for getTab"); } - sendResponse(tab); + sendResponse(tab == null ? {} : tab); } else { console.error("unable to deliver tab due to empty tab id"); sendResponse(null); From 4c2d8fe79ec5979e4594e49a2d381f5213a3d644 Mon Sep 17 00:00:00 2001 From: quoid Date: Thu, 25 Aug 2022 22:23:02 -0400 Subject: [PATCH 22/22] bump build --- extension/Userscripts.xcodeproj/project.pbxproj | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/extension/Userscripts.xcodeproj/project.pbxproj b/extension/Userscripts.xcodeproj/project.pbxproj index b0566c3a..17959b8e 100644 --- a/extension/Userscripts.xcodeproj/project.pbxproj +++ b/extension/Userscripts.xcodeproj/project.pbxproj @@ -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 = 30; + CURRENT_PROJECT_VERSION = 31; DEVELOPMENT_TEAM = J74Q8V8V8N; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "Userscripts-iOS/Info.plist"; @@ -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 = 30; + CURRENT_PROJECT_VERSION = 31; DEVELOPMENT_TEAM = J74Q8V8V8N; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "Userscripts-iOS/Info.plist"; @@ -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 = 30; + CURRENT_PROJECT_VERSION = 31; DEVELOPMENT_TEAM = J74Q8V8V8N; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "Userscripts-iOS Extension/Info.plist"; @@ -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 = 30; + CURRENT_PROJECT_VERSION = 31; DEVELOPMENT_TEAM = J74Q8V8V8N; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "Userscripts-iOS Extension/Info.plist"; @@ -929,7 +929,7 @@ CODE_SIGN_ENTITLEMENTS = "Userscripts Extension/Userscripts Extension.entitlements"; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 58; + CURRENT_PROJECT_VERSION = 59; DEVELOPMENT_TEAM = J74Q8V8V8N; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = "Userscripts Extension/Info.plist"; @@ -953,7 +953,7 @@ CODE_SIGN_ENTITLEMENTS = "Userscripts Extension/Userscripts Extension.entitlements"; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 58; + CURRENT_PROJECT_VERSION = 59; DEVELOPMENT_TEAM = J74Q8V8V8N; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = "Userscripts Extension/Info.plist"; @@ -980,7 +980,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 58; + CURRENT_PROJECT_VERSION = 59; DEVELOPMENT_TEAM = J74Q8V8V8N; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = Userscripts/Info.plist; @@ -1005,7 +1005,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 58; + CURRENT_PROJECT_VERSION = 59; DEVELOPMENT_TEAM = J74Q8V8V8N; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = Userscripts/Info.plist;