Move site js code to separate file "finder.js"
Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
This commit is contained in:
parent
0a857ba5e6
commit
86747dbadc
50
rssfinder/finder.js
Normal file
50
rssfinder/finder.js
Normal file
@ -0,0 +1,50 @@
|
||||
(function() {
|
||||
|
||||
var availableLinks = [];
|
||||
var links = document.getElementsByTagName('link');
|
||||
var siteTitle = 'No title was found';
|
||||
|
||||
if (document.getElementsByTagName('title').lenght > 0) {
|
||||
siteTitle = document.getElementsByTagName('title')[0].innerHTML
|
||||
}
|
||||
|
||||
for (link of links) {
|
||||
if (link.getAttribute('rel') == 'alternate' && link.getAttribute('type') == 'application/rss+xml') {
|
||||
var linkTitle;
|
||||
var linkUrl;
|
||||
|
||||
if (link.hasAttribute('title')) {
|
||||
linkTitle = link.getAttribute('title');
|
||||
} else {
|
||||
linkTitle = siteTitle;
|
||||
}
|
||||
|
||||
if (link.getAttribute('href').startsWith('/')) {
|
||||
linkUrl = window.location.protocol + '//' + window.location.hostname + link.getAttribute('href');
|
||||
} else if (!link.getAttribute('href').includes('/')) {
|
||||
linkUrl = window.location.protocol + '//' + window.location.hostname + '/' + link.getAttribute('href');
|
||||
} else {
|
||||
linkUrl = link.getAttribute('href');
|
||||
}
|
||||
|
||||
availableLinks.push({
|
||||
title: linkTitle,
|
||||
url: linkUrl
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (links.length == 0) {
|
||||
availableLinks.push({
|
||||
title: 'No RSS feed was found',
|
||||
url: 'No URL is provided'
|
||||
});
|
||||
}
|
||||
|
||||
var out = {
|
||||
links: availableLinks
|
||||
};
|
||||
|
||||
return out;
|
||||
|
||||
})()
|
@ -8,9 +8,15 @@ Falkon.PluginInterface {
|
||||
QtObject {
|
||||
id: rssFinderObject
|
||||
property ListModel feeds: ListModel {}
|
||||
property string jsFinder
|
||||
}
|
||||
|
||||
init: function(state, settingsPath){
|
||||
console.log(i18n('"RSSFinder" plugin is loading'))
|
||||
rssFinderObject.jsFinder = Falkon.FileUtils.readAllFileContents('finder.js')
|
||||
if (rssFinderObject.jsFinder.length == 0) {
|
||||
console.log(i18n('"RSSFinder" Unable to load "finder.js""'))
|
||||
}
|
||||
console.log(i18n('"RSSFinder" plugin loaded'))
|
||||
}
|
||||
|
||||
@ -31,56 +37,13 @@ Falkon.PluginInterface {
|
||||
}
|
||||
|
||||
function findFeeds() {
|
||||
if (rssFinderObject.jsFinder.length == 0) {
|
||||
return
|
||||
}
|
||||
|
||||
var window = Falkon.Windows.getCurrent()
|
||||
var currentTab = findCurrentTab(window)
|
||||
var result = currentTab.execJavaScript("
|
||||
var availableLinks = [];
|
||||
var links = document.getElementsByTagName('link');
|
||||
var siteTitle = 'No title was found';
|
||||
|
||||
if (document.getElementsByTagName('title').lenght > 0) {
|
||||
siteTitle = document.getElementsByTagName('title')[0].innerHTML
|
||||
}
|
||||
|
||||
for (link of links) {
|
||||
if (link.getAttribute('rel') == 'alternate' && link.getAttribute('type') == 'application/rss+xml') {
|
||||
var linkTitle;
|
||||
var linkUrl;
|
||||
|
||||
if (link.hasAttribute('title')) {
|
||||
linkTitle = link.getAttribute('title');
|
||||
} else {
|
||||
linkTitle = siteTitle;
|
||||
}
|
||||
|
||||
if (link.getAttribute('href').startsWith('/')) {
|
||||
linkUrl = window.location.protocol + '//' + window.location.hostname + link.getAttribute('href');
|
||||
} else if (!link.getAttribute('href').includes('/')) {
|
||||
linkUrl = window.location.protocol + '//' + window.location.hostname + '/' + link.getAttribute('href');
|
||||
} else {
|
||||
linkUrl = link.getAttribute('href');
|
||||
}
|
||||
|
||||
availableLinks.push({
|
||||
title: linkTitle,
|
||||
url: linkUrl
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (links.length == 0) {
|
||||
availableLinks.push({
|
||||
title: 'No RSS feed was found',
|
||||
url: 'No URL is provided'
|
||||
});
|
||||
}
|
||||
|
||||
var out = {
|
||||
links: availableLinks
|
||||
};
|
||||
|
||||
out;
|
||||
")
|
||||
var result = currentTab.execJavaScript(rssFinderObject.jsFinder)
|
||||
|
||||
rssFinderObject.feeds.clear()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user