This commit is contained in:
parent
f53b7b38b0
commit
3d421629d9
@ -11,7 +11,7 @@ jobs:
|
||||
go-version: '>=1.20.1'
|
||||
- uses: actions/checkout@v3
|
||||
- run: curl -sSL -u "$USERNAME:$PASSWORD" -o ShareWithTitle/$STORE_FILE https://cloud.crystalyx.net/remote.php/dav/files/$USERNAME/Bordel/$STORE_FILE
|
||||
- run: sh gradlew build bundleRelease assembleRelease --no-daemon
|
||||
- run: sh gradlew lint build bundle assemble --no-daemon
|
||||
- uses: https://gitea.com/actions/release-action@main
|
||||
if: startsWith(gitea.ref, 'refs/tags')
|
||||
with:
|
||||
|
@ -1,6 +1,8 @@
|
||||
package net.crystalyx.sharewithtitle;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
@ -17,7 +19,25 @@ public class HttpThreadHandler implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
title = Jsoup.connect(url.toString()).get().title();
|
||||
Document doc = Jsoup.connect(url.toString()).get();
|
||||
String titleMeta = doc.title();
|
||||
Element descriptionMeta = doc.select("meta[name=description]").first();
|
||||
Element titleElement = doc.select("meta[property=og:title]").first();
|
||||
Element descriptionElement = doc.select("meta[property=og:description]").first();
|
||||
|
||||
if (titleElement != null) {
|
||||
title = titleElement.attr("content");
|
||||
if (descriptionElement != null) {
|
||||
title += "\n" + descriptionElement.attr("content");
|
||||
} else if (descriptionMeta != null) {
|
||||
title += "\n" + descriptionMeta.attr("content");
|
||||
}
|
||||
} else {
|
||||
title = titleMeta;
|
||||
if (descriptionMeta != null) {
|
||||
title += "\n" + descriptionMeta.attr("content");
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
errorMessage = e.getMessage();
|
||||
}
|
||||
|
@ -25,16 +25,31 @@ public class MainActivity extends Activity {
|
||||
}
|
||||
|
||||
private void handleUrl(String textUrl) {
|
||||
URL url;
|
||||
URL originalUrl;
|
||||
URL fixedUrl;
|
||||
|
||||
try {
|
||||
url = new URL(textUrl);
|
||||
originalUrl = new URL(textUrl);
|
||||
|
||||
switch (originalUrl.getHost()) {
|
||||
case "twitter.com":
|
||||
case "t.co":
|
||||
case "x.com":
|
||||
fixedUrl = new URL(originalUrl.getProtocol(), "fxtwitter.com", originalUrl.getPort(), originalUrl.getFile());
|
||||
break;
|
||||
case "pixiv.net":
|
||||
fixedUrl = new URL(originalUrl.getProtocol(), "ppxiv.net", originalUrl.getPort(), originalUrl.getFile());
|
||||
break;
|
||||
default:
|
||||
fixedUrl = originalUrl;
|
||||
break;
|
||||
}
|
||||
} catch (MalformedURLException e) {
|
||||
Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
HttpThreadHandler handler = new HttpThreadHandler(url);
|
||||
HttpThreadHandler handler = new HttpThreadHandler(fixedUrl);
|
||||
Thread job = new Thread(handler);
|
||||
|
||||
job.start();
|
||||
@ -50,7 +65,7 @@ public class MainActivity extends Activity {
|
||||
if (title != null) {
|
||||
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
|
||||
sharingIntent.setType("text/plain");
|
||||
sharingIntent.putExtra(Intent.EXTRA_TEXT, title + "\n\n" + url);
|
||||
sharingIntent.putExtra(Intent.EXTRA_TEXT, title + "\n\n" + originalUrl);
|
||||
startActivity(Intent.createChooser(sharingIntent, "Share via"));
|
||||
} else if (errorMessage != null) {
|
||||
Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT).show();
|
||||
|
Loading…
Reference in New Issue
Block a user