-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdecensor.html
440 lines (389 loc) · 17.7 KB
/
decensor.html
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<meta name="msapplication-TileColor" content="#da532c">
<meta property="og:title" content="BetterCensorship" />
<meta property="og:description" content="Censor and decensor images quickly." />
<link rel="stylesheet" href="styles/icomoon.css">
<link rel="stylesheet" href="https://necolas.github.io/normalize.css/8.0.1/normalize.css">
<link rel="stylesheet" href="styles/styles.css">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js" integrity="sha512-E8QSvWZ0eCLGk4km3hxSsNmGWbLtSCSUcewDQPQWZF6pEU8GlT8a5fF32wOl1i8ftdMhssTrF/OhyGWwonTcXA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/aes.min.js" integrity="sha512-4b1zfeOuJCy8B/suCMGNcEkMcQkQ+/jQ6HlJIaYVGvg2ZydPvdp7GY0CuRVbNpSxNVFqwTAmls2ftKSkDI9vtA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="libraries/lz-string/lz-string.min.js"></script>
<script src="libraries/FileSaver-js/FileSaver.js"></script>
<link rel="apple-touch-icon" sizes="180x180" href="apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="favicon-16x16.png">
<link rel="manifest" href="site.webmanifest">
<title>BetterCensorship</title>
</head>
<body>
<div class="pageContainer d-flex align-items-center justify-content-center">
<div class="langRight">
<div class="languageSelector">
<span onclick="dropDownFlipper()"></span>
<div class="languageList">
</div>
</div>
</div>
<div id="decensorUpload" class="d-flex flex-column align-items-center" onclick="loadPage()" ondrop="dropHandler(event)" ondragover="dragOverHandler(event)">
<span class="icon-folder-upload"></span>
<span class="uploadText">Open File</span>
<span class="fileDistinction">(For Decensoring)</span>
</div>
<div id="canvasContainer">
<canvas id="drawingBoard"></canvas>
<div class="keyContainer">
<label id="keyText" for="key">Password: </label>
<input type="text" id="key" name="key">
</div>
<span id="keyHelpText">
(Leave empty if none)
</span>
<span id="decensorButton" onclick="decensorButton();">
Decensor!
</span>
</div>
<footer>
<div class="navLeft">
<div class="navigationContainer ">
<a href="/index.html">Home</a> /
<a href="/censor.html">Censor</a> /
<a href="/decensor.html">Decensor</a> /
<a href="/faq.html">FAQ</a>
</div>
</div>
<div class="versionRight">
<div class="versionContainer">
<span id="versionString">BetterCensorship vX.X.X</span><br>
<span><a href="https://www.patreon.com/BetterRepack">Patreon</a> /
<a href="https://subscribestar.adult/betterrepack">SubscribeStar</a> /
<a href="https://twitter.com/ProjRailgun">Twitter</a>
</span>
</div>
</div>
</footer>
</div>
<div class="error" id="notAnImage" title="Error">File is not an Image. Press OK to reload the page</div>
<div class="error" id="notBetterCensorshipImage" title="Error">Image not generated by BetterCensorship. Press OK to reload the page</div>
<div class="error" id="passwordIncorrect" title="Error">Password Incorrect. Press OK to reload the page</div>
<div class="error" id="dataPayloadCorrupted" title="Error">Data Payload Corrupted. Payload may be password protected. Press OK to reload the page</div>
<div class="status" id="loading" title="Loading">Please wait while the image processes. Processing time depends upon image size and edited content</div>
<script>
// Language Selector Code
let configDump, linesetDump;
function getCountryFlag(cc) {
// Mild sanity check.
if (cc.length !== 2)
return cc;
// Convert char to Regional Indicator Symbol Letter
function risl(chr) {
return String.fromCodePoint(0x1F1E6 - 65 + chr.toUpperCase().charCodeAt(0));
}
// Create RISL sequence from country code.
return risl(cc[0]) + risl(cc[1]);
}
function dropDownFlipper() {
let display = $(".languageList").css("display");
if (display === "none") {
display = "block"
} else {
display = "none";
}
$(".languageList").css("display", display);
}
function languageSetter(language) {
localStorage.setItem("lang", language)
location.href = location.href.split("?")[0];
}
$.getJSON("languages/config.json")
.done(langConfigArray=>{
let language;
configDump = langConfigArray;
let setLang = localStorage.getItem("lang");
if (setLang) {
language = setLang
} else {
language = "English"
}
configDump.forEach((item)=>{
if (item["name"] === language || item["country-code"] === language) {
$(".languageSelector span").text(getCountryFlag(item["country-code"]))
$.getJSON(`languages/${item["filename"]}`)
.done(lang=>{
linesetDump = lang[2]["lineset"];
$(".uploadText").text(linesetDump[0]);
$(".fileDistinction").text(linesetDump[1]);
$("#keyText").text(linesetDump[2]);
$("#keyHelpText").text(linesetDump[3]);
$("#decensorButton").text(linesetDump[4]);
$("[aria-describedby='notAnImage'] .ui-dialog-title").text(linesetDump[5]);
$("[aria-describedby='notBetterCensorshipImage'] .ui-dialog-title").text(linesetDump[5]);
$("[aria-describedby='passwordIncorrect'] .ui-dialog-title").text(linesetDump[5]);
$("[aria-describedby='dataPayloadCorrupted'] .ui-dialog-title").text(linesetDump[5]);
$("[aria-describedby='loading'] .ui-dialog-title").text(linesetDump[6]);
$("#notAnImage").text(linesetDump[7]);
$("#notBetterCensorshipImage").text(linesetDump[8]);
$("#passwordIncorrect").text(linesetDump[9]);
$("#dataPayloadCorrupted").text(linesetDump[10]);
$("#loading").text(linesetDump[11]);
$("[aria-describedby='notAnImage'] .ui-button").text(linesetDump[13]);
$("[aria-describedby='notBetterCensorshipImage'] .ui-button").text(linesetDump[13]);
$("[aria-describedby='resTooLarge'] .ui-button").text(linesetDump[13]);
$("[aria-describedby='imageContainsPayload'] .ui-button").text(linesetDump[13]);
// //$("").text(linesetDump[]);
$(".navigationContainer a:nth-child(1)").text(linesetDump[14]);
$(".navigationContainer a:nth-child(2)").text(linesetDump[15]);
$(".navigationContainer a:nth-child(3)").text(linesetDump[16]);
$(".navigationContainer a:nth-child(4)").text(linesetDump[17]);
$(".versionContainer a:nth-child(1)").text(linesetDump[18]);
$(".versionContainer a:nth-child(2)").text(linesetDump[19]);
$(".versionContainer a:nth-child(3)").text(linesetDump[20]);
})
}
$(".languageSelector .languageList").append(
`
<div class="lang-item" title="${item["country-code"]}" onclick="languageSetter('${item["name"]}')">
${getCountryFlag(item["country-code"])}
</div>
`
)
})
//Additional patch for url based language setting
try {
let langCode = window.location.search.substr(1).split("&")[0].split("=")[1]
configDump.forEach((item)=>{
if (item["country-code"] === langCode) {
languageSetter(langCode)
}
})
} catch {
//Catch added to avoid undefined errors.
}
//End patch
})
//End of Language Selector Code
</script>
<script>
let globalVersion = "BetterCensorship v1.1"
$("#versionString").text(globalVersion);
let _URL = window.URL || window.webkitURL;
let display = $("#canvasContainer").css("display");
$("#canvasContainer").css("display", "none");
let decensor, decensorButton;
let fileInput = $("<input type=file>");
let notAnImageDialog = $("#notAnImage");
let notBCImageDialog = $("#notBetterCensorshipImage");
let passwordIncorrectDialog = $("#passwordIncorrect");
let dataPayloadCorruptedDialog = $("#dataPayloadCorrupted");
let loadingDialog = $("#loading");
loadingDialog.dialog({
autoOpen: false,
modal: true,
dialogClass: "systemMessage no-close",
minWidth: 250,
})
let dialogOptions = {
autoOpen: false,
modal: true,
dialogClass: "systemMessage errorDialog no-close",
minWidth: 250,
buttons: [
{
text: "OK",
click: function () {
window.location.reload();
}
}
],
position: {
my: "center",
at: "center",
of: window
}
}
notAnImageDialog.dialog(dialogOptions);
notBCImageDialog.dialog(dialogOptions);
passwordIncorrectDialog.dialog(dialogOptions);
dataPayloadCorruptedDialog.dialog(dialogOptions);
let loadPage = function () {
fileInput.click();
return false;
}
fileInput.change(function () {
let file;
if ((file = this.files[0])) {
handleFile(file);
}
})
let dragOverHandler = function (e) {
//Shut up, browser.
e.preventDefault();
}
let dropHandler = function (e) {
let file
//Seriously, shut up, browser.
e.preventDefault();
if ((file = e.dataTransfer.files[0])) {
handleFile(file);
}
}
let handleFile = function (file) {
let img = new Image();
let filename = file.name;
let canvas = $("#drawingBoard")[0];
let ctx = canvas.getContext("2d");
img.onload = function () {
$("#canvasContainer").css("display", display)
$("#decensorUpload").attr('style', 'display: none !important');
canvas.height = this.height;
canvas.width = this.width;
if (this.height > (document.documentElement.clientHeight/1.5)) {
let scalar = this.height/(document.documentElement.clientHeight/1.5);
$("#drawingBoard").css("height", `${this.height/scalar}px`)
$("#drawingBoard").css("width", `${this.width/scalar}px`)
} else if (this.width > (document.documentElement.clientWidth/1.2)) {
let scalar = this.width/(document.documentElement.clientWidth/1.2);
$("#drawingBoard").css("height", `${this.height/scalar}px`)
$("#drawingBoard").css("width", `${this.width/scalar}px`)
}
ctx.drawImage(img, 0, 0);
decensorButton = function () {
loadingDialog.dialog("open");
setTimeout(()=>{
decensor();
}, 1)
}
decensor = function () {
let reader = new FileReader();
let payload, view, list, iend, encryption, version, decrypted;
reader.onload = function () {
try {
view = new Uint8Array(reader.result);
list = metadata.splitChunk(Uint8ToString(view));
iend = list.pop();
payload = list.pop();
encryption = list.pop();
version = list.pop();
//Might error at the strict type check
if ((version.data.split("Version\u0000").join("")).split(" ")[0] !== "BetterCensorship") {
throw new Error(linesetDump[12]);
}
try {
let key = $("#key").val();
payload = payload.data.split("Payload\u0000").join("")
let decryptedCompressed = CryptoJS.AES.decrypt(payload, key).toString(CryptoJS.enc.Utf16);
decrypted = LZString.decompress(decryptedCompressed);
try {
let decryptedPayload = JSON.parse(decrypted);
let canvasData = ctx.getImageData(0, 0, canvas.width, canvas.height)
decryptedPayload.items.forEach(chunk=>{
for (let i = 0; i<decryptedPayload.chunkSize; i++) {
let array = unpack(chunk.arrayString);
canvasData.data[(chunk.chunkIndex+i)] = array[i];
}
})
ctx.putImageData(canvasData, 0, 0)
loadingDialog.dialog("close");
$("#decensorButton").text(linesetDump[21]).click(function (){
let link = document.createElement('a');
link.download = filename.split(".")[0] + '_decensored.png';
link.href = canvas.toDataURL()
link.click();
})
} catch {
dataPayloadCorruptedDialog.dialog("open");
$("body").css('background-color', "grey");
ctx.clearRect(0, 0, canvas.width, canvas.height);
}
} catch {
passwordIncorrectDialog.dialog("open");
$("body").css('background-color', "grey");
ctx.clearRect(0, 0, canvas.width, canvas.height);
}
} catch {
notBCImageDialog.dialog("open");
$("body").css('background-color', "grey");
ctx.clearRect(0, 0, canvas.width, canvas.height);
}
}
reader.readAsArrayBuffer(file);
}
}
img.onerror = function () {
notAnImageDialog.dialog("open");
$("body").css('background-color', "grey");
}
img.src = _URL.createObjectURL(file);
}
</script>
<script>
//Foreign Code
function unpack(str) {
var bytes = [];
for(var i = 0, n = str.length; i < n; i++) {
var char = str.charCodeAt(i);
bytes.push(char >>> 8, char & 0xFF);
}
return bytes;
}
let metadata = {}
metadata.PNG_SIG = String.fromCharCode(0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a);
function Uint8ToString(u8a){
var CHUNK_SZ = 0x8000;
var c = [];
for (var i=0; i < u8a.length; i+=CHUNK_SZ) {
c.push(String.fromCharCode.apply(null, u8a.subarray(i, i+CHUNK_SZ)));
}
return c.join("");
}
metadata.isPNG = function (s) {
var sig = s.substr(0, 8);
return (sig === metadata.PNG_SIG);
};
metadata.splitChunk= function (s) {
// read signature
var sig = s.substr(0, 8);
if (!metadata.isPNG(sig)) return false;
s = s.substr(8); // chomp sig
var chunklist = [];
// read chunk list
while (s !== '') {
var chunk = {};
// read chunk size
var size = stoi(s.substr(0, 4));
if (size < 0) {
// If the size is negative, the data is likely corrupt, but we'll let
// the caller decide if any of the returned chunks are usable.
// We'll move forward in the file with the minimum chunk length (12 bytes).
size = 0;
}
var buf = s.substr(0, size + 12);
s = s.substr(size + 12); // delete this chunk
// read chunk data
chunk.size = size;
chunk.type = buf.substr(4, 4);
chunk.data = buf.substr(8, size);
chunk.crc = stoi(buf.substr(8 + size, 4));
// add chunk
chunklist.push(chunk);
}
return chunklist;
};
metadata.stoi = stoi;
function stoi(s) {
var v = 0;
for (var i = 0; i < s.length; i++) {
var c = s.charCodeAt(i);
v = (v << 8) | (c & 0xFF);
}
return v;
}
</script>
</body>
</html>