[英]How to use GrabzIt API in tampermonkey?
I'm am using GrabzIt API to convert a URL to PDF. 我正在使用GrabzIt API将URL转换为PDF。 But the code is not working.
但是代码不起作用。 Well, the code is just simple.
好的,代码很简单。
GrabzIt("XXXXXXXXXXXXXXXXXXXXXXX=").ConvertURL(url,{"format": "pdf", "download": 1}).Create();
How can I use the GrabzIt API to convert a URL from tampermonkey to pdf? 如何使用GrabzIt API将URL从tampermonkey转换为pdf? Documentation
文档
Edit: 编辑:
I need to mention that I made a test on the GoogleSite: 我需要提及的是,我在GoogleSite上进行了测试:
// ==UserScript==
// @name Convert Google to a PDF
// @namespace http://tampermonkey.net/
// @version 0.1
// @require http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
// @require https://cdn.jsdelivr.net/npm/@grabzit/js@3.3.4/grabzit.min.js
// @description try to take over the world!
// @author You
// @match https://www.google.com/
// @grant none
// ==/UserScript==
var $ = window.$;
/*globals GrabzIt*/
$("document").ready(function(){
GrabzIt("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX=").ConvertURL("www.google.com",{"format": "pdf", "download": 1}).Create();
});
I found the problem, it was a few multiple things. 我发现了问题,这是几件事情。 At first, I had to
@require
the GrabzIt Library . 首先,我必须
@require
the GrabzIt Library 。 Then I had to use the library and paste in the API Key (That is given at the GrabzIt settings page) . 然后,我不得不使用该库并粘贴API密钥(在GrabzIt设置页面上给出) 。 After that, I faced another error that says:
之后,我遇到了另一个错误:
GrabzIt Error: Domain www.google.com is not valid with this application key.
GrabzIt错误:域www.google.com对此应用程序密钥无效。 Please add it to your authorized domains: https://grabz.it/account/domains.aspx
请将其添加到您的授权域中: https : //grabz.it/account/domains.aspx
And there was a checkbox that said Enable Authorized Security . 并且有一个复选框显示启用授权安全性 。 So at first, I thought I had to enable it.
所以起初,我以为我必须启用它。 But after further reading I saw this: "Alternatively disable authorized domain security to allow any domain to use your Application Key."
但是,在进一步阅读之后,我看到了:“或者禁用授权域安全性,以允许任何域使用您的应用程序密钥。”
Then I disabled this feature and everything went good. 然后我禁用了此功能,一切顺利。
Note: I used another solution for the problem that the code was not working, by appending the following script to the HTML of the webpage and it worked also. 注意:通过将以下脚本附加到网页的HTML中,我使用了另一种解决方案来解决代码不起作用的问题,并且该解决方案也起作用。
<script src="https://cdn.jsdelivr.net/npm/@grabzit/js@3.3.4/grabzit.min.js"></script>
<script>
GrabzIt("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX=").ConvertURL("https://www.tesla.com",
{"format": "pdf", "download": 1}).Create();
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.