Skip to content

Commit

Permalink
Upd pikabu parser
Browse files Browse the repository at this point in the history
  • Loading branch information
NC22 committed Dec 16, 2023
1 parent cb4b2d8 commit d1f7373
Show file tree
Hide file tree
Showing 10 changed files with 226 additions and 49 deletions.
4 changes: 2 additions & 2 deletions extension/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -768,10 +768,10 @@
"message":"Related doc"
},
"related_doc_limit_one":{
"message":"Take only biggest one image per document"
"message":"Take only one best match image"
},
"related_doc_limit_all":{
"message":"Take any image that bigger then preview"
"message":"Take all images that bigger then preview"
},
"restore":{
"message":"Restore"
Expand Down
6 changes: 4 additions & 2 deletions extension/env/init/recorderPopup.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,13 +429,15 @@ KellyPopupPage.init = function() {
sm.loadDB('config', function(fav) {

if (fav) {

if (fav.coptions.toolbar && fav.coptions.toolbar.heartHidden) {
KellyPopupPage.buttons['support_project'].hidden = true;
}

// console.log(fav.coptions);

if (fav.coptions.darkTheme) KellyPopupPage.css.push('darkRecorderPopup');

} else {
KellyPopupPage.css.push('darkRecorderPopup');
}

KellyTools.getBrowser().runtime.sendMessage({method: "getResources", items : KellyPopupPage.css}, function(request) {
Expand Down
7 changes: 6 additions & 1 deletion extension/lib/kellyFavItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -1858,7 +1858,12 @@ function KellyFavItems(cfg)
}
}

updatePagination(KellyTools.getElementByClass(sideBarWrap, env.className + '-pagination'));
updatePagination(KellyTools.getElementByClass(sideBarWrap, env.className + '-pagination'));

if (env.events.onUpdateImagesBlock) {
env.events.onUpdateImagesBlock(handler, imagesBlock, startItem, end, page, totalPages);
}

return true;
}

Expand Down
8 changes: 4 additions & 4 deletions extension/lib/kellyGrabber.js
Original file line number Diff line number Diff line change
Expand Up @@ -946,10 +946,10 @@ function KellyGrabber(cfg) {

function showDownloadItemInfoTooltip(downloadIndex, target) {

if (KellyTools.getElementByClass(document, fav.getGlobal('env').className + '-tooltipster-help')) {
KellyTools.log('tooltip is not exist', 'KellyGrabber');
return;
}
// if (KellyTools.getElementByClass(document, fav.getGlobal('env').className + '-tooltipster-help')) {
// KellyTools.log('tooltip is not exist', 'KellyGrabber');
// return;
// }

if (!downloads[downloadIndex]) {
KellyTools.log('cant display item info by downloadIndex : ' + downloadIndex, 'KellyGrabber');
Expand Down
2 changes: 1 addition & 1 deletion extension/lib/kellyOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ function KellyOptions(cfg) {
if (!fav.coptions.grid.rowHeight || fav.coptions.grid.rowHeight <= 0) fav.coptions.grid.rowHeight = 250;
if (!fav.coptions.grid.min || fav.coptions.grid.min <= 0) fav.coptions.grid.min = 2;
if (!fav.coptions.grid.heightDiff || fav.coptions.grid.heightDiff <= 0) fav.coptions.grid.heightDiff = 10;
if (!fav.coptions.grid.perPage || fav.coptions.grid.perPage <= 0) fav.coptions.grid.perPage = 60;
if (!fav.coptions.grid.perPage || fav.coptions.grid.perPage <= 0) fav.coptions.grid.perPage = 40;
if (fav.coptions.grid.perPage > 1000) fav.coptions.grid.perPage = 1000;
if (fav.coptions.grid.heightDiff > 60) fav.coptions.grid.heightDiff = 60;

Expand Down
4 changes: 2 additions & 2 deletions extension/lib/kellyStorageManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,7 @@ function KellyFavStorageManager(cfg) {
addToFavSide : false,
addToFavNoConfirm : false,
webRequest : true,
// darkTheme : true,
darkTheme : true,
// storageDesc - associations of .storage keys with pretty names | todo - make changable from options [Profiles] tab
};
}
Expand Down Expand Up @@ -1358,7 +1358,7 @@ function KellyFavStorageManager(cfg) {
heightDiff : 10,
min : 2,
cssItem : '',
perPage : 60,
perPage : 40,
viewerShowAs : 'hd',
autoScroll : 1,
lazy : true,
Expand Down
211 changes: 181 additions & 30 deletions extension/lib/recorder/filters/pikabu.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,159 @@ KellyRecorderFilterPikabu.onBeforeDownloadValidate = function(handler, data) {

}

KellyRecorderFilterPikabu.previewLoader = {
work : [],
all : [],
images : [],
done : 0,
aborted : false,
abort : function() {

console.log('[KellyRecorderFilterPikabu] Decoder cleanup');

KellyRecorderFilterPikabu.previewLoader.aborted = true;
var works = KellyRecorderFilterPikabu.previewLoader.work;
for (var i = 0; i < works.length; i++) {
if (works[i].request) {
console.log('[KellyRecorderFilterPikabu] stopped [' + works[i].src + ']');
works[i].request.abort();
}
}

KellyRecorderFilterPikabu.previewLoader.done = 0;
KellyRecorderFilterPikabu.previewLoader.work = [];
},
refresher : function(limit) {

var info = document.getElementById('pikabu-decode-counter');
info.innerText = 'Осталось расшифровать : ' + (KellyRecorderFilterPikabu.previewLoader.images.length + KellyRecorderFilterPikabu.previewLoader.work.length);

if (KellyRecorderFilterPikabu.previewLoader.done >= limit) {
K_FAV.updateImagesBlock();
K_FAV.updateImageGrid();
KellyRecorderFilterPikabu.previewLoader.done = 0;
}
},
run : function() {

if (KellyRecorderFilterPikabu.previewLoader.aborted) return;

var works = KellyRecorderFilterPikabu.previewLoader.work;
if (works.length >= 3) return;

var job = KellyRecorderFilterPikabu.previewLoader.images.pop();
if (!job) {
KellyRecorderFilterPikabu.previewLoader.refresher(1);
if (KellyRecorderFilterPikabu.tooltip) KellyRecorderFilterPikabu.tooltip.show(false);
return;
}

works.push(job);
console.log('[KellyRecorderFilterPikabu] init work [' + job.src + ']');
job.request = KellyTools.fetchRequest(job.src, {responseType : 'arrayBuffer'}, function(urlOrig, arrayBuffer, errorCode, errorText, controller) {

job.request = false;
var jobKey = works.indexOf(job);
if (jobKey != -1) {
works.splice(jobKey, 1);
}

if (arrayBuffer !== false) {

var byteArray = new Uint8Array( arrayBuffer );
var result = KellyRecorderFilterPikabu.deNSFW.descramble(byteArray, parseInt(job.src.split('#nsfw')[1]));
if (result.base64) {
job.item.pImage = URL.createObjectURL(KellyTools.base64toBlob(result.base64, result.contentType));
console.log('[KellyRecorderFilterPikabu] Done ... [' + job.src + ']');
KellyRecorderFilterPikabu.previewLoader.done++;
KellyRecorderFilterPikabu.previewLoader.refresher(10);

} else {
//data.self.aDProgress.addErrorItem(false, 'Decode ... Err base64 [' + job.imgEl.src + ']');
console.log('[KellyRecorderFilterPikabu] Decode ... Err base64 [' + job.src + ']');
}

byteArray = null;
} else {
//data.self.aDProgress.addErrorItem(false, 'Decode ... Err arrayBuffer [' + job.imgEl.src + ']');
console.log('[KellyRecorderFilterPikabu] Decode ... Err arrayBuffer [' + job.src + ']');

}

setTimeout(KellyRecorderFilterPikabu.previewLoader.run, 500);
});

},
add : function(item) {

if (KellyRecorderFilterPikabu.previewLoader.all.indexOf(item.id) != -1) return;

KellyRecorderFilterPikabu.previewLoader.all.push(item.id);
console.log('[KellyRecorderFilterPikabu] Decode ... [' + item.id + ']');
//data.self.aDProgress.addErrorItem(false, 'Decode ... [' + imgEl.src + ']');

KellyRecorderFilterPikabu.previewLoader.images.push({src : item.pImage, item : item});
KellyRecorderFilterPikabu.previewLoader.run();
},
decodeCurrentPage : function() {

KellyRecorderFilterPikabu.previewLoader.aborted = false;
var dList = K_FAV.getGlobal('filtered');
var items = K_FAV.getGlobal('fav').items;

for (var i = KellyRecorderFilterPikabu.previewLoader.initData.startItem; i <= KellyRecorderFilterPikabu.previewLoader.initData.end; i++) {

if (items[dList[i]].pImage.indexOf('#nsfw') != -1) {
KellyRecorderFilterPikabu.previewLoader.add(items[dList[i]]);
}
}


if (KellyRecorderFilterPikabu.tooltip) KellyRecorderFilterPikabu.tooltip.show(KellyRecorderFilterPikabu.previewLoader.images.length > 0);
}

}

KellyRecorderFilterPikabu.onUpdateImagesBlock = function(handler, data) {


if (handler.url.indexOf('pikabu.ru') == -1) return;

KellyRecorderFilterPikabu.previewLoader.initData = data;
KellyRecorderFilterPikabu.previewLoader.decodeCurrentPage();


}

KellyRecorderFilterPikabu.onRecorderImagesShow = function(handler, data) {

if (handler.url.indexOf('pikabu.ru') == -1) return;

if (KellyDPage.cats['pikabu_nsfw'] && KellyDPage.cats['pikabu_nsfw'].id) {

var tooltip = KellyTools.getNoticeTooltip(KellyDPage.env.hostClass, KellyDPage.env.className);

KellyTools.setHTMLData(tooltip.getContent(), '<div>На странице обнаружены <b>NSFW</b> картинки которые сайт отдает в зашифрованном виде. ' +
'При скачивании расширение попробует их автоматически разблокировать и сохранить в исходном виде. ' +
'Если разработчики сайта поменяли алгоритм и разблокировка перестала работать, дайте знать на <b>radiokellyc@gmail.com</b></div>');
KellyRecorderFilterPikabu.tooltip = KellyTools.getNoticeTooltip(KellyDPage.env.hostClass, KellyDPage.env.className);
KellyRecorderFilterPikabu.tooltip.updateCfg({removeOnClose : false, closeByBody : false});

KellyTools.setHTMLData(KellyRecorderFilterPikabu.tooltip.getContent(), '<div><b>Расшифровка превью контента : </b> [<a href="#" id="pikabu-decode-stop">Остановить</a>]</div><div id="pikabu-decode-counter">Инициализация...</div><div>На странице обнаружены <b>NSFW</b> картинки которые сайт отдает в зашифрованном виде, необязательно дожидатся расшифровки превью, данные будут дешифрованы при скачивании</div>');

document.getElementById('pikabu-decode-stop').onclick = function() {

if (this.getAttribute('data-stoped') == '1') {

this.setAttribute('data-stoped', '0');
this.innerText = 'Остановить';
KellyRecorderFilterPikabu.previewLoader.all = [];
KellyRecorderFilterPikabu.previewLoader.decodeCurrentPage();

} else {
this.setAttribute('data-stoped', '1');
this.innerText = 'Начать';
KellyRecorderFilterPikabu.previewLoader.abort();
}

}

tooltip.show(true);
// KellyRecorderFilterPikabu.tooltip.show(true);
}
}

Expand All @@ -50,32 +190,43 @@ KellyRecorderFilterPikabu.addItemByDriver = function(handler, data) {
if (data.item.relatedSrc.length <= 0) return handler.addDriverAction.SKIP;
return handler.addDriverAction.ADD;

// catch decompiled item, oreder is important (must be upper common "article" detector)
// catch decompiled item, order is important (must be upper common "article" detector)

} else if (data.el.tagName == 'IMG' && data.el.getAttribute('data-src') && data.el.getAttribute('data-viewable') && KellyTools.getParentByTag(data.el, 'ARTICLE')) {

var pdata = data.el.getAttribute('data-src');
var fdata = data.el.getAttribute('data-large-image');
var fGroups = KellyRecorderFilterPikabu.getPostGroups(false);
var pGroups = ['pikabu_post_preview'];
} else if (data.el.tagName == 'IMG' && data.el.getAttribute('data-src') && data.el.getAttribute('data-viewable')) {

var marker = '';
if (data.el.getAttribute('data-scrambler-offset') !== null) {
marker = '#nsfw' + data.el.getAttribute('data-scrambler-offset');
fGroups.push('pikabu_nsfw');
pGroups.push('pikabu_nsfw');
var dGroup = false;
if (KellyTools.getParentByTag(data.el, 'ARTICLE')) {
dGroup = 'pikabu_post_preview';
} else if (KellyTools.getParentByClass(data.el, 'comment')) {
dGroup = 'pikabu_comment';
}

if (fdata && pdata && pdata.indexOf(fdata) == -1) {
handler.addSingleSrc(data.item, data.el.getAttribute('data-src') + marker, 'addSrcFromAttributes-src', data.el, pGroups);
} else {
fGroups.push('pikabu_post_preview');
}
if (dGroup !== false) {

handler.addSingleSrc(data.item, data.el.getAttribute('data-large-image') + marker, 'addSrcFromAttributes-src', data.el, fGroups);

if (data.item.relatedSrc.length <= 0) return handler.addDriverAction.SKIP;
return handler.addDriverAction.ADD;
var pdata = data.el.getAttribute('data-src');
var fdata = data.el.getAttribute('data-large-image');
var fGroups = KellyRecorderFilterPikabu.getPostGroups(false);
var pGroups = [];
pGroups.push(dGroup);

var marker = '';
if (data.el.getAttribute('data-scrambler-offset') !== null) {
marker = '#nsfw' + data.el.getAttribute('data-scrambler-offset');
fGroups.push('pikabu_nsfw');
pGroups.push('pikabu_nsfw');
}

if (fdata && pdata && pdata.indexOf(fdata) == -1) { // large version exist (preview src != full src) -> add preview image to list
handler.addSingleSrc(data.item, data.el.getAttribute('data-src') + marker, 'addSrcFromAttributes-src', data.el, pGroups);
} else {
fGroups.push(dGroup);
}

handler.addSingleSrc(data.item, data.el.getAttribute('data-large-image') + marker, 'addSrcFromAttributes-src', data.el, fGroups);

if (data.item.relatedSrc.length <= 0) return handler.addDriverAction.SKIP;
return handler.addDriverAction.ADD;
}

}
}
Expand Down Expand Up @@ -123,7 +274,7 @@ KellyRecorderFilterPikabu.onStartRecord = function(handler, data) {
handler.additionCats = {

pikabu_comment : {name : 'Comment', color : '#b7dd99', selected : 110},
pikabu_post : {name : 'Post', color : '#b7dd99', selected : 110},
pikabu_post : {name : 'Post', color : '#b7dd99', selected : 111},
pikabu_post_preview : {name : 'Post preview', color : '#b7dd99', selected : 100},
pikabu_nsfw : {name : 'Encoded NSFW', color : '#ff0983'},
pikabu_post_video : {name : 'Post Video', color : '#218bea'},
Expand Down Expand Up @@ -222,8 +373,8 @@ KellyPageWatchdog.validators.push({
host : 'pikabu.ru',
patterns : [
['images/previews_comm', 'imageAny'],
['/post_img/', 'imageAny'],
['images/big_size_comm', 'imageOriginal'], ['_comm', 'pikabu_comment'], ]
['/post_img/', 'imageAny']
]
});

KellyPageWatchdog.filters.push(KellyRecorderFilterPikabu);
Loading

0 comments on commit d1f7373

Please sign in to comment.