Work in progress implementation of #216

This commit is contained in:
Dylan
2024-08-24 18:49:21 +01:00
parent aeab60e059
commit 0db90f556c
7 changed files with 70 additions and 4 deletions

31
static/openInApp.js Normal file
View File

@ -0,0 +1,31 @@
function detectOS() {
const userAgent = navigator.userAgent || navigator.platform
if (/android/i.test(userAgent)) {
return 'android';
}
if (/iPad|iPhone|iPod/.test(userAgent) || (/Macintosh/.test(userAgent) && 'ontouchend' in document)) {
return 'ios';
}
return 'unknown';
}
function openTweet(tweetId){
var preference = localStorage.getItem("openLinksPreference");
if (preference === "true"){
const os = detectOS();
url = `twitter://status?id=${tweetId}`
if(os === 'android'){
window.location = url;
}else if (os === 'ios'){
window.location.replace(url);
}
setTimeout(() => {
window.location = `https://x.com/i/status/${tweetId}`
}, 1000)
}
}

25
static/preferences.html Normal file
View File

@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>
<head>
<title>Preferences</title>
<script>
function savePreference() {
var checkbox = document.getElementById("openLinksCheckbox");
localStorage.setItem("openLinksPreference", checkbox.checked);
}
function loadPreference() {
var checkbox = document.getElementById("openLinksCheckbox");
var preference = localStorage.getItem("openLinksPreference");
checkbox.checked = preference === "true";
}
</script>
</head>
<body onload="loadPreference()">
<h1>Preferences</h1>
<label for="openLinksCheckbox">
<input type="checkbox" id="openLinksCheckbox" onchange="savePreference()">
Open links in app
</label>
</body>
</html>

View File

@ -24,4 +24,4 @@
<meta property="og:description" content="{{ desc }}" /> <meta property="og:description" content="{{ desc }}" />
<link rel="alternate" href="{{ host }}/oembed.json?desc={{ urlUser }}&user=Twitter&link={{ tweetLink }}&ttype=photo&provider={{ appname }}" type="application/json+oembed" title="{{ tweet['user_name'] }}"> <link rel="alternate" href="{{ host }}/oembed.json?desc={{ urlUser }}&user=Twitter&link={{ tweetLink }}&ttype=photo&provider={{ appname }}" type="application/json+oembed" title="{{ tweet['user_name'] }}">
<meta http-equiv="refresh" content="0; url = {{ tweetLink }}" /> {% endblock %} {% block body %} Redirecting you to the tweet in a moment. <a href="{{ tweetLink }}">Or click here.</a> {% endblock %} <meta http-equiv="refresh" content="1; url = {{ tweetLink }}" /> {% endblock %} {% block body %} Redirecting you to the tweet in a moment. <a href="{{ tweetLink }}">Or click here.</a> {% endblock %}

View File

@ -10,4 +10,4 @@
<meta property="og:description" content="{{ desc }}" /> <meta property="og:description" content="{{ desc }}" />
<link rel="alternate" href="{{ host }}/oembed.json?desc={{ urlUser }}&user=Twitter&link={{ tweetLink }}&ttype=link&provider={{ appname }}" type="application/json+oembed" title="{{ tweet['user_name'] }}"> <link rel="alternate" href="{{ host }}/oembed.json?desc={{ urlUser }}&user=Twitter&link={{ tweetLink }}&ttype=link&provider={{ appname }}" type="application/json+oembed" title="{{ tweet['user_name'] }}">
<meta http-equiv="refresh" content="0; url = {{ tweetLink }}" /> {% endblock %} {% block body %} Redirecting you to the tweet in a moment. <a href="{{ tweetLink }}">Or click here.</a> {% endblock %} <meta http-equiv="refresh" content="1; url = {{ tweetLink }}" /> {% endblock %} {% block body %} Redirecting you to the tweet in a moment. <a href="{{ tweetLink }}">Or click here.</a> {% endblock %}

View File

@ -2,4 +2,6 @@
<meta content="{{ color }}" name="theme-color" /> <meta content="{{ color }}" name="theme-color" />
<meta property="og:site_name" content="{{ appname }}"> <meta property="og:site_name" content="{{ appname }}">
<meta name="twitter:title" content="{{ tweet['user_name'] }} (@{{ tweet['user_screen_name'] }})" /> <meta name="twitter:title" content="{{ tweet['user_name'] }} (@{{ tweet['user_screen_name'] }})" />
<script src="/openInApp.js"></script>
<script>document.addEventListener('DOMContentLoaded',function(){openTweet('{{ tweet["tweetID"] }}')})</script>

View File

@ -19,4 +19,4 @@
<meta property="og:description" content="{{ desc }}" /> <meta property="og:description" content="{{ desc }}" />
<link rel="alternate" href="{{ host }}/oembed.json?desc={{ urlUser }}&user={{ urlEncodedDesc }}&link={{ tweetLink }}&ttype=video&provider={{ appname }}" type="application/json+oembed" title="{{ tweet['user_name'] }}"> <link rel="alternate" href="{{ host }}/oembed.json?desc={{ urlUser }}&user={{ urlEncodedDesc }}&link={{ tweetLink }}&ttype=video&provider={{ appname }}" type="application/json+oembed" title="{{ tweet['user_name'] }}">
<meta http-equiv="refresh" content="0; url = {{ tweetLink }}" /> {% endblock %} {% block body %} Redirecting you to the tweet in a moment. <a href="{{ tweetLink }}">Or click here.</a> {% endblock %} <meta http-equiv="refresh" content="1; url = {{ tweetLink }}" /> {% endblock %} {% block body %} Redirecting you to the tweet in a moment. <a href="{{ tweetLink }}">Or click here.</a>{% endblock %}

View File

@ -275,6 +275,14 @@ def favicon(): # pragma: no cover
def apple_touch_icon(): # pragma: no cover def apple_touch_icon(): # pragma: no cover
return send_from_directory(os.path.join(app.root_path, 'static'), 'apple-touch-icon.png',mimetype='image/png') return send_from_directory(os.path.join(app.root_path, 'static'), 'apple-touch-icon.png',mimetype='image/png')
@app.route('/openInApp.js')
def openInAppJs(): # pragma: no cover
return send_from_directory(os.path.join(app.root_path, 'static'), 'openInApp.js',mimetype='application/javascript')
@app.route('/preferences')
def preferences(): # pragma: no cover
return send_from_directory(os.path.join(app.root_path, 'static'), 'preferences.html', mimetype='text/html')
@app.route('/tvid/<path:vid_path>') @app.route('/tvid/<path:vid_path>')
def tvid(vid_path): def tvid(vid_path):
url = f"https://video.twimg.com/{vid_path}.mp4" url = f"https://video.twimg.com/{vid_path}.mp4"