import org.kde.falkon 1.0 as Falkon import QtQuick.Controls 2.3 import QtQuick.Layouts 1.0 import QtQuick 2.3 Falkon.PluginInterface { QtObject { id: rssFinderObject property ListModel feeds: ListModel {} } init: function(state, settingsPath){ console.log(i18n('"RSSFinder" plugin loaded')) } testPlugin: function() { return true } unload: function() { console.log(i18n('"RSSFinder" plugin unloaded')) } function findCurrentTab(window) { for (var i = 0; i < window.tabs.length; ++i) { if (window.tabs[i].current) { return window.tabs[i] } } } function findFeeds() { 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; ") rssFinderObject.feeds.clear() for (var link of result.links) { rssFinderObject.feeds.append({ "title": link.title, "url": link.url }) } } Falkon.BrowserAction { name: 'RSS Finder' identity: 'rssfinder-id' title: i18n('RSS Finder') toolTip: i18n('RSS Finder') icon: 'rss' location: Falkon.BrowserAction.NavigationToolBar | Falkon.BrowserAction.StatusBar onClicked: findFeeds() popup: ScrollView { id: popupWindow width: 500 height: 200 ScrollBar.horizontal.policy: ScrollBar.AlwaysOn ScrollBar.vertical.policy: ScrollBar.AlwaysOn ListView { Component { id: contactsDelegate Button { hoverEnabled: true width: popupWindow.width onClicked: Falkon.Clipboard.copy(url) ToolTip.delay: 1000 ToolTip.timeout: 5000 ToolTip.visible: hovered ToolTip.text: i18n("Click to copy URL") ColumnLayout { id: wrapper spacing: 0 Text { font.bold: true text: title } Text { text: url } } } } model: rssFinderObject.feeds delegate: contactsDelegate focus: true } } } }