Skip to content

Commit

Permalink
1.17.5
Browse files Browse the repository at this point in the history
[mv3] Load user script for iframes
  • Loading branch information
brookhong committed Nov 25, 2024
1 parent 3eaff3f commit eb58929
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Surfingkeys",
"version": "1.17.4",
"version": "1.17.5",
"description": "Map your keys for web surfing, expand your browser with javascript and keyboard.",
"main": "background.js",
"directories": {
Expand Down
3 changes: 3 additions & 0 deletions src/content_scripts/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ window.getFrameId = function () {
&& window.frameElement.offsetWidth > 16 && window.frameElement.offsetWidth > 16))
) {
_initContent(_initModules());

// Only used to load user script for iframes in MV3
dispatchSKEvent('user', ["runUserScript"]);
}
return window.frameId;
};
Expand Down
21 changes: 15 additions & 6 deletions src/user_scripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const functionsToListSuggestions = {};
let inlineQuery;
let hintsFunction;
let onClipboardReadFn;
let userScriptTask = () => {};
initSKFunctionListener("user", {
callUserFunction: (keys, para) => {
if (userDefinedFunctions.hasOwnProperty(keys)) {
Expand All @@ -93,6 +94,9 @@ initSKFunctionListener("user", {
}
});
},
runUserScript: () => {
userScriptTask();
},
onClipboardRead: (resp) => {
onClipboardReadFn(resp);
},
Expand Down Expand Up @@ -227,11 +231,16 @@ const api = {
export default (extensionRootUrl, uf) => {
EXTENSION_ROOT_URL = extensionRootUrl;
if (isInUIFrame()) return;
var settings = {}, error = "";
try {
uf(api, settings);
} catch(e) {
error = e.toString();
userScriptTask = () => {
var settings = {}, error = "";
try {
uf(api, settings);
} catch(e) {
error = e.toString();
}
applyUserSettings({settings, error});
};
if (window === top) {
userScriptTask();
}
applyUserSettings({settings, error});
};

0 comments on commit eb58929

Please sign in to comment.