Pixiv Ajax Bookmark Mod

You can bookmark without going to the related pages. ページ遷移なく非同期的にブックマークします。

当前为 2019-09-02 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name             Pixiv Ajax Bookmark Mod
// @namespace        com.SaddestPanda.net.moe
// @version          2.3.2
// @description      You can bookmark without going to the related pages. ページ遷移なく非同期的にブックマークします。
// @include          /^https?:\/\/www.pixiv.net\/member_illust.php.*illust_id=.*/
// @include          /^https?:\/\/www.pixiv.net\/(member.php|member_illust.php|bookmark.php|mypixiv_all.php)\?id=.*/
// @exclude          /^https?:\/\/www.pixiv.net\/member.*mode=manga.*/
// @homepage         https://greasyfork.org/en/scripts/22767-pixiv-ajax-bookmark-mod
// @supportURL       https://greasyfork.org/en/scripts/22767-pixiv-ajax-bookmark-mod/feedback
// @author           qa2 & SaddestPanda
// @require          https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js
// @grant            none
// @run-at           document-idle
// @noframes
// ==/UserScript==

//When you add an illustration to bookmarks also give it a like.
// 1 でしたらブックマークした時、同時に「いいね!」もします。
var givelike = 1;

//R18 illustrations are added as private bookmarks.
// 1 でしたらイラストはR-18であった場合プライベートブックマークにします。
var r18private = 1;

// If set to "1": Always add to private bookmarks list.
//ブックマークする作品をいつも非公開にするかどうか 0:公開 1:非公開
var bkm_restrict = 0;

//Add all tags to the bookmark.
//作品に登録されているすべてのタグをブックマークタグとして追加
var add_all_tags = 1;

var tags, tagsInterval = "", TheInterval = "", resCheckerInterval = "", currLocation = "", restartInterval = "";

pageisNew();

function pageisNew() {
    //console.log("pageisnew");
    clearInterval(restartInterval);
    var TheInterval = setInterval(function () { //Check if the page is using the new design.
        try {
            if (globalInitData.token != null) {
                tagsInterval = setInterval(startingUp, 125);
                clearInterval(TheInterval);
            }
        } catch (e) {}
    }, 125);
}

function startingUp() {
    tags = "";
    //console.log("startingup");
    clearInterval(resCheckerInterval);
    currLocation = document.location.href;
    resCheckerInterval = setInterval(restartChecker, 100);
    //get all tags
    $("footer >").children().each(function () {
        try {
            tags += decodeURIComponent($(this).find("a")[0].href).split("&word=")[1] + " ";
        } catch (e) {}
    });

    if (tags != "") {
        //cancel if already bookmarked
        if ($(".gtm-main-bookmark").length != 1) {
            clearInterval(tagsInterval);
            return;
        } else {
            //Set the button action
            $(".gtm-main-bookmark")[0].href = "javascript:void(0)";
            $(".gtm-main-bookmark").on("click", function () {
                bkm();
                return false;
            });
            //console.log(tags);
            clearInterval(tagsInterval);
        }
    }
}

function restartChecker() {
    if (document.location != currLocation) {
        clearInterval(resCheckerInterval);
        clearInterval(restartInterval);
        restartInterval = setInterval(restartingSoon, 100);
    }
}

function restartingSoon() {
    //console.log("restartingsoon");
    try {
        if ($(".gtm-main-bookmark")[0].disabled == false) {
            pageisNew();
        }
    } catch (e) {}
}


// ajaxでブックマークする関数
function bkm() {
    //console.log("bkm");
    //var illustid = $("input[name=illust_id").val();
    //var tt = $("input[name=tt]").val();
    //var type = $("input[name=type]:eq(1)").val();
    //var illustid = pixiv.context.queries.id;
    var illustid = document.location.href.split("illust_id=")[1];
    var url = "https://www.pixiv.net/bookmark_add.php?id=" + illustid;    //https://www.pixiv.net/bookmark_add.php?rest=show&type=illust&p=1&illust_id=70318176
    var tt = globalInitData.token;
    if (!add_all_tags) {
        tags = "";
    }
    //var illusttype = "illust";

    try {
        if ($("footer >")[0].firstChild.innerText == "R-18" && r18private) {
            bkm_restrict = 1;
        }
    } catch (e) {}

    if (givelike) {
        $(".gtm-main-bookmark").parent()[0].nextSibling.children[0].click();
    }
    $.ajax({
        url: url,
        type: 'POST',
        dataType: 'json',
        data: {
            mode: "add",
            tt: tt,
            id: illustid,
            from_sid: "",
            type: "illust",
            comment: "",
            tag: tags,
            restrict: bkm_restrict,
            success: function () {
                if (bkm_restrict) {
                    //INSERT THE LOCKED HEART (PRIVATE BOOKMARK) SVG        https://yoksel.github.io/url-encoder/
                    $(".gtm-main-bookmark svg")[0].outerHTML = decodeURIComponent("%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32' width='32' height='32' class='j89e3c-1 kcOjCr' style='color: rgb(255, 64, 96);'%3E%3Cdefs%3E%3Cmask id='uid-mask-2'%3E%3Crect x='0' y='0' width='32' height='32' fill='white'%3E%3C/rect%3E%3Cpath d='M16,11.3317089 C15.0857201,9.28334665 13.0491506,7.5 11,7.5%0AC8.23857625,7.5 6,9.73857647 6,12.5 C6,17.4386065 9.2519779,21.7268174 15.7559337,25.3646328%0AC15.9076021,25.4494645 16.092439,25.4494644 16.2441073,25.3646326 C22.7480325,21.7268037 26,17.4385986 26,12.5%0AC26,9.73857625 23.7614237,7.5 21,7.5 C18.9508494,7.5 16.9142799,9.28334665 16,11.3317089 Z' class='j89e3c-0 kBfARi'%3E%3C/path%3E%3C/mask%3E%3C/defs%3E%3Cg mask='url(%23uid-mask-2)'%3E%3Cpath d='%0AM21,5.5 C24.8659932,5.5 28,8.63400675 28,12.5 C28,18.2694439 24.2975093,23.1517313 17.2206059,27.1100183%0AC16.4622493,27.5342993 15.5379984,27.5343235 14.779626,27.110148 C7.70250208,23.1517462 4,18.2694529 4,12.5%0AC4,8.63400691 7.13400681,5.5 11,5.5 C12.829814,5.5 14.6210123,6.4144028 16,7.8282366%0AC17.3789877,6.4144028 19.170186,5.5 21,5.5 Z'%3E%3C/path%3E%3Cpath d='M16,11.3317089 C15.0857201,9.28334665 13.0491506,7.5 11,7.5%0AC8.23857625,7.5 6,9.73857647 6,12.5 C6,17.4386065 9.2519779,21.7268174 15.7559337,25.3646328%0AC15.9076021,25.4494645 16.092439,25.4494644 16.2441073,25.3646326 C22.7480325,21.7268037 26,17.4385986 26,12.5%0AC26,9.73857625 23.7614237,7.5 21,7.5 C18.9508494,7.5 16.9142799,9.28334665 16,11.3317089 Z' class='j89e3c-0 kBfARi'%3E%3C/path%3E%3C/g%3E%3Cpath d='M29.9796 20.5234C31.1865 21.2121 32 22.511 32 24V28%0AC32 30.2091 30.2091 32 28 32H21C18.7909 32 17 30.2091 17 28V24C17 22.511 17.8135 21.2121 19.0204 20.5234%0AC19.2619 17.709 21.623 15.5 24.5 15.5C27.377 15.5 29.7381 17.709 29.9796 20.5234Z' class='j89e3c-2 jTfVcI' style='fill: rgb(255, 255, 255); fill-rule: evenodd; clip-rule: evenodd;'%3E%3C/path%3E%3Cpath d='M28 22C29.1046 22 30 22.8954 30 24V28C30 29.1046 29.1046 30 28 30H21%0AC19.8954 30 19 29.1046 19 28V24C19 22.8954 19.8954 22 21 22V21C21 19.067 22.567 17.5 24.5 17.5%0AC26.433 17.5 28 19.067 28 21V22ZM23 21C23 20.1716 23.6716 19.5 24.5 19.5C25.3284 19.5 26 20.1716 26 21V22H23%0AV21Z' class='j89e3c-3 fZVtyd' style='fill: rgb(31, 31, 31); fill-rule: evenodd; clip-rule: evenodd;'%3E%3C/path%3E%3C/svg%3E");
                } else {
                }
                $(".gtm-main-bookmark svg")[0].style.fill = "#ff4060";
                $(".gtm-main-bookmark svg path")[0].style.fill = "white";
                $(".gtm-main-bookmark")[0].href = "https://www.pixiv.net/bookmark_add.php?type=illust&illust_id=" + illustid;
                $(".gtm-main-bookmark").unbind("click");
                $(".gtm-main-bookmark").on("click", function (e) {
                    e.preventDefault();
                    window.location = "https://www.pixiv.net/bookmark_add.php?type=illust&illust_id=" + illustid;
                    return false;
                });
            }
        },
    });
}