Work in progress implementation of #216
This commit is contained in:
31
static/openInApp.js
Normal file
31
static/openInApp.js
Normal 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
25
static/preferences.html
Normal 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>
|
@ -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 %}
|
@ -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 %}
|
@ -3,3 +3,5 @@
|
|||||||
<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>
|
@ -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 %}
|
@ -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"
|
||||||
|
Reference in New Issue
Block a user