-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdecensooru_gm4.user.js
48 lines (47 loc) · 4.27 KB
/
decensooru_gm4.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
// ==UserScript==
// @name decensooru
// @namespace *
// @include http*://*.donmai.us/*
// @version 1
// @author Dariush
// @grant GM.setValue
// @grant GM.getValue
// @grant GM.xmlHttpRequest
// @grant unsafeWindow
// ==/UserScript==
(async function(){
console.log('Decensooru started. There are ' + unsafeWindow.localStorage.length + ' items in DB.');
var lastUpdate = await GM.getValue('lastUpdate', 0);
if (Date.now() - lastUpdate < 28800000){ // 8 hours
console.log('Nothing to do, wait for next batch.');
return;
}
GM.setValue('lastUpdate', Date.now());
var need_full_batch = (Date.now() - lastUpdate > 259200000); // 4 days
var notice = document.createElement('div');
notice.textContent = "Decensooru is pulling a " + (need_full_batch ? "full" : "partial") + " batch…";
notice.setAttribute('style', 'position:fixed; right:0; top:0; background: white; border:black solid 1px; font-size:18px; font-family:arial; padding:2px 10px; color: black !important; font-weight: bold');
notice.setAttribute('id', 'decensooru-notice');
document.body.appendChild(notice);
var xhr = GM.xmlHttpRequest({
method: "GET",
url: "https://f001.backblazeb2.com/file/decensooru-batches/" + (need_full_batch ? 0 : 1),
onload: function(response) {
notice.textContent = "Batch pulled, storing…";
var str = response.responseText;
var output = [];
for (var i = 0, len = str.length; i < len; i++) {
var bin = str[i].charCodeAt();
bin = ~bin + 128;
output.push(String.fromCharCode(bin));
}
output = output.join('');
var list = output.trim().split("\n");
for (var i = 0, len = list.length; i < len; i++) {
var data = list[i].split(':');
unsafeWindow.localStorage.setItem(data[0], data[1]);
}
notice.textContent = "Done.";
setTimeout(function(){ notice.parentNode.removeChild(notice); }, 3000);
}});
})();