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>
|
Reference in New Issue
Block a user