Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-155: Added ability to open external iframes in their own tab. #169

Merged
merged 1 commit into from
Feb 26, 2024
Merged
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
13 changes: 13 additions & 0 deletions src/css/iframe-wrapper.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
a.gamepad-navigator-iframe-wrapper {
display: block;
height: max-content;
margin: 0;
padding: 0;
width: max-content;
}

a.gamepad-navigator-iframe-wrapper:focus {
background-color: white;
border: 3px dashed white;
mix-blend-mode: difference;
}
62 changes: 62 additions & 0 deletions src/js/content_scripts/input-mapper-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ https://github.com/fluid-lab/gamepad-navigator/blob/main/LICENSE
"prefs.controlsOnAllMedia": {
func: "{that}.updateMediaControls",
args: [true] // performFullUpdate
},
"prefs.linkExternalIframes": {
func: "{that}.updateExternalIframes",
args: [true] // performFullUpdate
}
},
listeners: {
Expand Down Expand Up @@ -67,6 +71,10 @@ https://github.com/fluid-lab/gamepad-navigator/blob/main/LICENSE
funcName: "gamepad.inputMapper.base.updateMediaControls",
args: ["{that}", "{arguments}.0"] // performFullUpdate
},
updateExternalIframes: {
funcName: "gamepad.inputMapper.base.updateExternalIframes",
args: ["{that}", "{arguments}.0"] // performFullUpdate
},
produceNavigation: {
funcName: "gamepad.inputMapper.base.produceNavigation",
args: ["{that}", "{arguments}.0"]
Expand Down Expand Up @@ -326,6 +334,7 @@ https://github.com/fluid-lab/gamepad-navigator/blob/main/LICENSE

gamepad.inputMapper.base.handleDOMMutation = function (that) {
that.updateMediaControls();
that.updateExternalIframes();

gamepad.inputMapper.base.listenForFullscreenChanges(that);

Expand Down Expand Up @@ -403,6 +412,59 @@ https://github.com/fluid-lab/gamepad-navigator/blob/main/LICENSE
}
};

gamepad.inputMapper.base.updateExternalIframes = function (that, performFullUpdate) {
if (that.model.prefs.linkExternalIframes) {
gamepad.inputMapper.base.wrapExternalIframes();
}
else if (performFullUpdate) {
gamepad.inputMapper.base.unwrapExternalIframes();
}
};

gamepad.inputMapper.base.wrapExternalIframes = function () {
var iframeElements = document.querySelectorAll("iframe");
for (var iframeIndex = 0; iframeIndex < iframeElements.length; iframeIndex++) {
var iframeElement = iframeElements[iframeIndex];
if (!iframeElement.currentDocument) {
gamepad.inputMapper.base.wrapIframeElement(iframeElement);
}
}
};

gamepad.inputMapper.base.unwrapExternalIframes = function () {
var wrapperElements = document.querySelectorAll("a.gamepad-navigator-iframe-wrapper");
for (var wrapperIndex = 0; wrapperIndex < wrapperElements.length; wrapperIndex++) {
var wrapperElement = wrapperElements[wrapperIndex];
gamepad.inputMapper.base.unwrapIframeElement(wrapperElement);
}
};

gamepad.inputMapper.base.wrapIframeElement = function (iframeElement) {
if (!iframeElement.parentElement.classList.contains("gamepad-navigator-iframe-wrapper")) {
var src = iframeElement.getAttribute("src");
if (src && src.length) {
var wrapper = document.createElement("a");
wrapper.classList.add("gamepad-navigator-iframe-wrapper");
wrapper.setAttribute("href", src);

var iframeTitle = iframeElement.getAttribute("title");

var anchorAlt = iframeTitle && iframeTitle.length ? iframeTitle : "Open iframe content";
wrapper.setAttribute("alt", anchorAlt);

iframeElement.parentElement.insertBefore(wrapper, iframeElement);

wrapper.appendChild(iframeElement);
}
}
};

gamepad.inputMapper.base.unwrapIframeElement = function (wrapperElement) {
var iframeElement = wrapperElement.removeChild(wrapperElement.firstElementChild);
wrapperElement.parentElement.insertBefore(iframeElement, wrapperElement);
wrapperElement.remove();
};

gamepad.inputMapper.base.vibrate = function (that) {
if (that.model.prefs.vibrate) {
var gamepads = that.options.windowObject.navigator.getGamepads();
Expand Down
11 changes: 11 additions & 0 deletions src/js/settings/prefsPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,17 @@ https://github.com/fluid-lab/gamepad-navigator/blob/main/LICENSE
checked: "{gamepad.settings.ui.prefsPanel}.model.draftPrefs.fixFocus"
}
}
},
linkExternalIframes: {
container: "{that}.dom.body",
type: "gamepad.ui.prefs.toggle",
options: {
model: {
label: "Link External iframes",
description: "Iframe elements embed content from other pages. If these pages are hosted on other sites, the gamepad navigator can't control them directly. If this setting is on, uncontrollable iframes will be wrapped in a link that can be used to open the content.",
checked: "{gamepad.settings.ui.prefsPanel}.model.draftPrefs.linkExternalIframes"
}
}
}
}
});
Expand Down
1 change: 1 addition & 0 deletions src/js/shared/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ https://github.com/fluid-lab/gamepad-navigator/blob/main/LICENSE
arrowModals: true,
controlsOnAllMedia: true,
fixFocus: false,
linkExternalIframes: true,
newTabOrWindowURL: "https://www.google.com/",
openWindowOnStartup: true,
pollingFrequency: 50,
Expand Down
5 changes: 4 additions & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
"matches": [
"<all_urls>"
],
"css": ["css/focus-fix.css"],
"css": [
"css/focus-fix.css",
"css/iframe-wrapper.css"
],
"js": [
"js/lib/infusion/infusion-all.js",
"js/lib/ally/ally.min.js",
Expand Down
Loading