如何使用书签通过 API 的 HTTP POST 将文本粘贴到 Pastebin 站点?

发布于 2024-12-02 10:22:32 字数 463 浏览 1 评论 0原文

我想通过站点的 API 将一些文本粘贴到 Pastebin 站点。

正如我所发现的(我的编程知识有限),我需要两件事:首先处理选定的文本,然后通过 HTTP POST 将其发布到 Pastebin 站点。

我尝试这样做...

javascript:'<body%20onload="document.forms[0].submit()"><form%20method="post"%20action="http://sprunge.us"><input%20type="hidden"%20name="sprunge"%20value="+ document.getSelection() +"></form>'

....(你猜对了!)每次都会返回到我选择的文本为“+ document.getSelection() +”的页面。

有什么帮助吗?

I want to paste some text to a pastebin site through the site's API.

As I have figured out (I have limited knowledge of programming) I need two things: First to process the selected text and then to post it via HTTP POST to the pastebin site.

I tried to do this...

javascript:'<body%20onload="document.forms[0].submit()"><form%20method="post"%20action="http://sprunge.us"><input%20type="hidden"%20name="sprunge"%20value="+ document.getSelection() +"></form>'

....which (you guessed it!) returns to me EVERY TIME a page in which the selected text being "+ document.getSelection() +".

Any help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雪花飘飘的天空 2024-12-09 10:22:32

您必须以编程方式制作一个表单,添加所需的字段,然后发布——所有这些都用 JavaScript 进行。

这是一个示例 - 您至少需要更改 URL 和字段名称:

<a href="
    javascript:(function(){
        var myform = document.createElement('form');
        myform.method='post';

        /* change this URL: */
        myform.action='http://my-example-pastebin.com/submit.php';

        /* The goodies go here: */
        var myin=document.createElement('input');
        /* Change the fieldname here: */
        myin.setAttribute('name','fieldname_for_pasted_text');
        myin.setAttribute('value',document.getSelection());
        myform.appendChild(myin);

        /* If you need another field for username etc: */
        myin=document.createElement('input');
        myin.setAttribute('name','some_field_1');
        myin.setAttribute('value','some_field_value_1');
        myform.appendChild(myin);

        myform.submit();
    })()
">Bookmarklet for posting selected text to an online pastebin</a>

上面的压缩内容没有注释和换行符:

<a href="javascript:(function(){var myform = document.createElement('form'); myform.method='post'; myform.action='http://my-example-pastebin.com/submit.php'; var myin=document.createElement('input'); myin.setAttribute('name','fieldname_for_pasted_text'); myin.setAttribute('value',document.getSelection()); myform.appendChild(myin); myin=document.createElement('input'); myin.setAttribute('name','some_field_1'); myin.setAttribute('value','some_field_value_1'); myform.appendChild(myin); myform.submit();})()">Bookmarklet for posting selected text to an online pastebin</a>

我不熟悉 sprunge.us,但如果您有示例中的 URL 和字段名,您可以通过搜索替换来使其工作:

您还应该删除我的示例中包含的第二个字段(some_field_1、somefield_value_1)。

You have to make a form programmatically, add the fields required and then post -- all in JavaScript.

Here is an example -- you will at least have to change the URL and the fieldname:

<a href="
    javascript:(function(){
        var myform = document.createElement('form');
        myform.method='post';

        /* change this URL: */
        myform.action='http://my-example-pastebin.com/submit.php';

        /* The goodies go here: */
        var myin=document.createElement('input');
        /* Change the fieldname here: */
        myin.setAttribute('name','fieldname_for_pasted_text');
        myin.setAttribute('value',document.getSelection());
        myform.appendChild(myin);

        /* If you need another field for username etc: */
        myin=document.createElement('input');
        myin.setAttribute('name','some_field_1');
        myin.setAttribute('value','some_field_value_1');
        myform.appendChild(myin);

        myform.submit();
    })()
">Bookmarklet for posting selected text to an online pastebin</a>

The above compacted without comments and linebreaks:

<a href="javascript:(function(){var myform = document.createElement('form'); myform.method='post'; myform.action='http://my-example-pastebin.com/submit.php'; var myin=document.createElement('input'); myin.setAttribute('name','fieldname_for_pasted_text'); myin.setAttribute('value',document.getSelection()); myform.appendChild(myin); myin=document.createElement('input'); myin.setAttribute('name','some_field_1'); myin.setAttribute('value','some_field_value_1'); myform.appendChild(myin); myform.submit();})()">Bookmarklet for posting selected text to an online pastebin</a>

I'm not familiar with sprunge.us, but if you've got the URL and fieldname right in your example, you could get this to work by search-replace:

You should also remove the second field (some_field_1, somefield_value_1) included in my example.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文