// ==UserScript==
// @Name              QX每日Pixiv图脚本
// @WebURL            https://api.lolicon.app/#/setu
// @Quota             300次/天
// ==/UserScript==

let userApikey = ''; //无需apikey了
let userR18 = 2; //18禁为1 非为0 2是混合
let userKeyword = ''; //搜索关键字
let userNum = 1; //一次返回的结果数量，范围为1到10，数字的数量亦为弹框的次数
let proxy = 'i.pixiv.re';
var request = {
    url: encodeURI("https://api.lolicon.app/setu/v2?apikey=" + userApikey + "&r18=" + userR18 + "&keyword=" + userKeyword + "&num=" + userNum + "&proxy=" + proxy),
    header: {
        "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 13_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.2 Mobile/15E148 Safari/604.1"
    },
}
$task.fetch(request).then(response => {
    let obj = JSON.parse(response.body);
    console.log(response.body);
    if (obj.data) {
        for (i = 0; i < obj.data.length; i++) {
            const setu = obj.data[i];
            let pictureURL = encodeURI(setu.urls["original"]);
            let title = setu.title || '';
            let author = setu.author || '';
            if(setu.aiType == 2){
                title = title + '(AI)';
            }
            $notify("Pixiv", title, author, { "open-url": pictureURL, "media-url": pictureURL }); // Success
        }
    } else {
        $notify("Title", "Subtitle", reason.error); // Error!
    }
    $done({});
})