-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
avoid redeclaration of const/let; don't execute hasFeeds() call more …
…often than necessary
- Loading branch information
Showing
3 changed files
with
52 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,27 @@ | ||
'use strict'; | ||
|
||
const feeds = []; | ||
const links = document.getElementsByTagName('link'); | ||
const linksLength = links.length; | ||
// use IIFE to avoid redeclaration of const/let | ||
(() => { | ||
const links = document.getElementsByTagName('link'); | ||
const linksLength = links.length; | ||
let hasFeeds = false; | ||
|
||
for (let i = 0; i < linksLength; i++) { | ||
const link = links[i]; | ||
if (link.type && link.rel && link.rel.split(' ').indexOf('alternate') >= 0) { | ||
if (link.type.indexOf('rss') >= 0 || link.type.indexOf('atom') >= 0) { | ||
if (link.href && link.href.length > 0) { | ||
feeds.push(encodeURIComponent(link.href)); | ||
for (let i = 0; i < linksLength; i++) { | ||
const link = links[i]; | ||
if (link.type && link.rel && link.rel.split(' ').indexOf('alternate') >= 0) { | ||
if (link.type.indexOf('rss') >= 0 || link.type.indexOf('atom') >= 0) { | ||
if (link.href && link.href.length > 0) { | ||
hasFeeds = true; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
if (feeds.length > 0) { | ||
browser.runtime.sendMessage({ message : 'has_feed' }); | ||
} | ||
else { | ||
browser.runtime.sendMessage({ message : 'has_no_feed' }); | ||
} | ||
if (hasFeeds) { | ||
browser.runtime.sendMessage({ message : 'has_feed' }); | ||
} | ||
else { | ||
browser.runtime.sendMessage({ message : 'has_no_feed' }); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,35 @@ | ||
'use strict'; | ||
|
||
/* global feeds */ | ||
// use IIFE to avoid redeclaration of const/let | ||
(() => { | ||
const feeds = []; | ||
const links = document.getElementsByTagName('link'); | ||
const linksLength = links.length; | ||
const iframe = document.createElement('iframe'); | ||
const resource = window.location.toString(); | ||
let loaded = false; | ||
|
||
const iframe = document.createElement('iframe'); | ||
const resource = window.location.toString(); | ||
let loaded = false; | ||
for (let i = 0; i < linksLength; i++) { | ||
const link = links[i]; | ||
if (link.type && link.rel && link.rel.split(' ').indexOf('alternate') >= 0) { | ||
if (link.type.indexOf('rss') >= 0 || link.type.indexOf('atom') >= 0) { | ||
if (link.href && link.href.length > 0) { | ||
feeds.push(encodeURIComponent(link.href)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
iframe.setAttribute('style', 'display:block; position:fixed; top:0px; left:0px; width:100%; height:100%; border:0px; background: transparent; z-index: 2147483647'); | ||
iframe.setAttribute('src', 'https://www.subtome.com/?subs/#/subscribe?resource=' + encodeURIComponent(resource) + '&feeds=' + encodeURIComponent(feeds.join(','))); | ||
iframe.setAttribute('style', 'display:block; position:fixed; top:0px; left:0px; width:100%; height:100%; border:0px; background: transparent; z-index: 2147483647'); | ||
iframe.setAttribute('src', 'https://www.subtome.com/?subs/#/subscribe?resource=' + encodeURIComponent(resource) + '&feeds=' + encodeURIComponent(feeds.join(','))); | ||
|
||
iframe.onload = function () { | ||
if (loaded) { | ||
document.getElementsByTagName('body')[0].removeChild(iframe); | ||
} | ||
iframe.onload = function () { | ||
if (loaded) { | ||
document.getElementsByTagName('body')[0].removeChild(iframe); | ||
} | ||
|
||
loaded = true; | ||
}; | ||
loaded = true; | ||
}; | ||
|
||
document.getElementsByTagName('body')[0].appendChild(iframe); | ||
document.getElementsByTagName('body')[0].appendChild(iframe); | ||
})(); |