Save reader`s settings
closes #4 closes #7 Signed-off-by: Juraj Oravec <sgd.orava@gmail.com>
This commit is contained in:
parent
bbce8c6ee1
commit
b9d87ba86f
59
readability/JsObject.py
Normal file
59
readability/JsObject.py
Normal file
@ -0,0 +1,59 @@
|
||||
# Readability - plugin for Falkon
|
||||
# Copyright (C) 2019 Juraj Oravec <sgd.orava@gmail.com>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import Falkon
|
||||
from PySide2 import QtCore, QtGui
|
||||
|
||||
|
||||
class JsObject(QtCore.QObject):
|
||||
config = None
|
||||
|
||||
configChanged = QtCore.Signal()
|
||||
|
||||
def __init__(self, config, parent=None):
|
||||
super().__init__(parent)
|
||||
|
||||
self.config = config
|
||||
|
||||
@QtCore.Slot(str)
|
||||
def setColorTheme(self, colorTheme):
|
||||
if colorTheme not in ("light", "sepia", "dark"):
|
||||
return
|
||||
|
||||
if self.config["colorTheme"] != colorTheme:
|
||||
self.config["colorTheme"] = colorTheme
|
||||
|
||||
self.configChanged.emit()
|
||||
|
||||
@QtCore.Slot(str)
|
||||
def setFont(self, font):
|
||||
if font not in ("sans-serif", "serif"):
|
||||
return
|
||||
|
||||
if self.config["font"] != font:
|
||||
self.config["font"] = font
|
||||
|
||||
self.configChanged.emit()
|
||||
|
||||
@QtCore.Slot(int)
|
||||
def setFontSize(self, fontSize):
|
||||
if fontSize < 1 and fontSize > 9:
|
||||
return
|
||||
|
||||
if self.config["fontSize"] != fontSize:
|
||||
self.config["fontSize"] = fontSize
|
||||
|
||||
self.configChanged.emit()
|
@ -20,12 +20,14 @@ from PySide2 import QtCore, QtGui
|
||||
from readability.settingsDialog import SettingsDialog
|
||||
from readability.button import Button
|
||||
from readability.str2bool import str2bool
|
||||
from readability.JsObject import JsObject
|
||||
|
||||
|
||||
class Readability(Falkon.PluginInterface, QtCore.QObject):
|
||||
config = None
|
||||
view = None
|
||||
buttons = None
|
||||
jsObject = None
|
||||
|
||||
style = ""
|
||||
scriptReadability = ""
|
||||
@ -45,6 +47,11 @@ class Readability(Falkon.PluginInterface, QtCore.QObject):
|
||||
self.loadSettings()
|
||||
self.onConfigUpdate()
|
||||
|
||||
self.jsObject = JsObject(self.config, self)
|
||||
self.jsObject.configChanged.connect(self.saveSettings)
|
||||
|
||||
Falkon.ExternalJsObject.registerExtraObject("readability", self.jsObject)
|
||||
|
||||
plugins = Falkon.MainApplication.instance().plugins()
|
||||
|
||||
plugins.mainWindowCreated.connect(self.onMainWindowCreated)
|
||||
@ -58,6 +65,8 @@ class Readability(Falkon.PluginInterface, QtCore.QObject):
|
||||
for window in Falkon.MainApplication.instance().windows():
|
||||
self.onMainWindowDeleted(window)
|
||||
|
||||
Falkon.ExternalJsObject.unregisterExtraObject(self.jsObject)
|
||||
|
||||
def testPlugin(self):
|
||||
return True
|
||||
|
||||
|
@ -34,16 +34,31 @@ function addListeners(){
|
||||
document.getElementById('style-button').addEventListener("click", toolbarService);
|
||||
|
||||
var lightButton = document.getElementById('light-button');
|
||||
lightButton.addEventListener("click", function(){switchToLight();});
|
||||
lightButton.addEventListener("click", function(){
|
||||
switchToLight();
|
||||
external.extra.readability.setColorTheme('light');
|
||||
});
|
||||
var sepiaButton = document.getElementById('sepia-button');
|
||||
sepiaButton.addEventListener("click", function(){switchToSepia();});
|
||||
sepiaButton.addEventListener("click", function(){
|
||||
switchToSepia();
|
||||
external.extra.readability.setColorTheme('sepia');
|
||||
});
|
||||
var darkButton = document.getElementById('dark-button');
|
||||
darkButton.addEventListener("click", function(){switchToDark();});
|
||||
darkButton.addEventListener("click", function(){
|
||||
switchToDark();
|
||||
external.extra.readability.setColorTheme('dark');
|
||||
});
|
||||
|
||||
var serifButton = document.getElementById('serif-button');
|
||||
serifButton.addEventListener("click", function(){switchToSerif();});
|
||||
serifButton.addEventListener("click", function(){
|
||||
switchToSerif();
|
||||
external.extra.readability.setFont('serif');
|
||||
});
|
||||
var sansSerifButton = document.getElementById('sans-serif-button');
|
||||
sansSerifButton.addEventListener("click", function(){switchToSansSerif();});
|
||||
sansSerifButton.addEventListener("click", function(){
|
||||
switchToSansSerif();
|
||||
external.extra.readability.setFont('sans-serif');
|
||||
});
|
||||
|
||||
var fontSizePlusButton = document.getElementById('font-size-plus');
|
||||
fontSizePlusButton.addEventListener("click", fontSizePlus);
|
||||
@ -120,6 +135,7 @@ function fontSizePlus(){
|
||||
var size = container.classList[i].substr(-1, 1);
|
||||
if(parseInt(size) < 9){
|
||||
incrementedSize = parseInt(size) + 1;
|
||||
external.extra.readability.setFontSize(incrementedSize);
|
||||
} else return;
|
||||
container.classList.remove(container.classList[i]);
|
||||
container.classList.add('font-size' + incrementedSize);
|
||||
@ -135,10 +151,11 @@ function fontSizeMinus(){
|
||||
if(container.classList[i].indexOf('font-size') > -1){
|
||||
var size = container.classList[i].substr(-1, 1);
|
||||
if(parseInt(size) > 1){
|
||||
incrementedSize = parseInt(size) - 1;
|
||||
decrementedSize = parseInt(size) - 1;
|
||||
external.extra.readability.setFontSize(decrementedSize);
|
||||
} else return;
|
||||
container.classList.remove(container.classList[i]);
|
||||
container.classList.add('font-size' + incrementedSize);
|
||||
container.classList.add('font-size' + decrementedSize);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user