-
Notifications
You must be signed in to change notification settings - Fork 59
/
__init__.py
33 lines (26 loc) · 914 Bytes
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# -*- mode: Python ; coding: utf-8 -*-
#
# Copyright © 2014–17 Roland Sieker <[email protected]>
#
# License: GNU AGPL, version 3 or later;
# http://www.gnu.org/copyleft/agpl.html
"""Add-on for Anki 2.1 to allow the use of cookies."""
import re
import urllib.parse
from aqt.webview import AnkiWebPage, AnkiWebView
from aqt import mw
from PyQt5.QtCore import QUrl
__version__ = "0.1.0"
def setHtmlWithBaseurl(webpage, html):
try:
base_url = QUrl(
urllib.parse.unquote(
re.search('<base href="(.*?)">', html).group(1)) +
"__viewer__.html")
except AttributeError as ae:
original_setHtml(webpage, html)
else:
original_setHtml(webpage, html, base_url)
original_setHtml = AnkiWebPage.setHtml
AnkiWebPage.setHtml = setHtmlWithBaseurl
mw.web = AnkiWebView() # I think the webview has already been created when we get here. So reset it.