AJAX Pixiv Bookmark

Modified from https://github.com/killtw/AJAX-Pixiv-Bookmark 可自动从 http://www.pixiv.net/bookmark_tag_all.php 获取可用的标签。

目前為 2017-04-18 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @id             ajax_pixiv_bookmark
// @name           AJAX Pixiv Bookmark
// @version        2.0.7
// @description  Modified from https://github.com/killtw/AJAX-Pixiv-Bookmark 可自动从 http://www.pixiv.net/bookmark_tag_all.php 获取可用的标签。
// @namespace      http://blog.k2ds.net/
// @author         pks
// @description    Using AJAX to add a bookmark in Pixiv
// @match          http://www.pixiv.net/member_illust.php?*
// @match          https://www.pixiv.net/member_illust.php?*
// @match          http://www.pixiv.net/setting_user.php
// @match          https://www.pixiv.net/setting_user.php
// @icon         https://www.pixiv.net/favicon.ico
// ==/UserScript==


var loadJQ, main;

loadJQ = function(callback) {
    var e;

    e = document.createElement('script');
    e.setAttribute('src', '//cdn.bootcss.com/jquery/1.12.4/jquery.min.js');
    e.addEventListener('load', function() {
        var script;

        script = document.createElement('script');
        script.textContent = "(" + callback.toString() + ")();";
        document.body.appendChild(script);
    });
    document.body.appendChild(e);
};

main = function() {
    var settings;

    settings = {
        default_tag: localStorage.default_tag
    };
    $('table tbody:eq(1)').append('\
<tr><th>預設標籤</th><td>\
<p>當沒有符合的標籤時將使用代入預設標籤,空白即不代入預設標籤</p>\
<p><input type="text" name="default_tag" onkeyup="localStorage.setItem(\'default_tag\', this.value)" value="' + settings.default_tag + '"></p>\
</td></tr>');
    $('div.bookmark-container a._bookmark-toggle-button.add-bookmark').click(function(e) {
        var illust_id, illust_tags, input_tag, tt, my_tags;

        e.preventDefault();
        illust_tags = [];
        input_tag = [];
        my_tags = [];
        illust_id = document.URL.match(/\d+/)[0];
        tt = $('input[name="tt"]').val();
        $.ajax({
            url: 'http://www.pixiv.net/bookmark_tag_all.php',
            type: 'GET',
            dataType: 'html',
            beforeSend: function() {
                $("div.bookmark-container a._bookmark-toggle-button").text('数据准备中…');

                var tag, _i, _len, _ref;

                if (document.URL.match('manga')) {
                    $.ajax({
                        url: "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=" + illust_id,
                        type: 'GET',
                        dataType: 'html',
                        async: false,
                        success: function(data) {
                            var tag, _i, _len, _ref;

                            _ref = $(data).find('a.text');
                            for (_i = 0, _len = _ref.length; _i < _len; _i++) {
                                tag = _ref[_i];
                                illust_tags.push(tag.text);
                            }
                            return tt = $(data).find('input[name="tt"]')[0].value;
                        }
                    });
                } else {
                    _ref = $('a.text');
                    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
                        tag = _ref[_i];
                        illust_tags.push(tag.text);
                    }
                }
            },
            success: function(data) {
                var tag, _i, _len, _ref;

                $(data).find('a.tag-name').text(function(index,text){
                    my_tags.push(text);
                });
                _ref = $(data).find('a.tag-name');
                for (_i = 0, _len = _ref.length; _i < _len; _i++) {
                    tag = _ref[_i];
                    if (illust_tags.indexOf(tag.text) !== -1) {
                        input_tag.push(tag.text);
                    }
                }
                if (input_tag.length === 0) {
                    input_tag.push(settings.default_tag);
                }
            },
            complete: function() {
                $.ajax({
                    url: 'bookmark_add.php',
                    data: {
                        mode: 'add',
                        tt: tt,
                        id: illust_id,
                        tag: input_tag.join(' '),
                        type: 'illust',
                        form_sid: '',
                        restrict: '0'
                    },
                    dataType: 'html',
                    type: 'POST',
                    beforeSend: function() {
                        $("div.bookmark-container a._bookmark-toggle-button").text('追加中…');
                    },
                    success: function() {
                        $("div.bookmark-container a._bookmark-toggle-button").text('加入成功');
                        $('div.bookmark-container').fadeOut('fast').html('<a href="bookmark_add.php?type=illust&illust_id=' + illust_id + '" class="_bookmark-toggle-button bookmarked edit-bookmark"><span class="description">编辑收藏</span></a>').fadeIn('fast');
                    }
                });
            }
        });
    });
};

loadJQ(main);