-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ldr_ng.user.js
165 lines (146 loc) · 4.45 KB
/
ldr_ng.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
// ==UserScript==
// @name LDR NG
// @namespace http://d.hatena.ne.jp/zaknak/20080909/1220936155
// @include http://reader.livedoor.com/reader/*
// @include http://fastladder.com/reader/*
// @version 0.1.0
// @grant none
// ==/UserScript==
var w = window;
var ldrNg = {
//NG条件に一致したときタイトルを置き換える文字列
ngTitle: 'NG Item',
NGINFO: [
{
channel: {
force: true
},
item: {
title: [/^AD:/, /^PR:/]
}
},
{
channel: {
force: true
},
item: {
link: /^https:\/\/alpha.app.net/
}
},
{
channel: {
link: /^http:\/\/atnd.org/
},
item: {
title: /TechBuzz/i,
author: /TechBuzz/i
}
}
],
initCount: 0,
checkTarget: function (cond, target) {
if (cond.force) {
return true;
}
var method = cond.and ? 'every' : 'some';
for (var i in cond) {
if (i == 'and' || i == 'force') {
continue;
}
if (cond[i].length) {
if (cond[i][method](function (obj) {
return obj.test(target[i]);
})) {
return true;
}
} else {
if (cond[i].test(target[i])) {
return true;
}
}
}
},
before: function (feed) {
if (feed._checkedNg) {
return;
}
var items = feed.items;
ldrNg.NGINFO.forEach(function (ng) {
if (!ldrNg.checkTarget(ng.channel, feed.channel)) {
return;
}
items.forEach(function (item) {
if (ldrNg.checkTarget(ng.item, item)) {
feed._ngIDlist = feed._ngIDlist || [];
feed._ngIDlist.push(item.id);
item._ngItem = true;
item._title = item.title;
item.title = ldrNg.ngTitle;
}
});
});
feed._checkedNg = true;
if (feed._ngIDlist) {
feed.items = items.filter(function (item) {
return !item._ngItem
}).concat(items.filter(function (item) {
return item._ngItem
}));
}
},
after: function (feed) {
if (!feed._ngIDlist) {
return;
}
feed._ngIDlist.forEach(function (id) {
(function (id) {
var self = arguments.callee;
self.count = self.count || 0;
var bodyId = 'item_body_' + id;
var itemId = 'item_' + id;
var itemBody = w.$(bodyId);
if (itemBody) {
w.addClass(itemBody, 'ngbody');
w.addClass(itemId, 'ngitem');
} else if (self.count++ < 10) {
setTimeout(self, 500, id);
}
})(id);
});
},
openNG: function () {
var count = w.get_active_item();
if (typeof count != 'number') {
w.message('nothing...');
return;
}
var item = w.get_active_feed().items[count];
if (!item._ngItem) {
w.message('This item is not NG.');
return;
}
var bodyId = 'item_body_' + item.id;
var itemId = 'item_' + item.id;
var headId = 'head_' + item.id;
w.removeClass(bodyId, 'ngbody');
w.removeClass(itemId, 'ngitem');
var head = w.$(headId);
var link = head.getElementsByTagName('a')[0];
link.textContent = item._title;
w.message('Done...');
},
init: function () {
if (typeof w.Keybind != 'undefined' && typeof w.register_hook != 'undefined') {
w.Keybind.add('N', ldrNg.openNG);
w.LDR_addStyle('div.ngbody', 'display : none;');
w.LDR_addStyle('div.ngitem', 'font-size : 6px;');
w.register_hook("before_printfeed", ldrNg.before);
w.register_hook("after_printfeed", ldrNg.after);
w.message("LDR NG SETUP is completed.");
} else if (ldrNg.initCount < 5) {
setTimeout(ldrNg.init, 500);
ldrNg.initCount++;
}
}
};
ldrNg.init();