[GH-ISSUE #18] 请问怎么推送一个链接? #16

Closed
opened 2026-03-03 11:33:22 +03:00 by kerem · 6 comments
Owner

Originally created by @hzfmer on GitHub (Mar 10, 2019).
Original GitHub issue: https://github.com/Finb/Bark/issues/18

有时候推送的文本其实是一个网址, 有什么办法可以强行转义,保证推送的就是文本本身吗?

Originally created by @hzfmer on GitHub (Mar 10, 2019). Original GitHub issue: https://github.com/Finb/Bark/issues/18 有时候推送的文本其实是一个网址, 有什么办法可以强行转义,保证推送的就是文本本身吗?
kerem closed this issue 2026-03-03 11:33:22 +03:00
Author
Owner

@Finb commented on GitHub (Mar 10, 2019):

内容有特殊符号时,需要url编码一下。

hzfmer notifications@github.com于2019年3月10日 周日21:34写道:

有时候推送的文本其实是一个网址, 有什么办法可以强行转义,保证推送的就是文本本身吗?


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/Finb/Bark/issues/18, or mute the thread
https://github.com/notifications/unsubscribe-auth/AGhzWFCJuFb8JAYdvY7GsCfn2lb95K4Eks5vVQnLgaJpZM4bnQ7s
.

<!-- gh-comment-id:471306746 --> @Finb commented on GitHub (Mar 10, 2019): 内容有特殊符号时,需要url编码一下。 hzfmer <notifications@github.com>于2019年3月10日 周日21:34写道: > 有时候推送的文本其实是一个网址, 有什么办法可以强行转义,保证推送的就是文本本身吗? > > — > You are receiving this because you are subscribed to this thread. > Reply to this email directly, view it on GitHub > <https://github.com/Finb/Bark/issues/18>, or mute the thread > <https://github.com/notifications/unsubscribe-auth/AGhzWFCJuFb8JAYdvY7GsCfn2lb95K4Eks5vVQnLgaJpZM4bnQ7s> > . >
Author
Owner

@hzfmer commented on GitHub (Mar 10, 2019):

@Finb
我是拿来直接用的, 找了个automator的workflow。普通文本没问题。
不过不好意思没用过js, 尝试着在workflow里修改了下,没有成功。
下面是workflow调用的js,能指导一下该如何编码吗? 多谢!

function run(input, parameters) {
	
	var text=input;
	var apiUrl="https://api.day.app/{MYKEY}/";
	var autoCopy="?automaticallyCopy=1";
	var urlResult=encodeURI(apiUrl+text+autoCopy);
	return urlResult;
}
<!-- gh-comment-id:471308035 --> @hzfmer commented on GitHub (Mar 10, 2019): @Finb 我是拿来直接用的, 找了个automator的workflow。普通文本没问题。 不过不好意思没用过js, 尝试着在workflow里修改了下,没有成功。 下面是workflow调用的js,能指导一下该如何编码吗? 多谢! ```(javascript) function run(input, parameters) { var text=input; var apiUrl="https://api.day.app/{MYKEY}/"; var autoCopy="?automaticallyCopy=1"; var urlResult=encodeURI(apiUrl+text+autoCopy); return urlResult; } ```
Author
Owner

@Finb commented on GitHub (Mar 10, 2019):

var urlResult=apiUrl+ encodeURI(text) +autoCopy;

确保 encodeURI 方法正常工作

hzfmer notifications@github.com于2019年3月10日 周日21:51写道:

@Finb https://github.com/Finb
我是拿来直接用的, 找了个automator的workflow。普通文本没问题。
不过不好意思没用过js, 尝试着在workflow里修改了下,没有成功。
下面是workflow调用的js,能指导一下该如何编码吗? 多谢!

function run(input, parameters) {

var text=input;

var apiUrl="https://api.day.app/{MYKEY}/";

var autoCopy="?automaticallyCopy=1";

var urlResult=encodeURI(apiUrl+text+autoCopy);

return urlResult;

}


You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub
https://github.com/Finb/Bark/issues/18#issuecomment-471308035, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AGhzWGS7RvvJwFEk9ZCdNgpHotZYed5Fks5vVQ33gaJpZM4bnQ7s
.

<!-- gh-comment-id:471308257 --> @Finb commented on GitHub (Mar 10, 2019): var urlResult=apiUrl+ encodeURI(text) +autoCopy; 确保 encodeURI 方法正常工作 hzfmer <notifications@github.com>于2019年3月10日 周日21:51写道: > @Finb <https://github.com/Finb> > 我是拿来直接用的, 找了个automator的workflow。普通文本没问题。 > 不过不好意思没用过js, 尝试着在workflow里修改了下,没有成功。 > 下面是workflow调用的js,能指导一下该如何编码吗? 多谢! > > function run(input, parameters) { > > > > var text=input; > > var apiUrl="https://api.day.app/{MYKEY}/"; > > var autoCopy="?automaticallyCopy=1"; > > var urlResult=encodeURI(apiUrl+text+autoCopy); > > return urlResult; > > } > > > — > You are receiving this because you were mentioned. > > > Reply to this email directly, view it on GitHub > <https://github.com/Finb/Bark/issues/18#issuecomment-471308035>, or mute > the thread > <https://github.com/notifications/unsubscribe-auth/AGhzWGS7RvvJwFEk9ZCdNgpHotZYed5Fks5vVQ33gaJpZM4bnQ7s> > . >
Author
Owner

@hzfmer commented on GitHub (Mar 10, 2019):

谢谢!

不过这样还是有点问题, 比如 copy 了

https://github.com/Finb/Bark/issues/18

再推送的话,就推送不过来。 似乎相当于在 chrome 输入:

https://api.day.app/{MYKEY}/https://github.com/Finb/Bark/issues/18?automaticallyCopy=1

但是如果只是 copy

https://github.com

就会推送

github.com

总之,https://会被忽略 (严格来说还是连带 https 一起推送更好) , 而/ 出现超过一次就可能推送失败了。看起来应该还是 url 编码的问题?

<!-- gh-comment-id:471313122 --> @hzfmer commented on GitHub (Mar 10, 2019): 谢谢! 不过这样还是有点问题, 比如 copy 了 ```text https://github.com/Finb/Bark/issues/18 ``` 再推送的话,就推送不过来。 似乎相当于在 chrome 输入: ```text https://api.day.app/{MYKEY}/https://github.com/Finb/Bark/issues/18?automaticallyCopy=1 ``` 但是如果只是 copy ```text https://github.com ``` 就会推送 ```text github.com ``` 总之,`https://`会被忽略 (严格来说还是连带 https 一起推送更好) , 而`/` 出现超过一次就可能推送失败了。看起来应该还是 url 编码的问题?
Author
Owner

@Finb commented on GitHub (Mar 11, 2019):

@hzfmer
对,因为:// 破坏了 URL 的结构,
如果有这种特殊字符,需要URL编码
你这里的情况需要这样

https://api.day.app/{MYKEY}/https%3A%2F%2Fgithub.com%2FFinb%2FBark%2Fissues%2F18?automaticallyCopy=1

你那是否有类似 encodeURIComponent 的方法? 需要这样对URL进行编码下

<!-- gh-comment-id:471386845 --> @Finb commented on GitHub (Mar 11, 2019): @hzfmer 对,因为:// 破坏了 URL 的结构, 如果有这种特殊字符,需要URL编码 你这里的情况需要这样 ``` https://api.day.app/{MYKEY}/https%3A%2F%2Fgithub.com%2FFinb%2FBark%2Fissues%2F18?automaticallyCopy=1 ``` 你那是否有类似 encodeURIComponent 的方法? 需要这样对URL进行编码下
Author
Owner

@hzfmer commented on GitHub (Mar 11, 2019):

是的, 我今天自己研究了下,确实需要这样编码。 但是一个简单的workflow要加上这样的正则替换还是挺麻烦的,就先算了吧。
总之多谢!

<!-- gh-comment-id:471409644 --> @hzfmer commented on GitHub (Mar 11, 2019): 是的, 我今天自己研究了下,确实需要这样编码。 但是一个简单的workflow要加上这样的正则替换还是挺麻烦的,就先算了吧。 总之多谢!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/Bark#16
No description provided.