Skip to content

Commit

Permalink
Merge pull request #1215 from GrosPoulet/master
Browse files Browse the repository at this point in the history
New plug-in for: Itaku.ee
  • Loading branch information
GrosPoulet authored Aug 15, 2023
2 parents ac79f61 + e1d776f commit 95ca049
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 0 deletions.
1 change: 1 addition & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"plugins/imgur_a.js",
"plugins/instagram_a.js",
"plugins/ipboard_a.js",
"plugins/itaku_a.js",
"plugins/kick_a.js",
"plugins/mediawiki_a.js",
"plugins/medium_a.js",
Expand Down
111 changes: 111 additions & 0 deletions plugins/itaku_a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
var hoverZoomPlugins = hoverZoomPlugins || [];
hoverZoomPlugins.push({
name:'itaku_a',
version:'1.0',
prepareImgLinks:function (callback) {
var name = this.name;
var res = [];

// image/video
// sample: https://itaku.ee/images/533225
// Itaku (img/video) id: 533225
$('a[href*="/images/"]').filter(function() { return (/itaku\.ee\/images\/\d+/.test($(this).prop('href'))) }).one('mouseover', function() {
const href = this.href;
var link = $(this);

const re = /itaku\.ee\/images\/(\d+)/;
m = href.match(re);
if (m == undefined) return;
const itakuId = m[1];

// reuse previous result
if (link.data().hoverZoomItakuId == itakuId) {
if (link.data().hoverZoomItakuUrl) {
link.data().hoverZoomSrc = link.data().hoverZoomItakuUrl;
link.data().hoverZoomCaption = link.data().hoverZoomItakuCaption;
}
return;
}

link.data().hoverZoomItakuId = itakuId;
link.data().hoverZoomItakuUrl = undefined;
link.data().hoverZoomItakuCaption = undefined;

chrome.runtime.sendMessage({action:'ajaxRequest',
method:'GET',
url:'https://itaku.ee/api/galleries/images/' + itakuId},
function (response) {
try {
const j = JSON.parse(response);
const itakuUrl = j.video?.video || j.image;
if (itakuUrl) {
link.data().hoverZoomSrc = link.data().hoverZoomItakuUrl = [itakuUrl];
link.data().hoverZoomCaption = link.data().hoverZoomItakuCaption = j.title;
callback(link, name);
hoverZoom.displayPicFromElement(link);
}
} catch {}
});
});

// commission
// sample: https://itaku.ee/commissions/1212
$('a[href*="/commissions/"]').filter(function() { return (/itaku\.ee\/commissions\/\d+/.test($(this).prop('href'))) }).one('mouseover', function() {
const href = this.href;
var link = $(this);

const re = /itaku\.ee\/commissions\/(\d+)/;
m = href.match(re);
if (m == undefined) return;
const itakuId = m[1];

// reuse previous result
if (link.data().hoverZoomItakuId == itakuId) {
if (link.data().hoverZoomItakuGallery) {
link.data().hoverZoomGallerySrc = link.data().hoverZoomItakuGallery;
link.data().hoverZoomGalleryCaption = link.data().hoverZoomItakuCaptions;
}
return;
}

link.data().hoverZoomItakuId = itakuId;
link.data().hoverZoomItakuGallery = undefined;
link.data().hoverZoomItakuCaptions = undefined;

chrome.runtime.sendMessage({action:'ajaxRequest',
method:'GET',
url:'https://itaku.ee/api/commissions/' + itakuId},
function (response) {
try {
const j = JSON.parse(response);
const images = j.reference_gallery_images.map(r => [r.image_xl]);
const captions = j.reference_gallery_images.map(r => r.title);
if (images) {
link.data().hoverZoomSrc = undefined;
link.data().hoverZoomGallerySrc = link.data().hoverZoomItakuGallery = images;
link.data().hoverZoomGalleryCaption = link.data().hoverZoomItakuCaptions = captions;
link.data().hoverZoomGalleryIndex = 0;
callback(link, name);
hoverZoom.displayPicFromElement(link);
}
} catch {}
});
});

// profile
hoverZoom.urlReplace(res,
'img[src*="itaku.ee/api/media/profile_pics/"]',
'/sm.',
'/md.'
);

// cover
hoverZoom.urlReplace(res,
'img[src*="itaku.ee/api/media/cover_pics/"]',
'/sm.',
'/lg.'
);

callback($(res), name);
}
});

0 comments on commit 95ca049

Please sign in to comment.