Forgot password?
 Create new account
Author: hbghlyj

Asymptote测试

[Copy link]

3148

Threads

8489

Posts

610K

Credits

Credits
66148
QQ

Show all posts

 Author| hbghlyj Posted at 2024-11-12 15:50:29
kuing 发表于 2024-11-12 03:18
不好意思,完全看不懂……😢

是将现在的 /asy/index.php 换成 61# 吗?
可以先保存為/aops.php,保留原來的吧,也許以後再換回去

用法是 ?tex=JHheMit5XjIk (需要转换为base64)

701

Threads

110K

Posts

910K

Credits

Credits
94145
QQ

Show all posts

kuing Posted at 2024-11-12 17:46:20
hbghlyj 发表于 2024-11-12 15:50
可以先保存為/aops.php,保留原來的吧,也許以後再換回去

用法是 ?tex=JHheMit5XjIk (需要转换为base64 ...
那 JS 怎么改啊,要用那啥 btoa 还是 atob?

Comment

转换为 base64 后长度增加 25%!  Posted at 2024-11-14 00:08

3148

Threads

8489

Posts

610K

Credits

Credits
66148
QQ

Show all posts

 Author| hbghlyj Posted at 2024-11-12 17:53:10
kuing 发表于 2024-11-12 09:46
那 JS 怎么改啊,要用那啥 btoa 还是 atob?
将需要的公式转成base64,比如
window.btoa("$x^2+y^2$")
输出JHheMit5XjIk

701

Threads

110K

Posts

910K

Credits

Credits
94145
QQ

Show all posts

kuing Posted at 2024-11-12 23:37:34
Last edited by kuing at 2024-11-13 00:23:00刚才初改完代码,具体改法:
先将 61# 的代码存为 aops.php 放在 /asy/ 下;
然后在 zdy3pc.js 里:
var str_for_link = encodeURIComponent(str); 改成 var str_for_link = window.btoa(str);
以及之后的 <img src="/asy/?format=svg&code='+str_for_link+'" 改成 <img src="/asy/aops.php?tex='+str_for_link+'"
测试结果输出了一串文字的图片,原来是忘记加 asy 标签了。
然而,即便后来补回了 asy 标签,仍然所有的图都一直是先前的输出,如同你刚才另一帖说的故障那样。

现在似乎无论啥代码,一直是下图:


然而,如果右键 - 用新标签页打开图片,又是另一个图!且这个图也是不变的😯

所以你另一帖说的故障还是需要搞清楚才行,是因为有缓存机制之类的吗?

3148

Threads

8489

Posts

610K

Credits

Credits
66148
QQ

Show all posts

 Author| hbghlyj Posted at 2024-11-13 01:14:37
kuing 发表于 2024-11-12 15:37
所以你另一帖说的故障还是需要搞清楚才行,是因为有缓存机制之类的吗?
猜测和token有关。也就是每次进入artofproblemsolving.com/texer 之后,会转到一个网址,后缀是8个字母。建议每次都随机生成一个token

3148

Threads

8489

Posts

610K

Credits

Credits
66148
QQ

Show all posts

 Author| hbghlyj Posted at 2024-11-13 01:16:35
按楼上所述,php代码修改为:
  1. <?php
  2. $characters = 'abcdefghijklmnopqrstuvwxyz';
  3. $randomString = '';
  4. for ($i = 0; $i < 6; $i++) {
  5.     $randomString .= $characters[rand(0, 25)];
  6. }
  7. $data = array(
  8.         'action'=>'image',
  9.         'token'=>$randomString,
  10.         'tex'=>$_GET["tex"],
  11.         'rerender'=>false
  12. );
  13. $ch = curl_init();
  14. curl_setopt_array($ch, array(
  15.         CURLOPT_URL => "https://artofproblemsolving.com/m/texer/ajax.php",
  16.         CURLOPT_RETURNTRANSFER => true,
  17.         CURLOPT_POST => 1,
  18.         CURLOPT_SSL_VERIFYHOST => 0,
  19.         CURLOPT_SSL_VERIFYPEER => 0,
  20.         CURLOPT_HTTPHEADER => array('Content-Type: application/x-www-form-urlencoded'),
  21.         CURLOPT_POSTFIELDS => http_build_query($data)
  22. ));
  23. $result=curl_exec($ch);
  24. if(curl_errno($ch)){
  25.         die('Request Error:' . curl_error($ch));
  26. }
  27. $res=json_decode($result)->response->urls[0];
  28. header('Location: '.$res);
  29. ?>
Copy the Code

701

Threads

110K

Posts

910K

Credits

Credits
94145
QQ

Show all posts

kuing Posted at 2024-11-13 01:57:39
hbghlyj 发表于 2024-11-13 01:16
按楼上所述,php代码修改为:
用了这个,好像可以了。
但图的尺寸有点大,加载也有点慢。
而且也不是完全正确,比如 5# 第二个图,没有了透明度。

3148

Threads

8489

Posts

610K

Credits

Credits
66148
QQ

Show all posts

 Author| hbghlyj Posted at 2024-11-13 02:39:26
kuing 发表于 2024-11-12 17:57
但图的尺寸有点大,
其实它返回的数据中有宽度。可以在
  1. $res=json_decode($result)->response->urls[0];
Copy the Code

的后面补上
  1. $width=json_decode($result)->response->width[0];
Copy the Code

得到图片的宽度。修改之后,上面那个Venn图就变小了!

3148

Threads

8489

Posts

610K

Credits

Credits
66148
QQ

Show all posts

 Author| hbghlyj Posted at 2024-11-13 02:44:26
按楼上所述,php改为
  1. <?php
  2. $characters = 'abcdefghijklmnopqrstuvwxyz';
  3. $randomString = '';
  4. for ($i = 0; $i < 6; $i++) {
  5.     $randomString .= $characters[rand(0, 25)];
  6. }
  7. $data = array(
  8.         'action'=>'image',
  9.         'token'=>$randomString,
  10.         'tex'=>$_GET["tex"],
  11.         'rerender'=>false
  12. );
  13. $ch = curl_init();
  14. curl_setopt_array($ch, array(
  15.         CURLOPT_URL => "https://artofproblemsolving.com/m/texer/ajax.php",
  16.         CURLOPT_RETURNTRANSFER => true,
  17.         CURLOPT_POST => 1,
  18.         CURLOPT_SSL_VERIFYHOST => 0,
  19.         CURLOPT_SSL_VERIFYPEER => 0,
  20.         CURLOPT_HTTPHEADER => array('Content-Type: application/x-www-form-urlencoded'),
  21.         CURLOPT_POSTFIELDS => http_build_query($data)
  22. ));
  23. $result=curl_exec($ch);
  24. if(curl_errno($ch)){
  25.         die('Request Error:' . curl_error($ch));
  26. }
  27. $url=json_decode($result)->response->urls[0];
  28. $width=json_decode($result)->response->width[0];
  29. echo "<img src='$url' width='$width'>";
  30. ?>
Copy the Code
这样返回的是图片的HTML,指定了宽度。

Comment

用了这个,图片不显示了啊  Posted at 2024-11-13 12:00
是不是 JS 也要跟着改?  Posted at 2024-11-13 12:00
是的。这样返回的是图片的HTML,指定了宽度。  Posted at 2024-11-13 16:02
请问 JS 咋改  Posted at 2024-11-13 16:18

701

Threads

110K

Posts

910K

Credits

Credits
94145
QQ

Show all posts

kuing Posted at 2024-11-13 11:50:31
hbghlyj 发表于 2024-11-13 02:49
AoPS 每次编译时都会给出永久的 URL,所以只要保存这个 URL 就可以了,这样下次刷新页面就不需要重新编译 ...
代码咋写啊这……

Comment

图片的宽度那个返回的不再是图片地址,是图片的HTML,指定了宽度。  Posted at 2024-11-13 16:03
因此需要改一下 JS  Posted at 2024-11-13 16:04
我不会写  Posted at 2024-11-13 16:16

3148

Threads

8489

Posts

610K

Credits

Credits
66148
QQ

Show all posts

 Author| hbghlyj Posted at 2024-11-13 16:53:06
kuing 发表于 2024-11-13 03:50
代码咋写啊这……

需要从'/asy/aops.php?tex='+str_for_link获取数据,应该可以写成
  1. fetch('/asy/aops.php?tex='+str_for_link).then(response => response.text()).then(data => console.log(data));
Copy the Code

Screenshot 2024-11-13 085554.png

3148

Threads

8489

Posts

610K

Credits

Credits
66148
QQ

Show all posts

 Author| hbghlyj Posted at 2024-11-13 17:00:19
按楼上的fetch,应该可以将
  1. item.innerHTML = '<div class="jiaz"></div><div class="tuozt" onmousedown="tuozhuai2(this.parentNode);return false;"><!--拖动--></div><div class="guiw" onclick="guiwei(this.parentNode);return false;"><!--归位--></div><img src="/asy/aops.php?tex='+str_for_link+'" onclick="show_tikz_window(\''+str_for_show+'\');" onload="this.parentNode.classList.add(\'jiazed\')" />';
Copy the Code
先改为
  1. fetch('/asy/aops.php?tex='+str_for_link).then(response => response.text()).then(data => {item.innerHTML = data;})
Copy the Code

测试一下

如果测试成功就可以把其余的HTML加上了。

Comment

貌似不行  Posted at 2024-11-13 17:47
哪里出错了呢?  Posted at 2024-11-13 17:55
要不先别管宽度了,先研究下 75# 说的“永久 URL”怎么写代码吧……  Posted at 2024-11-13 18:00

701

Threads

110K

Posts

910K

Credits

Credits
94145
QQ

Show all posts

kuing Posted at 2024-11-13 18:40:34
问题是,发帖时根本不知道 URL 是什么,怎么存?

Comment

发帖提交时需要从AoPS获取URL吧。  Posted at 2024-11-13 18:43
需要在发帖时取得URL吧  Posted at 2024-11-13 20:08
这样只需在发帖时编译,看帖时就不需要重新编译了😀  Posted at 2024-11-13 20:09
可以自动吧。用户只需要提交[asy]...code...[/asy],和之前一样。  Posted at 2024-11-13 20:33
像[img]...URL...[/img]和[img=width,height]...URL...[/img]一样,可以使[asy]也接收一个可选参数,成为[asy=...URL...]...code...[/img],也保留原来的[asy]...code...[/asy]  Posted at 2024-11-14 00:03
使[asy=...URL...]...code...[/asy]解析为<img src="...URL">😀  Posted at 2024-11-14 00:04

3148

Threads

8489

Posts

610K

Credits

Credits
66148
QQ

Show all posts

 Author| hbghlyj Posted at 2024-11-13 18:44:57
kuing 发表于 2024-11-13 10:40
问题是,发帖时根本不知道 URL 是什么,怎么存?
就像发帖时的 “链接识别”、“@用户 识别”一样,可以做一个“[asy]识别”

701

Threads

110K

Posts

910K

Credits

Credits
94145
QQ

Show all posts

kuing Posted at 2024-11-13 21:55:16
hbghlyj 发表于 2024-11-13 18:44
就像发帖时的 “链接识别”、“@用户 识别”一样,可以做一个“[asy]识别” ...
链接识别这些只是在点击确定之时做一个简单的替换,而现在要获取的 URL 还得和 aops 连接,等他编译再返回,复杂得多吧,能做到吗?
代码我是肯定写不来的,你还是自己先弄成功了,再回来说,你不是之前在 github 还是什么的弄了一个 discuz 吗,在那里测试吧。

3148

Threads

8489

Posts

610K

Credits

Credits
66148
QQ

Show all posts

 Author| hbghlyj Posted at 2024-11-13 22:58:19
kuing 发表于 2024-11-13 13:55
复杂得多吧,能做到吗?

现在已经有了aops.php,可以像上面那样连接aops.php,
  1. function replaceAsy(){
  2.   let match = textobj.value.match(/\[asy\].*?\[\/asy\]/s);
  3.   if(match){
  4.     fetch('/asy/aops.php?tex='+window.btoa(match)).then(response => response.text()).then(data => {textobj.value = textobj.value.replaceAll(match, data); replaceAsy();});
  5.   }
  6. }
Copy the Code

3148

Threads

8489

Posts

610K

Credits

Credits
66148
QQ

Show all posts

 Author| hbghlyj Posted at 2024-11-13 23:14:17
kuing 发表于 2024-11-13 13:55
你还是自己先弄成功了
弄成功了!按楼上的代码,在编辑帖子页运行的效果:自动逐一替换。
Animation.gif

Comment

然后?就没了?  Posted at 2024-11-14 01:09
然后需要定义[asy]的参数  Posted at 2024-11-14 01:21
像[img]...URL...[/img]和[img=width,height]...URL...[/img]一样,可以使[asy]也接收一个可选参数,成为[asy=...URL...]...code...[/img],也保留原来的[asy]...code...[/asy]  Posted at 2024-11-14 01:21
使[asy=...URL...]...code...[/asy]解析为<img src="...URL">😀  Posted at 2024-11-14 01:21

3148

Threads

8489

Posts

610K

Credits

Credits
66148
QQ

Show all posts

 Author| hbghlyj Posted at 2024-11-14 01:25:07
kuing 发表于 2024-11-12 17:57
加载也有点慢。

AoPS 每次编译时都会给出永久的 URL,所以只要保存这个 URL 就可以了,这样下次刷新页面就不需要重新编译了。

可以将此 URL 存储在帖子正文中,如:用户发帖内容为
  1. [asy]........asy源代码.......[/asy]
Copy the Code

按下“保存”键后,自动从aops.php得到永久URL再将以上内容替换为
  1. [asy=....永久URL.....]........asy源代码.......[/asy]
Copy the Code

再保存。


浏览帖子时,让图像从永久 URL 加载。如:帖子内容为
  1. [asy=....永久URL.....]........asy源代码.......[/asy]
Copy the Code

显示为
  1. <img src="....永久URL.....">[/asy]
Copy the Code

这样,只要不编辑帖子,就无需重新编译。


在编辑帖子页,将其替换回
  1. [asy]........asy源代码.......[/asy]
Copy the Code
因此用户在编辑该帖子时会感觉和以前一样。

3148

Threads

8489

Posts

610K

Credits

Credits
66148
QQ

Show all posts

 Author| hbghlyj Posted at 2024-11-14 01:30:30
kuing 发表于 2024-11-13 13:55
链接识别这些只是在点击确定之时做一个简单的替换...

把这段代码加到链接识别附近的位置(因为功能类似)如何?

701

Threads

110K

Posts

910K

Credits

Credits
94145
QQ

Show all posts

kuing Posted at 2024-11-14 10:59:26
你在你的 discuz 里完整测试成功再说吧,我没心思写代码。

Comment

上面这段简短的 js 代码现在测试吗?  Posted at 2024-11-14 16:07

手机版Mobile version|Leisure Math Forum

2025-4-20 12:23 GMT+8

Powered by Discuz!

× Quick Reply To Top Return to the list