Skip to content

Commit

Permalink
fixes #42
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-portmen committed Nov 29, 2020
1 parent f76912d commit 0e67557
Show file tree
Hide file tree
Showing 17 changed files with 121 additions and 69 deletions.
6 changes: 4 additions & 2 deletions brave/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@
"matches": ["<all_urls>"],
"js": ["data/inject.js"],
"run_at": "document_start",
"all_frames": true
"all_frames": true,
"match_about_blank": true
}],
"options_ui": {
"page": "data/options/index.html",
"chrome_style": true
"chrome_style": true,
"open_in_tab": true
}
}
6 changes: 4 additions & 2 deletions chrome/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@
"matches": ["<all_urls>"],
"js": ["data/inject.js"],
"run_at": "document_start",
"all_frames": true
"all_frames": true,
"match_about_blank": true
}],
"options_ui": {
"page": "data/options/index.html",
"chrome_style": true
"chrome_style": true,
"open_in_tab": true
}
}
7 changes: 4 additions & 3 deletions chromium/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"name": "Open in Chromium Browser",
"short_name": "ioichromium",
"description": "Open current page, link, or all tabs in the Chromium browser.",
"author": "Andy Portmen",
"version": "0.1.3",
Expand Down Expand Up @@ -39,10 +38,12 @@
"matches": ["<all_urls>"],
"js": ["data/inject.js"],
"run_at": "document_start",
"all_frames": true
"all_frames": true,
"match_about_blank": true
}],
"options_ui": {
"page": "data/options/index.html",
"chrome_style": true
"chrome_style": true,
"open_in_tab": true
}
}
45 changes: 39 additions & 6 deletions common/data/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ const config = {
enabled: false,
hosts: [],
urls: [],
reverse: false
reverse: false,
topRedict: false
};

const validate = (a, callback) => {
const validate = (a, callback, isTop = false) => {
if (config.hosts.length) {
const host = a.hostname;
if (host) {
Expand All @@ -30,7 +31,7 @@ const validate = (a, callback) => {
}
}
// reverse mode
if (config.reverse && a.href && a.href.indexOf('#') === -1) {
if (config.reverse && a.href && (a.href.indexOf('#') === -1 || isTop)) {
if (a.href.startsWith('http') || a.href.startsWith('file')) {
return callback(a.href);
}
Expand All @@ -50,7 +51,7 @@ chrome.storage.local.get(config, prefs => {
config.reverse = config.reverse || prefs.reverse;
}
// top level redirect
if (window.top === window) {
if (window.top === window && config.topRedict) {
validate(location, url => {
if (history.length) {
history.back();
Expand All @@ -62,7 +63,39 @@ chrome.storage.local.get(config, prefs => {
cmd: 'open-in',
url
});
});
}, true);
}
// Gmail attachments
// https://github.com/andy-portmen/open-in/issues/42
if (window.top === window && location.hostname === 'mail.google.com') {
validate(location, () => {
const script = document.createElement('script');
script.textContent = `{
const script = document.currentScript;
const hps = Object.getOwnPropertyDescriptor(HTMLIFrameElement.prototype, 'src');
Object.defineProperty(HTMLIFrameElement.prototype, 'src', {
set(v) {
if (v && v.indexOf('&view=att&') !== -1) {
script.dispatchEvent(new CustomEvent('open-request', {
detail: v
}));
}
else {
hps.set.call(this, v);
}
}
});
}`;
script.addEventListener('open-request', e => {
e.stopPropagation();
chrome.runtime.sendMessage({
cmd: 'open-in',
url: e.detail
});
});
document.documentElement.appendChild(script);
script.remove();
}, true);
}
});
});
Expand All @@ -86,7 +119,7 @@ document.addEventListener('click', e => {
};
// hostname on left-click
if (e.button === 0 && !e.altKey && !e.ctrlKey && !e.metaKey && !e.shiftKey) {
if (config.hosts.length || config.urls.length) {
if (config.hosts.length || config.urls.length || config.reverse) {
let a = e.target.closest('a');
if (a) {
if (a.href.startsWith('https://www.google') && a.href.indexOf('&url=') !== -1) {
Expand Down
56 changes: 26 additions & 30 deletions common/data/options/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
<title>Open In Options</title>
<meta charset="UTF-8">
<style>
body {
min-width: 500px;
}
table.tbl {
width: 100%;
}
Expand Down Expand Up @@ -45,6 +42,11 @@
li {
margin-bottom: 5px;
}
.grid {
display: grid;
grid-template-columns: 1fr min-content;
grid-gap: 5px;
}
</style>
</head>

Expand Down Expand Up @@ -85,34 +87,27 @@ <h2>Open with Left-Click</h2>
<td colspan="2"><textarea id="urls" style="width: 100%" rows="3" placeholder="e.g.: https://www.google.com/, https://bing.com/"></textarea></td>
</tr>
</table>
<label style="display: inline-flex; align-items: center;"><input type="checkbox" id="reverse">&nbsp;Reverse Mode<sup>5</sup></label>
<div class="grid">
<label for="reverse">Reverse Mode<sup>5</sup></label>
<input type="checkbox" id="reverse">
<label for="topRedict">Consider even top-level navigation<sup>6</sup></label>
<input type="checkbox" id="topRedict">
</div>
<h2>Misc</h2>
<table class="tbl">
<tbody>
<tr>
<td><label for="closeme">Close the source tab when link is pushed</label></td>
<td><input type="checkbox" id="closeme"></td>
</tr>
<tr>
<td><label for="multiple">Open multiple links at once<sup>3</sup></label></td>
<td><input type="checkbox" id="multiple"></td>
</tr>
<tr>
<td><label for="faqs">Open FAQs page on updates</label></td>
<td><input type="checkbox" id="faqs"></td>
</tr>
<tr>
<td colspan="2" style="text-align: left;">Path to the executable<sup>2</sup>:</td>
</tr>
<tr>
<td colspan="2">
<div style="display: flex;">
<input type="text" id="path" style="flex: 1;">
</div>
</td>
</tr>
</tbody>
</table>
<div class="grid">
<label for="closeme">Close the source tab when link is pushed</label>
<input type="checkbox" id="closeme">
<label for="multiple">Open multiple links at once<sup>3</sup></label>
<input type="checkbox" id="multiple">
<label for="faqs">Open FAQs page on updates</label>
<input type="checkbox" id="faqs">
</div>
<div>
<span style="margin-top: 10px; margin-bottom: 5px; display: block">Path to the executable<sup>2</sup>:</span>
<div style="display: flex;">
<input type="text" id="path" style="flex: 1;">
</div>
</div>

<div class="admin">This extension supports managed storage. Some of the preferences can be pre-configured by <a href="https://add0n.com/open-in.html#faq17">the domain administrator</a></div>

Expand All @@ -130,6 +125,7 @@ <h2>Misc</h2>
<li>By activating this option all the requested URLs are sent to the external executable at once. Only activate this option if the external executable is capable of handling this type of requests.</li>
<li>Not all key combinations are allowed in all operating systems.</li>
<li>When enabled, all left-click links except the ones that match with at least one condition will be sent to the external executable.</li>
<li>If checked, the extension validates top-level navigation with the list of left-click hostnames and URLs. If matched, the URL is sent to the external executable, and the navigation is blocked.</li>
</ol style="padding-left: 1.8em;">

<script src="../../config.js"></script>
Expand Down
8 changes: 6 additions & 2 deletions common/data/options/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ function restore() {
multiple: app.multiple,
hosts: [],
urls: [],
reverse: false
reverse: false,
topRedict: false
}, prefs => {
document.getElementById('path').value = prefs.path;
document.getElementById('enabled').checked = prefs.enabled;
Expand All @@ -37,6 +38,7 @@ function restore() {
document.getElementById('hosts').value = prefs.hosts.join(', ');
document.getElementById('urls').value = prefs.urls.join(', ');
document.getElementById('reverse').checked = prefs.reverse;
document.getElementById('topRedict').checked = prefs.topRedict;
});
}

Expand All @@ -54,6 +56,7 @@ function save() {
const hosts = document.getElementById('hosts').value;
const urls = document.getElementById('urls').value;
const reverse = document.getElementById('reverse').checked;
const topRedict = document.getElementById('topRedict').checked;

chrome.storage.local.set({
path,
Expand All @@ -72,7 +75,8 @@ function save() {
.filter((h, i, l) => h && l.indexOf(h) === i),
urls: urls.split(/\s*,\s*/).filter(s => s.startsWith('http') || s.startsWith('file'))
.filter((h, i, l) => h && l.indexOf(h) === i),
reverse
reverse,
topRedict
}, () => {
restore();
const status = document.getElementById('status');
Expand Down
2 changes: 1 addition & 1 deletion common/data/options/matched.js
2 changes: 1 addition & 1 deletion common/data/options/matched.json
6 changes: 4 additions & 2 deletions edge/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@
"matches": ["<all_urls>"],
"js": ["data/inject.js"],
"run_at": "document_start",
"all_frames": true
"all_frames": true,
"match_about_blank": true
}],
"options_ui": {
"page": "data/options/index.html",
"chrome_style": true
"chrome_style": true,
"open_in_tab": true
}
}
6 changes: 4 additions & 2 deletions firefox/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@
"matches": ["<all_urls>"],
"js": ["data/inject.js"],
"run_at": "document_start",
"all_frames": true
"all_frames": true,
"match_about_blank": true
}],
"options_ui": {
"page": "data/options/index.html",
"chrome_style": true
"chrome_style": true,
"open_in_tab": true
}
}
7 changes: 4 additions & 3 deletions ie/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"name": "Open in IE",
"short_name": "ioiie",
"description": "Open current page, link, or all tabs in the Internet Explorer browser.",
"author": "Andy Portmen",
"version": "0.2.3",
Expand Down Expand Up @@ -39,10 +38,12 @@
"matches": ["<all_urls>"],
"js": ["data/inject.js"],
"run_at": "document_start",
"all_frames": true
"all_frames": true,
"match_about_blank": true
}],
"options_ui": {
"page": "data/options/index.html",
"chrome_style": true
"chrome_style": true,
"open_in_tab": true
}
}
7 changes: 4 additions & 3 deletions opera/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"name": "Open in Opera",
"short_name": "ioiopera",
"description": "Open current page, link, or all tabs in the Opera browser.",
"author": "Andy Portmen",
"version": "0.1.9",
Expand Down Expand Up @@ -39,10 +38,12 @@
"matches": ["<all_urls>"],
"js": ["data/inject.js"],
"run_at": "document_start",
"all_frames": true
"all_frames": true,
"match_about_blank": true
}],
"options_ui": {
"page": "data/options/index.html",
"chrome_style": true
"chrome_style": true,
"open_in_tab": true
}
}
6 changes: 4 additions & 2 deletions palemoon/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@
"matches": ["<all_urls>"],
"js": ["data/inject.js"],
"run_at": "document_start",
"all_frames": true
"all_frames": true,
"match_about_blank": true
}],
"options_ui": {
"page": "data/options/index.html",
"chrome_style": true
"chrome_style": true,
"open_in_tab": true
}
}
7 changes: 4 additions & 3 deletions safari/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"name": "Open in Safari",
"short_name": "ioisafari",
"description": "Open current page, link, or all tabs in the Safari browser.",
"author": "Andy Portmen",
"version": "0.2.0",
Expand Down Expand Up @@ -39,10 +38,12 @@
"matches": ["<all_urls>"],
"js": ["data/inject.js"],
"run_at": "document_start",
"all_frames": true
"all_frames": true,
"match_about_blank": true
}],
"options_ui": {
"page": "data/options/index.html",
"chrome_style": true
"chrome_style": true,
"open_in_tab": true
}
}
7 changes: 4 additions & 3 deletions vivaldi/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"name": "Open in Vivaldi",
"short_name": "ioivivaldi",
"description": "Open current page, link, or all tabs in the Vivaldi browser.",
"author": "Andy Portmen",
"version": "0.1.9",
Expand Down Expand Up @@ -39,10 +38,12 @@
"matches": ["<all_urls>"],
"js": ["data/inject.js"],
"run_at": "document_start",
"all_frames": true
"all_frames": true,
"match_about_blank": true
}],
"options_ui": {
"page": "data/options/index.html",
"chrome_style": true
"chrome_style": true,
"open_in_tab": true
}
}
Loading

0 comments on commit 0e67557

Please sign in to comment.