forked from fireattack/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2ch_add_thumbnail.user.js
More file actions
165 lines (152 loc) · 5.18 KB
/
2ch_add_thumbnail.user.js
File metadata and controls
165 lines (152 loc) · 5.18 KB
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
165
// ==UserScript==
// @name 2ch (5ch) enhancer
// @namespace http://tampermonkey.net/
// @version 5.5
// @author ぬ / fireattack
// @match http://*.5ch.net/*
// @match https://*.5ch.net/*
// @match http://*.2ch.sc/*
// @match https://*.2ch.sc/*
// @match http://*.bbspink.com/*
// @match https://*.bbspink.com/*
// @grant GM_addStyle
// @run-at document-idle
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js
// ==/UserScript==
// Original: https://greasyfork.org/scripts/25165
GM_addStyle(`
#mydiv {
position: fixed;
right: 60px;
top: 10px;
font-size: 12pt;
padding: 10px;
background-color: #FFFFFF;
}
#mylabel {
padding: 5px;
margin: 0 0 5px;
display: block;
}
.folded {
padding: 0px !important;
}
.folded > .message {
display: none !important;
}
`
);
function htmlDecode(input) {
var doc = new DOMParser().parseFromString(input, "text/html");
return doc.documentElement.textContent;
}
function scroll(readId) {
if (!readId) return;
$([document.documentElement, document.body]).animate({
scrollTop: $(`#${readId}`).offset().top
}, 0);
}
function foldPosts(readId) {
let existingContent = [];
$('div.post').each(function () {
$('.meta', this).click(() => {
$(this).toggleClass('folded');
});
$('.meta > span.name a', this).removeAttr("href");
let id = Number($(this).attr('id'));
// Unescape HTML entities
$('.message > span', this).contents().filter(function () {
return this.nodeType === 3; //Node.TEXT_NODE
}).each(function () {
this.textContent = htmlDecode(this.textContent);
})
let text = $('.message', this).text();
let filtered = blacklist.some(w => text.includes(w));
if ((readId && id <= readId) || existingContent.includes(text) || filtered) {
$(this).addClass('folded');
}
else {
existingContent.push(text);
}
});
if (readId) label.innerHTML = `Your last progress is: <b>${readId}</b>`;
}
function setReadProgress() {
let oldId = Number(localStorage.getItem('readId'));
let oldURL = localStorage.getItem('readURL');
let newestId = Number($('div.post').last().attr('id'));
let url = window.location.href;
if (!oldURL || url !== oldURL || !oldId || newestId > oldId) {
localStorage.setItem('readId', newestId);
localStorage.setItem('readURL', url);
localStorage.setItem('readTitle', document.title);
label.innerHTML = `Your last progress is: <b>${newestId}</b>`;
}
}
function addThumb() {
$('div.post').each(function () {
if ($(this).hasClass('folded')) return;
$('div.message a', this).each(function () {
if ($(this).hasClass('done')) return;
var address = $(this).text();
var ext = address.split('.').pop();
var exts = ["jpg", "jpeg", "png", "gif", "bmp"];
if (address.includes('twimg.com') || exts.includes(ext.toLowerCase())) {
$(this).after($('</br><a href=' + address + ' target="_blank"><img src=' + address + ' width=400/></a></br>'));
$(this).addClass('done');
}
});
});
}
var readURL = localStorage.getItem('readURL');
var readId = Number(localStorage.getItem('readId'));
var readTitle = localStorage.getItem('readTitle');
if (window.location.href.includes('read.cgi')) {
var myDiv = document.createElement('div');
myDiv.id = 'mydiv';
document.body.appendChild(myDiv);
var label = document.createElement('p');
label.id = 'label';
label.innerHTML = `Your last progress is: <b>N/A</b>`;
myDiv.appendChild(label);
var myBtn = document.createElement('button');
myBtn.textContent = 'Set reading progress!';
myBtn.onclick = () => {
setReadProgress();
};
myDiv.appendChild(myBtn);
let bl;
var blacklist = [];
if (bl = localStorage.getItem('blacklist')) {
var blacklist = bl.split(';');
}
if (window.location.href !== readURL) readId = 0; //If not the same post, doesn't count.
foldPosts(readId); //Fold both read posts and duplicates
if (window.location.href === readURL) { //Scroll to last read
scroll(readId);
$('button#btGoTop').click(function (e) { //Override top button as well
scroll(readId);
e.stopPropagation();
});
}
addThumb();
//history.scrollRestoration = "manual"; // Use this if you don't want browser to retain the scr. pos.
} else if (window.location.href.includes('krsw.5ch.net/idolmaster')) {
GM_addStyle(`
div.board_header,body > div:nth-child(5),body > div:nth-child(2) > p,div.ADVERTISE_AREA {
display: none;
}
`)
let lastThreadID = Number(readTitle.match(/\d+/)[0]);
$('body > div.HEADER_AREA > h3').append(`<span> Last read: <a href="${readURL}">${readTitle} (${readId})</a></span>`)
$('body > div.THREAD_MENU > div > p').each(function () {
if ($(this).text().includes('箱崎星梨花')) {
let newTitle = $(this).text().replace(/\d+:\s+(.+)$/, '$1');
let newThreadID = newTitle.match(/\d+/)[0];
let newURL = $('a', this)[0].href.replace(/l50$/, '');
if (newThreadID >= lastThreadID)
$('body > div.HEADER_AREA > h3').append(`<span> New thread: <a href="${newURL}">${newTitle}</a></span>`)
return false;
}
})
}