aboutsummaryrefslogtreecommitdiff
path: root/src/content/components
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2017-10-14 13:18:46 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2017-10-14 13:18:46 +0900
commitfc90f78e26dcf9531ec3702f99a3a45fd8cd4a18 (patch)
tree918b5bf4930aefdf249eded45de1b670b5ad2c51 /src/content/components
parentbebf8e23275156d39decbc974bcc05fa1d977d26 (diff)
load content script all_frames and click link
Diffstat (limited to 'src/content/components')
-rw-r--r--src/content/components/follow.js44
1 files changed, 20 insertions, 24 deletions
diff --git a/src/content/components/follow.js b/src/content/components/follow.js
index 3307893..3f28cc2 100644
--- a/src/content/components/follow.js
+++ b/src/content/components/follow.js
@@ -90,33 +90,29 @@ export default class FollowComponent {
});
}
+ openLink(element) {
+ if (!this.state.newTab) {
+ element.click();
+ return;
+ }
+
+ let href = element.getAttribute('href');
+
+ // eslint-disable-next-line no-script-url
+ if (!href || href === '#' || href.toLowerCase().startsWith('javascript:')) {
+ return;
+ }
+ return browser.runtime.sendMessage({
+ type: messages.OPEN_URL,
+ url: element.href,
+ newTab: this.state.newTab,
+ });
+ }
+
activate(element) {
switch (element.tagName.toLowerCase()) {
case 'a':
- if (this.state.newTab) {
- // getAttribute() to avoid to resolve absolute path
- let href = element.getAttribute('href');
-
- // eslint-disable-next-line no-script-url
- if (!href || href === '#' || href.startsWith('javascript:')) {
- return;
- }
- return browser.runtime.sendMessage({
- type: messages.OPEN_URL,
- url: element.href,
- newTab: this.state.newTab,
- });
- }
- if (element.href.startsWith('http://') ||
- element.href.startsWith('https://') ||
- element.href.startsWith('ftp://')) {
- return browser.runtime.sendMessage({
- type: messages.OPEN_URL,
- url: element.href,
- newTab: this.state.newTab,
- });
- }
- return element.click();
+ return this.openLink(element, this.state.newTab);
case 'input':
switch (element.type) {
case 'file':