Cleaned up filter class, updated js config tool

このコミットが含まれているのは:
Ben Busby 2020-04-29 09:46:18 -06:00
コミット 5fe308956b
2個のファイルの変更45行の追加46行の削除

ファイルの表示

@ -42,14 +42,19 @@ class Filter:
if input_form is not None:
input_form['method'] = 'POST'
# Ensure no extra scripts passed through
for script in soup('script'):
script.decompose()
footer = soup.find('div', id='sfooter')
if footer is not None:
footer.decompose()
return soup
def remove_ads(self, soup):
main_divs = soup.find('div', {'id': 'main'})
if main_divs is None:
return
result_divs = main_divs.findAll('div', recursive=False)
result_divs = main_divs.find_all('div', recursive=False)
# Only ads/sponsored content use classes in the list of result divs
ad_divs = [ad_div for ad_div in result_divs if 'class' in ad_div.attrs]
@ -101,19 +106,18 @@ class Filter:
a.decompose()
continue
if '?q=' not in href:
continue
result_link = urlparse.urlparse(href)
query_link = parse_qs(result_link.query)['q'][0]
query_link = parse_qs(result_link.query)['q'][0] if '?q=' in href else ''
if '/search?q=' in href:
enc_result = Fernet(self.secret_key).encrypt(query_link.encode())
new_search = '/search?q=' + enc_result.decode()
for param in VALID_PARAMS:
if param in parse_qs(result_link.query):
new_search += '&' + param + '=' + parse_qs(result_link.query)[param][0]
query_params = parse_qs(urlparse.urlparse(href).query)
allowed_params = [_ for _ in query_params if _ in VALID_PARAMS]
for param in allowed_params:
param_val = query_params[param][0]
new_search += '&' + param + '=' + param_val
a['href'] = new_search
continue
@ -140,18 +144,13 @@ class Filter:
# Add no-js option
if self.nojs:
nojs_link = soup.new_tag('a')
nojs_link['href'] = '/window?location=' + query_link
nojs_link['style'] = 'display:block;width:100%;'
nojs_link.string = 'NoJS Link: ' + nojs_link['href']
a.append(BeautifulSoup('<br><hr><br>', 'html.parser'))
a.append(nojs_link)
gen_nojs(soup, query_link, a)
# Ensure no extra scripts passed through
try:
for script in soup('script'):
script.decompose()
soup.find('div', id='sfooter').decompose()
except Exception:
pass
def gen_nojs(soup, link, sibling):
nojs_link = soup.new_tag('a')
nojs_link['href'] = '/window?location=' + link
nojs_link['style'] = 'display:block;width:100%;'
nojs_link.string = 'NoJS Link: ' + nojs_link['href']
sibling.append(BeautifulSoup('<br><hr><br>', 'html.parser'))
sibling.append(nojs_link)

ファイルの表示

@ -15,28 +15,6 @@ const setupSearchLayout = () => {
});
}
const setupConfigLayout = () => {
// Setup shoogle config
const collapsible = document.getElementById("config-collapsible");
collapsible.addEventListener("click", function() {
this.classList.toggle("active");
let content = this.nextElementSibling;
if (content.style.maxHeight) {
content.style.maxHeight = null;
} else {
content.style.maxHeight = content.scrollHeight + "px";
}
content.classList.toggle("open");
});
const near = document.getElementById("config-near");
const noJS = document.getElementById("config-nojs");
const dark = document.getElementById("config-dark");
fillConfigValues(near, noJS, dark);
}
const fillConfigValues = (near, nojs, dark) => {
// Request existing config info
let xhrGET = new XMLHttpRequest();
@ -69,6 +47,28 @@ const fillConfigValues = (near, nojs, dark) => {
xhrGET.send();
}
const setupConfigLayout = () => {
// Setup shoogle config
const collapsible = document.getElementById("config-collapsible");
collapsible.addEventListener("click", function() {
this.classList.toggle("active");
let content = this.nextElementSibling;
if (content.style.maxHeight) {
content.style.maxHeight = null;
} else {
content.style.maxHeight = content.scrollHeight + "px";
}
content.classList.toggle("open");
});
const near = document.getElementById("config-near");
const noJS = document.getElementById("config-nojs");
const dark = document.getElementById("config-dark");
fillConfigValues(near, noJS, dark);
}
document.addEventListener("DOMContentLoaded", function() {
setTimeout(function() {
document.getElementById("main").style.display = "block";