Cleaned up filter class, updated js config tool
parent
0a3da5cea4
commit
5fe308956b
|
@ -42,14 +42,19 @@ class Filter:
|
||||||
if input_form is not None:
|
if input_form is not None:
|
||||||
input_form['method'] = 'POST'
|
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
|
return soup
|
||||||
|
|
||||||
def remove_ads(self, soup):
|
def remove_ads(self, soup):
|
||||||
main_divs = soup.find('div', {'id': 'main'})
|
main_divs = soup.find('div', {'id': 'main'})
|
||||||
if main_divs is None:
|
result_divs = main_divs.find_all('div', recursive=False)
|
||||||
return
|
|
||||||
|
|
||||||
result_divs = main_divs.findAll('div', recursive=False)
|
|
||||||
|
|
||||||
# Only ads/sponsored content use classes in the list of result divs
|
# 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]
|
ad_divs = [ad_div for ad_div in result_divs if 'class' in ad_div.attrs]
|
||||||
|
@ -101,19 +106,18 @@ class Filter:
|
||||||
a.decompose()
|
a.decompose()
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if '?q=' not in href:
|
|
||||||
continue
|
|
||||||
|
|
||||||
result_link = urlparse.urlparse(href)
|
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:
|
if '/search?q=' in href:
|
||||||
enc_result = Fernet(self.secret_key).encrypt(query_link.encode())
|
enc_result = Fernet(self.secret_key).encrypt(query_link.encode())
|
||||||
new_search = '/search?q=' + enc_result.decode()
|
new_search = '/search?q=' + enc_result.decode()
|
||||||
|
|
||||||
for param in VALID_PARAMS:
|
query_params = parse_qs(urlparse.urlparse(href).query)
|
||||||
if param in parse_qs(result_link.query):
|
allowed_params = [_ for _ in query_params if _ in VALID_PARAMS]
|
||||||
new_search += '&' + param + '=' + parse_qs(result_link.query)[param][0]
|
for param in allowed_params:
|
||||||
|
param_val = query_params[param][0]
|
||||||
|
new_search += '&' + param + '=' + param_val
|
||||||
a['href'] = new_search
|
a['href'] = new_search
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -140,18 +144,13 @@ class Filter:
|
||||||
|
|
||||||
# Add no-js option
|
# Add no-js option
|
||||||
if self.nojs:
|
if self.nojs:
|
||||||
|
gen_nojs(soup, query_link, a)
|
||||||
|
|
||||||
|
|
||||||
|
def gen_nojs(soup, link, sibling):
|
||||||
nojs_link = soup.new_tag('a')
|
nojs_link = soup.new_tag('a')
|
||||||
nojs_link['href'] = '/window?location=' + query_link
|
nojs_link['href'] = '/window?location=' + link
|
||||||
nojs_link['style'] = 'display:block;width:100%;'
|
nojs_link['style'] = 'display:block;width:100%;'
|
||||||
nojs_link.string = 'NoJS Link: ' + nojs_link['href']
|
nojs_link.string = 'NoJS Link: ' + nojs_link['href']
|
||||||
a.append(BeautifulSoup('<br><hr><br>', 'html.parser'))
|
sibling.append(BeautifulSoup('<br><hr><br>', 'html.parser'))
|
||||||
a.append(nojs_link)
|
sibling.append(nojs_link)
|
||||||
|
|
||||||
# Ensure no extra scripts passed through
|
|
||||||
try:
|
|
||||||
for script in soup('script'):
|
|
||||||
script.decompose()
|
|
||||||
soup.find('div', id='sfooter').decompose()
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
|
@ -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) => {
|
const fillConfigValues = (near, nojs, dark) => {
|
||||||
// Request existing config info
|
// Request existing config info
|
||||||
let xhrGET = new XMLHttpRequest();
|
let xhrGET = new XMLHttpRequest();
|
||||||
|
@ -69,6 +47,28 @@ const fillConfigValues = (near, nojs, dark) => {
|
||||||
xhrGET.send();
|
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() {
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
document.getElementById("main").style.display = "block";
|
document.getElementById("main").style.display = "block";
|
||||||
|
|
Loading…
Reference in New Issue