It could be easy now to turn it into real loadable plugin.remotes/origin/Falkon/3.0
parent
401e600821
commit
ff1171abf0
17 changed files with 111 additions and 39 deletions
@ -0,0 +1,7 @@ |
||||
<RCC> |
||||
<qresource prefix="/adblock"> |
||||
<file>data/adblock.png</file> |
||||
<file>data/adblock_big.png</file> |
||||
<file>data/adblock.html</file> |
||||
</qresource> |
||||
</RCC> |
||||
@ -0,0 +1,61 @@ |
||||
/* ============================================================
|
||||
* QupZilla - Qt web browser |
||||
* Copyright (C) 2018 David Rosca <nowrep@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/>.
|
||||
* ============================================================ */ |
||||
|
||||
#include "adblockplugin.h" |
||||
#include "adblockmanager.h" |
||||
#include "adblockicon.h" |
||||
|
||||
#include "scripts.h" |
||||
#include "webpage.h" |
||||
#include "pluginproxy.h" |
||||
#include "browserwindow.h" |
||||
#include "navigationbar.h" |
||||
#include "mainapplication.h" |
||||
|
||||
AdBlockPlugin::AdBlockPlugin(QObject *parent) |
||||
: QObject(parent) |
||||
{ |
||||
connect(mApp, &MainApplication::aboutToQuit, AdBlockManager::instance(), &AdBlockManager::save); |
||||
connect(mApp->plugins(), &PluginProxy::webPageCreated, this, &AdBlockPlugin::webPageCreated); |
||||
connect(mApp->plugins(), &PluginProxy::mainWindowCreated, this, &AdBlockPlugin::mainWindowCreated); |
||||
} |
||||
|
||||
void AdBlockPlugin::webPageCreated(WebPage *page) |
||||
{ |
||||
connect(page, &WebPage::loadFinished, this, [=]() { |
||||
AdBlockManager *manager = AdBlockManager::instance(); |
||||
if (!manager->isEnabled()) { |
||||
return; |
||||
} |
||||
// Apply global element hiding rules
|
||||
const QString elementHiding = manager->elementHidingRules(page->url()); |
||||
if (!elementHiding.isEmpty()) { |
||||
page->runJavaScript(Scripts::setCss(elementHiding), WebPage::SafeJsWorld); |
||||
} |
||||
// Apply domain-specific element hiding rules
|
||||
const QString siteElementHiding = manager->elementHidingRulesForDomain(page->url()); |
||||
if (!siteElementHiding.isEmpty()) { |
||||
page->runJavaScript(Scripts::setCss(siteElementHiding), WebPage::SafeJsWorld); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
void AdBlockPlugin::mainWindowCreated(BrowserWindow *window) |
||||
{ |
||||
window->navigationBar()->addToolButton(new AdBlockIcon(window)); |
||||
} |
||||
@ -0,0 +1,33 @@ |
||||
/* ============================================================
|
||||
* QupZilla - Qt web browser |
||||
* Copyright (C) 2018 David Rosca <nowrep@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/>.
|
||||
* ============================================================ */ |
||||
#pragma once |
||||
|
||||
#include <QObject> |
||||
|
||||
class WebPage; |
||||
class BrowserWindow; |
||||
|
||||
class AdBlockPlugin : public QObject |
||||
{ |
||||
public: |
||||
explicit AdBlockPlugin(QObject *parent = nullptr); |
||||
|
||||
private: |
||||
void webPageCreated(WebPage *page); |
||||
void mainWindowCreated(BrowserWindow *window); |
||||
}; |
||||
|
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 3.9 KiB After Width: | Height: | Size: 3.9 KiB |
|
Before Width: | Height: | Size: 1.2 KiB |
Loading…
Reference in new issue