-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcok.r18.user.js
More file actions
218 lines (206 loc) · 7.24 KB
/
Copy pathcok.r18.user.js
File metadata and controls
218 lines (206 loc) · 7.24 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
// ==UserScript==
// @name COK.R18
// @name:zh-cn 刚满 18 岁 Cookie 版
// @namespace https://github.com/Vinfall/UserScripts
// @version 0.17.3
// @author Vinfall
// @match https://archive.org/details/*
// @match https://archive.org/download/*
// @match https://fc2db.net/*
// @match https://jaststore.com/games/*/*
// @match https://jaststore.com/zh_Hans/games/*/*
// @match https://jaststore.com/zh_Hant/games/*/*
// @match https://jkforum.net/p/forum-*
// @match https://jkforum.net/p/type-*
// @match https://jkforum.net/p/thread-*
// @match https://moepedia.net/
// @match https://moepedia.net/*
// @match https://moepedia.net/game/*
// @match https://ntrdb.com/
// @match https://ntrdb.com/*
// @match https://store.steampowered.com/agecheck/app/*
// @match https://store.steampowered.com/agecheck/bundle/*
// @match https://store.steampowered.com/agecheck/sub/*
// @match https://www.dlsite.com/*-touch/
// @match https://www.dlsite.com/*-touch/*
// @match https://www.dlsite.com/*/announce/=/product_id/*
// @match https://www.dlsite.com/*/work/=/product_id/*
// @match https://www.getchu.com/item/*
// @match https://www.getchu.com/php/attestation.html?aurl=*
// @match https://www.gog.com/*/game/*
// @match https://www.moyu.moe/*
// @match https://www.nintendo.com/*/store/products/*
// @match https://www.nintendo.com/us/store/products/*
// @match https://www.ptt.cc/ask/over18?from=*
// @match https://www.ptt.cc/bbs/*/*.html
// @exclude-match https://fc2db.net/auth/*
// @exclude-match https://www.gog.com/forum/*
// @exclude-match https://www.moyu.moe/*/*/pr
// @exclude-match https://www.moyu.moe/about
// @exclude-match https://www.moyu.moe/about/*
// @exclude-match https://www.moyu.moe/auth/*
// @exclude-match https://www.moyu.moe/edit/create
// @exclude-match https://www.moyu.moe/friend-link
// @exclude-match https://www.moyu.moe/login
// @exclude-match https://www.moyu.moe/register
// @grant unsafeWindow
// @grant GM_getValue
// @grant GM_setValue
// @run-at document-start
// @license CC0 1.0 Universal (Public Domain)
// @icon data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🔞</text></svg>
// @description Certainly Older than Kid, aka. COK.R18
// @description:zh-cn 因为我刚满 18 岁~
// ==/UserScript==
// Docs: https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie
/*
TODO
- set cookie_override via GM_setValue
- set cookie in the correct way (is it even possible?)
*/
// patch for 'unsafeWindow is not defined'
const _global = typeof unsafeWindow === 'undefined' ? window : unsafeWindow;
const cookie_override = true;
const config = [
{
domains: ['archive.org'],
name: 'hide_flag_porn',
value: '1',
},
{
domains: ['dlsite.com'],
name: 'adultchecked',
value: '1',
},
{
domains: ['fc2db.net'],
name: 'mdb_age_gate_confirmed',
value: '1',
},
{
domains: ['getchu.com'],
name: 'getchu_adalt_flag',
value: 'getchu.com',
},
{
domains: ['gog.com'],
name: 'gog_wantsmaturecontent',
value: '18',
},
{
domains: ['jaststore.com'],
name: 'mature-warning-check',
value: '1',
},
{
domains: ['jkforum.net'],
name: 'apea',
value: '100',
},
{
domains: ['moepedia.net'],
name: 'adult',
value: '1',
},
{
domains: ['nintendo.com'],
name: 'nintendo.ageGate.isOldEnough',
value: '"true"', // this IS correct, the value is literal "true"
},
{
domains: ['ntrdb.com'],
name: 'ntrdb_age_confirmed',
value: '1',
},
{
domains: ['ptt.cc'],
name: 'over18',
value: '1',
},
{
domains: ['store.steampowered.com'],
name: 'birthtime', // not lastagecheckage or wants_mature_content
value: '-3599',
},
// {
// domains: ['www.moyu.moe'],
// name: 'kun-patch-setting-store',
// value: '%7B%22data%22%3A%7B%22kunNsfwEnable%22%3A%22all%22%2C%22nsfwAckedIds%22%3A%5B%5D%2C%22titleLanguage%22%3A%22zh-cn%22%2C%22showJapaneseSubtitle%22%3Afalse%2C%22showReleaseDate%22%3Afalse%2C%22showNsfwBadge%22%3Atrue%2C%22showGalgamesWithoutResource%22%3Afalse%7D%7D',
// }, // would overwrite user pref
];
/**
* Find config via hostname
* @returns {object|undefined}
*/
function getMatchingConfig() {
const hostname = window.location.hostname;
return config.find((item) => item.domains.some((domain) => hostname.includes(domain)));
}
/**
* Get Cookie
* @param {string} name
* @returns {string|null}
*/
function getCookie(name) {
const match = document.cookie.match(new RegExp(`(^|;\\s*)${name}=([^;]+)`));
return match ? match[2] : null;
}
/**
* Set Cookie
* @param {string} name
* @param {string} value
* @param {number} days
*/
function setCookie(name, value, days = 365) {
const date = new Date();
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
const expires = `expires=${date.toUTCString()}`;
// biome-ignore lint/suspicious/noDocumentCookie: CookieStore only works for HTTPS
document.cookie = `${name}=${value}; ${expires}; path=/; SameSite=Lax`;
}
function main() {
const matchingConfig = getMatchingConfig();
if (!matchingConfig) {
console.log('%c[COK.R18]%c Domain not found. Skipping.', 'color: #90060a; font-weight: bold;', '');
return;
}
const { name, value } = matchingConfig;
const currentCookieValue = getCookie(name);
// cookie w/ correct value
if (currentCookieValue === value) {
console.log(
`%c[COK.R18]%c Cookie "${name}" value matched, skipping.`,
'color: #90060a; font-weight: bold;',
'',
);
return;
}
// no cookie or wrong value
if (currentCookieValue !== null) {
// wrong value
if (cookie_override) {
console.log(
`%c[COK.R18]%c Cookie "${name}" value mismatch, and cookie_override is true, overwriting...`,
'color: #90060a; font-weight: bold;',
'',
);
setCookie(name, value);
// refresh page after setting cookie
location.reload();
} else {
console.log(
`%c[COK.R18]%c Cookie "${name}" value mismatch, but cookie_override is false, skipping...`,
'color: #90060a; font-weight: bold;',
'',
);
return;
}
} else {
// no cookie
console.log(`%c[COK.R18]%c Cookie "${name}" not found, setting...`, 'color: #90060a; font-weight: bold;', '');
setCookie(name, value);
// refresh page after setting cookie
location.reload();
}
}
main();