105 lines
3.4 KiB
QML
105 lines
3.4 KiB
QML
|
import org.kde.falkon 1.0 as Falkon
|
||
|
import QtQuick.Controls 2.3
|
||
|
import QtQuick.Layouts 1.0
|
||
|
import QtQuick 2.3
|
||
|
|
||
|
Falkon.PluginInterface {
|
||
|
|
||
|
init: function(state, settingsPath) {
|
||
|
}
|
||
|
|
||
|
testPlugin: function() {
|
||
|
return true
|
||
|
}
|
||
|
|
||
|
unload: function() {
|
||
|
}
|
||
|
|
||
|
function findCurrentTab() {
|
||
|
var window = Falkon.Windows.getCurrent()
|
||
|
for (var i = 0; i < window.tabs.length; ++i) {
|
||
|
if (window.tabs[i].current) {
|
||
|
return window.tabs[i]
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function currentDomain(url) {
|
||
|
var result = url.match(/:\/\/(.[^/:#?]+)/)[1];
|
||
|
return result
|
||
|
}
|
||
|
|
||
|
function escapeForPre(text) {
|
||
|
return String(text).replace(/&/g, "&")
|
||
|
.replace(/</g, "<")
|
||
|
.replace(/>/g, ">")
|
||
|
.replace(/"/g, """)
|
||
|
.replace(/'/g, "'");
|
||
|
}
|
||
|
|
||
|
function exportCookies(onlyCurrentSite = false) {
|
||
|
var currentTab = findCurrentTab()
|
||
|
var cookies = Falkon.Cookies.getAll({})
|
||
|
var domain = currentDomain(currentTab.url)
|
||
|
var content = ""
|
||
|
var downloadable = ""
|
||
|
downloadable += "# Netscape HTTP Cookie File\n"
|
||
|
downloadable += "# https://curl.haxx.se/rfc/cookie_spec.html\n"
|
||
|
downloadable += "# This is a generated file! Do not edit.\n\n"
|
||
|
|
||
|
for (var i = 0; i < cookies.length; ++i) {
|
||
|
if (cookies[i].domain.indexOf(domain) != -1
|
||
|
|| cookies[i].domain.endsWith(domain)
|
||
|
|| domain.endsWith(cookies[i].domain)
|
||
|
|| !onlyCurrentSite
|
||
|
) {
|
||
|
content += escapeForPre(cookies[i].domain);
|
||
|
content += "\t";
|
||
|
content += escapeForPre((!cookies[i].hostOnly).toString().toUpperCase());
|
||
|
content += "\t";
|
||
|
content += escapeForPre(cookies[i].path);
|
||
|
content += "\t";
|
||
|
content += escapeForPre(cookies[i].secure.toString().toUpperCase());
|
||
|
content += "\t";
|
||
|
content += escapeForPre(!cookies[i].session ? Math.round(cookies[i].expirationDate) : "0");
|
||
|
content += "\t";
|
||
|
content += escapeForPre(cookies[i].name);
|
||
|
content += "\t";
|
||
|
content += escapeForPre(cookies[i].value);
|
||
|
content += "\n";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
currentTab.load("data:application/octet-stream;base64," + Qt.btoa(downloadable + content))
|
||
|
}
|
||
|
|
||
|
Falkon.BrowserAction {
|
||
|
name: i18n('Cookies.txt')
|
||
|
identity: 'cookies-txt-id'
|
||
|
title: i18n('Cookies.txt')
|
||
|
toolTip: i18n('Export Cookies')
|
||
|
icon: "cookie.svg"
|
||
|
location: Falkon.BrowserAction.NavigationToolBar | Falkon.BrowserAction.StatusBar
|
||
|
|
||
|
popup: Pane {
|
||
|
ColumnLayout {
|
||
|
Button {
|
||
|
text: i18n("All")
|
||
|
hoverEnabled: true
|
||
|
onClicked: exportCookies();
|
||
|
Layout.fillWidth: true
|
||
|
Layout.alignment: Qt.AlignHCenter
|
||
|
}
|
||
|
Button {
|
||
|
text: i18n("Current Site")
|
||
|
hoverEnabled: true
|
||
|
onClicked: exportCookies(true);
|
||
|
Layout.fillWidth: true
|
||
|
Layout.alignment: Qt.AlignHCenter
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|