Skip to content

Commit d013d69

Browse files
authored
Merge pull request #81 from Xyl-AU/soyjak-party-embed-styling
soyjak.party: support embeds, more text styling
2 parents cded8ec + e26c148 commit d013d69

File tree

5 files changed

+39
-76
lines changed

5 files changed

+39
-76
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
<resources>
2-
<string name="preference_kaptcha_replies">Show Kaptcha for replies</string>
3-
<string name="preference_kaptcha_replies_summary">Enable Kaptcha for replies instead of just new threads</string>
42
</resources>

extensions/sojakparty/src/com/mishiranu/dashchan/chan/sojakparty/SojakpartyChanConfiguration.java

+2-31
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,11 @@
77
public class SojakpartyChanConfiguration extends ChanConfiguration {
88

99
public static final String CAPTCHA_TYPE_NONE = "None";
10-
public static final String CAPTCHA_TYPE_KAPTCHA = "Kaptcha";
11-
12-
public static final String KAPTCHA_REPLIES = "KaptchaReplies";
1310

1411
public SojakpartyChanConfiguration() {
1512
request(OPTION_READ_POSTS_COUNT);
1613
addCaptchaType(CAPTCHA_TYPE_NONE);
17-
addCaptchaType(CAPTCHA_TYPE_KAPTCHA);
1814
addCaptchaType(CAPTCHA_TYPE_RECAPTCHA_2);
19-
addCustomPreference(KAPTCHA_REPLIES, false);
2015
setDefaultName("Chud");
2116
}
2217

@@ -71,12 +66,6 @@ public Captcha obtainCustomCaptchaConfiguration(String captchaType) {
7166
Captcha captcha;
7267

7368
switch (captchaType) {
74-
case CAPTCHA_TYPE_KAPTCHA:
75-
captcha = new Captcha();
76-
captcha.title = captchaType;
77-
captcha.input = Captcha.Input.ALL;
78-
captcha.validity = Captcha.Validity.SHORT_LIFETIME;
79-
break;
8069
case CAPTCHA_TYPE_NONE:
8170
captcha = new Captcha();
8271
captcha.title = CAPTCHA_TYPE_NONE;
@@ -93,24 +82,6 @@ public Captcha obtainCustomCaptchaConfiguration(String captchaType) {
9382

9483
@Override
9584
public CustomPreference obtainCustomPreferenceConfiguration(String key) {
96-
Resources resources = getResources();
97-
CustomPreference customPreference;
98-
99-
switch (key) {
100-
case KAPTCHA_REPLIES:
101-
customPreference = new CustomPreference();
102-
customPreference.title = resources.getString(R.string.preference_kaptcha_replies);
103-
customPreference.summary = resources.getString(R.string.preference_kaptcha_replies_summary);
104-
break;
105-
default:
106-
customPreference = null;
107-
break;
108-
}
109-
110-
return customPreference;
111-
}
112-
113-
public boolean isKaptchaRepliesEnabled() {
114-
return get(null, KAPTCHA_REPLIES, false);
85+
return null;
11586
}
116-
}
87+
}

extensions/sojakparty/src/com/mishiranu/dashchan/chan/sojakparty/SojakpartyChanMarkup.java

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public SojakpartyChanMarkup() {
1919
addTag("code", TAG_CODE);
2020
addTag("span", "spoiler", TAG_SPOILER);
2121
addTag("span", "quote", TAG_QUOTE);
22+
addTag("big", TAG_HEADING);
2223
addColorable("div");
2324
addColorable("span");
2425
}

extensions/sojakparty/src/com/mishiranu/dashchan/chan/sojakparty/SojakpartyChanPerformer.java

+3-36
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.mishiranu.dashchan.chan.sojakparty;
22

3-
import static com.mishiranu.dashchan.chan.sojakparty.SojakpartyChanConfiguration.CAPTCHA_TYPE_KAPTCHA;
4-
53
import static chan.content.ChanConfiguration.CAPTCHA_TYPE_RECAPTCHA_2;
64

75
import java.io.IOException;
@@ -188,9 +186,6 @@ public SendPostResult onSendPost(SendPostData data) throws HttpException, ApiExc
188186
String captchaType = data.captchaData.get(CAPTCHA_DATA_KEY_TYPE);
189187
if (captchaType.equals(CAPTCHA_TYPE_RECAPTCHA_2)) {
190188
entity.add("g-recaptcha-response", data.captchaData.get(CaptchaData.INPUT));
191-
} else if (captchaType.equals(CAPTCHA_TYPE_KAPTCHA)) {
192-
entity.add("_KAPTCHA_KEY", data.captchaData.get(CaptchaData.CHALLENGE));
193-
entity.add("_KAPTCHA", StringUtils.emptyIfNull(data.captchaData.get(CaptchaData.INPUT)));
194189
}
195190
}
196191

@@ -202,7 +197,7 @@ public SendPostResult onSendPost(SendPostData data) throws HttpException, ApiExc
202197
.perform().readString();
203198
try {
204199
AntispamFieldsParser.parseAndApply(responseText, entity, "board", "thread", "name", "email",
205-
"subject", "body", "password", "file", "spoiler", "json_response", "_KAPTCHA", "_KAPTCHA_NOJS", "_KAPTCHA_KEY");
200+
"subject", "body", "password", "file", "spoiler", "json_response");
206201
} catch (ParseException e) {
207202
throw new InvalidResponseException();
208203
}
@@ -337,18 +332,17 @@ public SendReportPostsResult onSendReportPosts(SendReportPostsData data) throws
337332
return null;
338333
}
339334
String errorMessage = jsonObject.optString("error");
340-
if (errorMessage != null) {
335+
if (!errorMessage.isEmpty()) {
341336
CommonUtils.writeLog("Soyjak.party report message", errorMessage);
342337
throw new ApiException(errorMessage);
343338
}
344339
throw new InvalidResponseException();
345340
}
346341

347342
@Override
348-
public ReadCaptchaResult onReadCaptcha(ReadCaptchaData data) throws InvalidResponseException, HttpException {
343+
public ReadCaptchaResult onReadCaptcha(ReadCaptchaData data) {
349344
String captchaType = data.captchaType;
350345
SojakpartyChanLocator locator = SojakpartyChanLocator.get(this);
351-
SojakpartyChanConfiguration configuration = SojakpartyChanConfiguration.get(this);
352346
ReadCaptchaResult result;
353347
if (SojakpartyChanConfiguration.CAPTCHA_TYPE_RECAPTCHA_2.equals(captchaType)) {
354348
CaptchaData captchaData = new CaptchaData();
@@ -360,33 +354,6 @@ public ReadCaptchaResult onReadCaptcha(ReadCaptchaData data) throws InvalidRespo
360354
} else if (SojakpartyChanConfiguration.CAPTCHA_TYPE_NONE.equals(captchaType)) {
361355
captchaType = null;
362356
result = new ReadCaptchaResult(CaptchaState.SKIP, null);
363-
} else if (CAPTCHA_TYPE_KAPTCHA.equals(captchaType)) {
364-
if (data.threadNumber != null && !configuration.isKaptchaRepliesEnabled()) {
365-
return new ReadCaptchaResult(CaptchaState.SKIP, null);
366-
}
367-
String chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789=-";
368-
SecureRandom rnd = new SecureRandom();
369-
StringBuilder keyBuilder = new StringBuilder(64);
370-
for(int i = 0; i < 64; i++) {
371-
keyBuilder.append(chars.charAt(rnd.nextInt(chars.length())));
372-
}
373-
String key = keyBuilder.toString();
374-
375-
Uri uri = Uri.parse("https://sys.kolyma.net/kaptcha/kaptcha.php?key=" + key);
376-
Bitmap image;
377-
String response = new HttpRequest(uri, data)
378-
.addHeader(USER_AGENT_HTTP_HEADER_NAME, USER_AGENT_HTTP_HEADER_VALUE)
379-
.perform().readString();
380-
byte[] imageBytes = Base64.decode(response.split(", ")[1], 0);
381-
image = imageBytes.length == 0 ? null
382-
: BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length);
383-
if (image == null) {
384-
throw new InvalidResponseException(new Exception("Image is null"));
385-
}
386-
CaptchaData captchaData = new CaptchaData();
387-
captchaData.put(CAPTCHA_DATA_KEY_TYPE, CAPTCHA_TYPE_KAPTCHA);
388-
captchaData.put(CaptchaData.CHALLENGE, key);
389-
result = new ReadCaptchaResult(CaptchaState.CAPTCHA, captchaData).setImage(image);
390357
} else {
391358
throw new IllegalStateException();
392359
}

extensions/sojakparty/src/com/mishiranu/dashchan/chan/sojakparty/SojakpartyModelMapper.java

+33-7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.Locale;
88

99
import chan.content.model.Attachment;
10+
import chan.content.model.EmbeddedAttachment;
1011
import chan.content.model.FileAttachment;
1112
import chan.content.model.Icon;
1213
import chan.content.model.Post;
@@ -179,12 +180,28 @@ public static Post createPost(JsonSerial.Reader reader, SojakpartyChanLocator lo
179180
case "com": {
180181
String comment = reader.nextString()
181182
.replaceAll("%23", "#")
182-
.replaceAll("(?<=<a href=\\\")https://jump\\.kolyma\\.net/\\?", "")
183-
.replaceAll("(?<=<div )class=\\\"glow", "style=\\\"color:#00FE20")
184-
.replaceAll("(?<=<span )style=\\\"text-shadow:0px 0px 40px #fffb00, 0px 0px 2px #fffb00", "style=\\\"color:#FFFB00")
185-
.replaceAll("(?<=<span )class=\\\"heading2", "style=\\\"color:#2424AD")
186-
.replaceAll("(?<=<span )class=\\\"heading", "style=\\\"color:#AF0A0F")
187-
.replaceAll("(?<=<span )class=\\\"quote2", "style=\\\"color:#F6750B");
183+
.replaceAll("<div", "<span")
184+
.replaceAll("</div", "</span")
185+
// gemerald text
186+
.replaceAll("<span style=\"background: linear-gradient\\(to left, red, orange , yellow, green, cyan, blue, violet\\);-webkit-background-clip: text;-webkit-text-fill-color: transparent;\"><span class=\"glow\">(<[^/]*>)*(.*?)</span></span>",
187+
"<span style=\"color:#00FE20\">$1\uD83D\uDC8E $2 \uD83D\uDC8E</span>")
188+
// diamond text
189+
.replaceAll("<span style=\"background: linear-gradient\\(to left, red, orange , yellow, green, cyan, blue, violet\\);-webkit-background-clip: text;-webkit-text-fill-color: transparent;\"><span style=\"text-shadow:0px 0px 40px #36d7f7, 0px 0px 2px #36d7f7\">(<[^/]*>)*(.*?)</span></span>",
190+
"<span style=\"color:#36D7F7\">$1\uD83D\uDC8E $2 \uD83D\uDC8E</span>")
191+
// gold text
192+
.replaceAll("<span style=\"background: linear-gradient\\(to left, red, orange , yellow, green, cyan, blue, violet\\);-webkit-background-clip: text;-webkit-text-fill-color: transparent;\"><span style=\"text-shadow:0px 0px 40px #fffb00, 0px 0px 2px #fffb00\">(<[^/]*>)*(.*?)</span></span>",
193+
"<span style=\"color:#FFFB00\">$1\uD83C\uDFC6 $2 \uD83C\uDFC6</span>")
194+
// rainbow text
195+
.replaceAll("<span style=\"background: linear-gradient\\(to left, red, orange , yellow, green, cyan, blue, violet\\);-webkit-background-clip: text;-webkit-text-fill-color: transparent;\">(<[^/]*>)*(.*?)</span>",
196+
"<span>$1\uD83C\uDF08 $2 \uD83C\uDF08</span>")
197+
.replaceAll("<span class=\"rotate\">(<[^/]*>)*(.*?)</span>","<span>$1\uD83D\uDD03 $2 \uD83D\uDD03</span>") // spin text
198+
.replaceAll("<span class=\"glow\">(.*?)</span>", "<span style=\"color:#00FE20\">$1</span>") // glow text
199+
.replaceAll("<span style=\"text-shadow:0px 0px 40px #36d7f7, 0px 0px 2px #36d7f7\">(.*?)</span>", "<span style=\"color:#36D7F7\">$1</span>") // blue glow text
200+
.replaceAll("<span style=\"text-shadow:0px 0px 40px #fffb00, 0px 0px 2px #fffb00\">(.*?)</span>", "<span style=\"color:#FFFB00\">$1</span>") // sneed text
201+
.replaceAll("<span class=\"heading\">(.*?)</span>","<span style=\"color:#AF0A0F\">$1</span>") // red text
202+
.replaceAll("<span class=\"heading2\">(.*?)</span>","<span style=\"color:#2424AD\">$1</span>") // blue text
203+
.replaceAll("<span class=\"quote2\">(.*?)</span>", "<span style=\"color:#F6750B\">$1</span>") // orange quote
204+
.replaceAll("<font color=\"FD3D98\"><b>(.*?)</b></font>", "<strong><span style=\"color:#FD3D98\">$1</span></strong>"); // pink text
188205
post.setComment(comment);
189206
break;
190207
}
@@ -243,6 +260,15 @@ public static Post createPost(JsonSerial.Reader reader, SojakpartyChanLocator lo
243260
}
244261
break;
245262
}
263+
case "embed": {
264+
String embedString = reader.nextString()
265+
.replaceAll("vocaroo\\.com/embed", "vocaroo.com");
266+
EmbeddedAttachment attachment = EmbeddedAttachment.obtain(embedString);
267+
if (attachment != null) {
268+
attachments.add(attachment);
269+
}
270+
break;
271+
}
246272
default: {
247273
reader.skip();
248274
break;
@@ -251,8 +277,8 @@ public static Post createPost(JsonSerial.Reader reader, SojakpartyChanLocator lo
251277
}
252278
if (tim != null && size >= 0) {
253279
attachments.add(0, createFileAttachment(locator, boardName, tim, ext, filename, size, width, height));
254-
post.setAttachments(attachments);
255280
}
281+
post.setAttachments(attachments);
256282
if (CommonUtils.equals(post.getIdentifier(), post.getCapcode())) {
257283
post.setIdentifier(null);
258284
}

0 commit comments

Comments
 (0)