简体   繁体   中英

How to use GrabzIt API in tampermonkey?

I'm am using GrabzIt API to convert a URL to 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? Documentation

Edit:

I need to mention that I made a test on the 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 . Then I had to use the library and paste in the API Key (That is given at the GrabzIt settings page) . After that, I faced another error that says:

GrabzIt Error: Domain www.google.com is not valid with this application key. Please add it to your authorized domains: 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.

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM