This repository has been archived by the owner on Jul 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathajax_pixiv_bookmark.user.js
124 lines (113 loc) · 3.71 KB
/
ajax_pixiv_bookmark.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// Generated by CoffeeScript 1.6.2
/*
// ==UserScript==
// @id ajax_pixiv_bookmark
// @name AJAX Pixiv Bookmark
// @version 2.0.3
// @namespace http://blog.k2ds.net/
// @author killtw
// @description Using AJAX to add a bookmark in Pixiv
// @match http://www.pixiv.net/member_illust.php?*
// @match http://www.pixiv.net/setting_user.php
// ==/UserScript==
*/
var addjQuery, main;
addjQuery = function(callback) {
var e;
e = document.createElement('script');
e.setAttribute('src', 'http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/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._button').click(function(e) {
var illust_id, illust_tags, input_tag, tt;
e.preventDefault();
illust_tags = [];
input_tag = [];
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() {
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;
_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._button").text('追加中…');
},
success: function() {
$("div.bookmark-container a._button").text('加入成功');
$('div.bookmark-container').fadeOut('fast').html('<a href="bookmark_add.php?type=illust&illust_id=' + illust_id + '" class="button-on">編輯收藏</a>').fadeIn('fast');
}
});
}
});
});
};
addjQuery(main);