Adding optional nojs links to results page, changed nojs to a user setting

main
Ben Busby 2020-04-07 17:04:03 +00:00
parent 48495c04f6
commit 5687c87a65
2 changed files with 15 additions and 14 deletions

View File

@ -23,10 +23,6 @@ DESKTOP_UA = mozilla + '/5.0 (Windows NT 6.1; Win64; x64; rv:59.0) Gecko/2010010
# Base search url # Base search url
SEARCH_URL = 'https://www.google.com/search?gbv=1&q=' SEARCH_URL = 'https://www.google.com/search?gbv=1&q='
# Optional nojs tag - opens links in a contained window with all js removed
# (can be useful for achieving nojs on mobile)
nojs = int(os.environ.get('NOJS'))
user_config = json.load(open(STATIC_FOLDER + '/config.json')) user_config = json.load(open(STATIC_FOLDER + '/config.json'))
@ -36,12 +32,15 @@ def get_ua(user_agent):
def send_request(curl_url, ua): def send_request(curl_url, ua):
request_header = [] request_header = []
response_header = []
b_obj = BytesIO() b_obj = BytesIO()
crl = pycurl.Curl() crl = pycurl.Curl()
crl.setopt(crl.URL, curl_url) crl.setopt(crl.URL, curl_url)
crl.setopt(crl.USERAGENT, ua) crl.setopt(crl.USERAGENT, ua)
crl.setopt(crl.WRITEDATA, b_obj) crl.setopt(crl.WRITEDATA, b_obj)
crl.setopt(crl.HEADERFUNCTION, response_header.append)
crl.setopt(pycurl.FOLLOWLOCATION, 1)
crl.perform() crl.perform()
crl.close() crl.close()
@ -127,13 +126,20 @@ def search():
if '/advanced_search' in href: if '/advanced_search' in href:
a.decompose() a.decompose()
continue continue
if 'url?q=' in href: if 'url?q=' in href:
# Strip unneeded arguments
href = urlparse.urlparse(href) href = urlparse.urlparse(href)
href = parse_qs(href.query)['q'][0] href = parse_qs(href.query)['q'][0]
if nojs:
a['href'] = '/window?location=' + href # Add no-js option
# else: # Automatically go to reader mode in ff? Not sure if possible if user_config['nojs']:
# a['href'] = 'about:reader?url=' + href nojs_link = soup.new_tag('a')
nojs_link['href'] = '/window?location=' + href
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)
# Ensure no extra scripts passed through # Ensure no extra scripts passed through
try: try:

7
run.sh
View File

@ -2,11 +2,6 @@
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# Set NOJS mode to false if unavailable
if [[ -z "$NOJS" ]]; then
export NOJS=0
fi
# Create config json if it doesn't exist # Create config json if it doesn't exist
if [[ ! -f $SCRIPT_DIR/app/static/config.json ]]; then if [[ ! -f $SCRIPT_DIR/app/static/config.json ]]; then
echo "{}" > $SCRIPT_DIR/app/static/config.json echo "{}" > $SCRIPT_DIR/app/static/config.json
@ -16,4 +11,4 @@ pkill flask
# TODO: Set up the following for running over https # TODO: Set up the following for running over https
#--cert=./app/cert.pem --key=./app/key.pem #--cert=./app/cert.pem --key=./app/key.pem
$SCRIPT_DIR/venv/bin/flask run $SCRIPT_DIR/venv/bin/flask run