Scan to open on your phone
Point a camera at the QR code - it opens this exact paste, no app needed.
https://codepastes.com/zzgrs3c16efh7qp2Movie_CrewJavaScript
(function () {
'use strict';
if (window.movie_crew_plugin_v349) return;
window.movie_crew_plugin_v349 = true;
window.movie_crew_plugin = true;
var COMPONENT = 'movie_crew_v2';
var STYLE_ID = 'movie-crew-v2-style';
var TXT = {
uk: {
row: 'Знімальна група', loading: 'Завантаження…',
fail: 'Не вдалося завантажити дані', empty: 'Дані про знімальну групу відсутні',
episodes: 'еп.'
},
ru: {
row: 'Съёмочная группа', loading: 'Загрузка…',
fail: 'Не удалось загрузить данные', empty: 'Данные о съёмочной группе отсутствуют',
episodes: 'эп.'
},
en: {
row: 'Crew', loading: 'Loading…',
fail: 'Could not load data', empty: 'No crew data available',
episodes: 'eps.'
}
};
var DEPT_ORDER = [
'Directing', 'Writing', 'Production', 'Camera', 'Editing', 'Sound',
'Art', 'Costume & Make-Up', 'Lighting', 'Visual Effects', 'Crew', 'Actors'
];
var DEPT_LABELS = {
uk: {
Directing: 'Режисура', Writing: 'Сценарій', Production: 'Виробництво',
Camera: 'Операторська робота', Editing: 'Монтаж', Sound: 'Звук',
Art: 'Художній відділ', 'Costume & Make-Up': 'Костюми та грим',
Lighting: 'Освітлення', 'Visual Effects': 'Візуальні ефекти',
Crew: 'Знімальна група', Actors: 'Актори'
},
ru: {
Directing: 'Режиссура', Writing: 'Сценарий', Production: 'Производство',
Camera: 'Операторская работа', Editing: 'Монтаж', Sound: 'Звук',
Art: 'Художественный отдел', 'Costume & Make-Up': 'Костюмы и грим',
Lighting: 'Освещение', 'Visual Effects': 'Визуальные эффекты',
Crew: 'Съёмочная группа', Actors: 'Актёры'
},
en: {}
};
var ICON = '<img src="https://svgsilh.com/svg/1300107.svg" alt="" ' +
'class="movie-crew-v2-row__image">';
var PLACEHOLDER = '<svg width="100%" height="100%" viewBox="0 0 100 100" aria-hidden="true">' +
'<rect width="100" height="100" fill="#25252b"></rect>' +
'<circle cx="50" cy="38" r="18" fill="#45454d"></circle>' +
'<ellipse cx="50" cy="88" rx="30" ry="22" fill="#45454d"></ellipse></svg>';
function lang() {
var value = 'uk';
try {
value = Lampa.Storage.get('language', 'uk') || 'uk';
} catch (e) {}
if (value === 'uk') return 'uk';
if (value === 'ru' || value === 'be') return 'ru';
return 'en';
}
function t(key) {
return TXT[lang()][key] || TXT.en[key] || key;
}
function deptLabel(department) {
var labels = DEPT_LABELS[lang()] || {};
return labels[department] || department;
}
function addStyle() {
if ($('#' + STYLE_ID).length) return;
$('head').append(
'<style id="' + STYLE_ID + '">' +
/* Crew button on the movie card */
'.movie-crew-v2-row .items-line__title{' +
'display:inline-flex;align-items:center;gap:.55em;cursor:pointer;' +
'padding:.48em .85em;border-radius:1.4em;' +
'background:rgba(0,0,0,.20);transition:background .2s ease;' +
'}' +
'.movie-crew-v2-row__icon{' +
'display:inline-flex;align-items:center;justify-content:center;' +
'flex:0 0 auto;width:1.25em;height:1.25em;' +
'}' +
'.movie-crew-v2-row__image{' +
'display:block;width:1.2em;height:1.2em;object-fit:contain;' +
'filter:brightness(0) invert(1);' +
'}' +
'.movie-crew-v2-row .items-line__head.focus .items-line__title,' +
'.movie-crew-v2-row .items-line__head:hover .items-line__title{' +
'background:rgba(255,255,255,.16);text-decoration:underline;' +
'}' +
/* Full-screen crew Activity content */
'.movie-crew-v2{' +
'width:100%;height:100%;min-height:0;box-sizing:border-box;' +
'display:block;overflow:hidden;background:#15151a;color:#fff;' +
'}' +
'.movie-crew-v2 *{box-sizing:border-box;}' +
'.movie-crew-v2__body{' +
'position:relative;width:100%;height:100%;min-height:0;' +
'overflow-y:auto;overflow-x:hidden;-webkit-overflow-scrolling:touch;' +
'padding:1.1em 2em 3em;' +
'}' +
'.movie-crew-v2__status{' +
'opacity:.72;padding:2.5em 1em;text-align:center;' +
'}' +
'.movie-crew-v2__section{margin:0 0 1.8em;}' +
'.movie-crew-v2__dept{' +
'font-size:1.12em;font-weight:600;margin:0 0 .85em;opacity:.9;' +
'}' +
'.movie-crew-v2__grid{' +
'display:flex;flex-wrap:wrap;align-items:flex-start;margin:-.35em;' +
'}' +
'.movie-crew-v2__card{' +
'width:9.2em;max-width:calc(50% - .7em);margin:.35em;' +
'min-width:0;cursor:pointer;' +
'}' +
'.movie-crew-v2__photo{' +
'width:100%;height:12em;overflow:hidden;' +
'border-radius:.55em;background:#25252b;' +
'}' +
'.movie-crew-v2__photo img{' +
'display:block;width:100%;height:100%;object-fit:cover;' +
'}' +
'.movie-crew-v2__card.focus .movie-crew-v2__photo{' +
'box-shadow:0 0 0 .2em #fff;' +
'}' +
'.movie-crew-v2__name{' +
'font-size:.94em;font-weight:600;line-height:1.25;' +
'margin-top:.48em;overflow-wrap:anywhere;' +
'}' +
'.movie-crew-v2__job{' +
'font-size:.78em;line-height:1.3;opacity:.65;' +
'margin-top:.22em;overflow-wrap:anywhere;' +
'}' +
'@media (max-width:600px){' +
'.movie-crew-v2__body{padding:1em 1em 2em;}' +
'.movie-crew-v2__card{width:7.3em;}' +
'.movie-crew-v2__photo{height:9.8em;}' +
'}' +
'</style>'
);
}
function isSeries(movie) {
return !!(movie && (
movie.media_type === 'tv' ||
movie.first_air_date ||
movie.number_of_seasons ||
movie.original_name
));
}
function normalizeTitle(value) {
return String(value || '')
.replace(/\s+/g, ' ')
.replace(/^\s+|\s+$/g, '')
.toLowerCase();
}
function isActorsTitle(value) {
var current = normalizeTitle(value);
var translated = '';
try {
translated = Lampa.Lang.translate('title_actors');
} catch (e) {}
if (current && current === normalizeTitle(translated)) return true;
return current === 'актори' ||
current === 'актеры' ||
current === 'actors' ||
current === 'cast' ||
current === 'в ролях';
}
function getMovieFromBuild(event) {
var movie = null;
try {
if (event.props && event.props.get) {
movie = event.props.get('movie');
}
} catch (e) {}
if (!movie && event.data && event.data.movie) {
movie = event.data.movie;
}
return movie;
}
function bindFire(element, handler) {
var lastFire = 0;
var fire = function () {
var now = new Date().getTime();
if (now - lastFire < 450) return;
lastFire = now;
handler();
};
element.on('hover:enter', fire);
if (element[0]) {
element[0].addEventListener('click', fire, false);
}
}
function openCrew(movie) {
if (!movie || !movie.id) return;
Lampa.Activity.push({
url: '',
component: COMPONENT,
movie: movie,
title: t('row')
});
}
/* Native row inserted into the vertical Main list */
function CrewNativeRow(movie) {
this.movie = movie;
this.components = [];
this.last = false;
this.html = $(
'<div class="items-line movie-crew-v2-row">' +
' <div class="items-line__head selector movie-crew-v2-row__head">' +
' <div class="items-line__title">' +
' <span class="movie-crew-v2-row__icon">' + ICON + '</span>' +
' <span class="movie-crew-v2-row__label"></span>' +
' </div>' +
' </div>' +
'</div>'
);
this.html.find('.movie-crew-v2-row__label').text(t('row'));
var self = this;
bindFire(this.html.find('.movie-crew-v2-row__head'), function () {
openCrew(self.movie);
});
}
CrewNativeRow.prototype.use = function (Module) {
var instance = typeof Module === 'function' ? new Module(this) : Module;
if (!instance || this.components.indexOf(instance) !== -1) return;
this.components.push(instance);
};
CrewNativeRow.prototype.emit = function (event) {
var args = Array.prototype.slice.call(arguments, 1);
var name = event.charAt(0).toUpperCase() + event.slice(1);
var only = null;
var i;
var handler;
for (i = 0; i < this.components.length; i++) {
handler = this.components[i]['only' + name];
if (typeof handler === 'function') {
only = handler;
}
}
if (only) return only.apply(this, args);
for (i = 0; i < this.components.length; i++) {
handler = this.components[i]['on' + name];
if (typeof handler === 'function') {
handler.apply(this, args);
}
}
};
CrewNativeRow.prototype.render = function (asElement) {
return asElement ? this.html[0] : this.html;
};
CrewNativeRow.prototype.toggle = function () {
var self = this;
var controller = {
link: this,
toggle: function () {
Lampa.Controller.collectionSet(self.html);
Lampa.Controller.collectionFocus(self.last || false, self.html);
self.emit('toggle');
},
right: function () {
if (window.Navigator && window.Navigator.canmove('right')) {
window.Navigator.move('right');
}
},
left: function () {
if (window.Navigator && window.Navigator.canmove('left')) {
window.Navigator.move('left');
} else {
self.emit('left');
}
},
down: function () {
self.emit('down');
},
up: function () {
self.emit('up');
},
back: function () {
self.emit('back');
}
};
this.emit('active');
this.emit('controller', controller);
Lampa.Controller.add('items_line', controller);
Lampa.Controller.toggle('items_line');
};
CrewNativeRow.prototype.destroy = function () {
this.html.remove();
this.components = [];
};
/* TMDB credits */
function requestCredits(path, onSuccess, onError) {
var tmdb = Lampa.Api &&
Lampa.Api.sources &&
Lampa.Api.sources.tmdb;
if (!tmdb || typeof tmdb.get !== 'function') {
onError();
return;
}
try {
tmdb.get(path, {}, function (json) {
onSuccess(json || {});
}, function () {
onError();
});
} catch (e) {
onError();
}
}
function fetchCrew(movie, onDone, onFail) {
if (!movie || !movie.id) {
onFail();
return;
}
if (isSeries(movie)) {
var tvPath = 'tv/' + movie.id + '/aggregate_credits';
requestCredits(tvPath, function (json) {
if (json.crew && json.crew.length) {
onDone(json.crew, true);
} else {
requestCredits('tv/' + movie.id + '/credits', function (fallback) {
onDone((fallback && fallback.crew) || [], false);
}, onFail);
}
}, function () {
requestCredits('tv/' + movie.id + '/credits', function (fallback) {
onDone((fallback && fallback.crew) || [], false);
}, onFail);
});
} else {
requestCredits('movie/' + movie.id + '/credits', function (json) {
onDone((json && json.crew) || [], false);
}, onFail);
}
}
function makeJobs(person, aggregate) {
var jobs = [];
var source = person.jobs && person.jobs.length ? person.jobs : null;
var i;
var role;
var label;
if (source) {
for (i = 0; i < source.length; i++) {
role = source[i];
if (typeof role === 'string') {
label = role;
} else {
label = role && role.job ? role.job : '';
if (aggregate && role && role.episode_count) {
label += ' (' + role.episode_count + ' ' + t('episodes') + ')';
}
}
if (label && jobs.indexOf(label) === -1) {
jobs.push(label);
}
}
}
if (!jobs.length && person.job) jobs.push(person.job);
if (!jobs.length && person.department) jobs.push(person.department);
return jobs;
}
function groupByDepartment(crew, aggregate) {
var groups = {};
var seenOrder = [];
var i;
var person;
var department;
var bucket;
var existing;
var j;
var jobs;
var k;
var order;
var result = [];
for (i = 0; i < crew.length; i++) {
person = crew[i] || {};
if (!person.id) continue;
department = person.department ||
person.known_for_department ||
'Crew';
if (!groups[department]) {
groups[department] = [];
seenOrder.push(department);
}
bucket = groups[department];
existing = null;
for (j = 0; j < bucket.length; j++) {
if (String(bucket[j].id) === String(person.id)) {
existing = bucket[j];
break;
}
}
jobs = makeJobs(person, aggregate);
if (existing) {
for (k = 0; k < jobs.length; k++) {
if (existing.jobs.indexOf(jobs[k]) === -1) {
existing.jobs.push(jobs[k]);
}
}
} else {
bucket.push({
id: person.id,
name: person.name || '',
profile_path: person.profile_path || '',
known_for_department: person.known_for_department || department,
jobs: jobs,
raw: person
});
}
}
order = DEPT_ORDER.filter(function (name) {
return !!groups[name];
});
for (i = 0; i < seenOrder.length; i++) {
if (order.indexOf(seenOrder[i]) === -1) {
order.push(seenOrder[i]);
}
}
for (i = 0; i < order.length; i++) {
department = order[i];
result.push({
key: department,
title: deptLabel(department),
items: groups[department]
});
}
return result;
}
/* Full-screen crew Activity */
function CrewComponent(object) {
this.object = object || {};
this.movie = this.object.movie;
this.destroyed = false;
this.groups = [];
}
CrewComponent.prototype.create = function () {
addStyle();
this.html = $(
'<div class="movie-crew-v2">' +
' <div class="movie-crew-v2__body">' +
' <div class="movie-crew-v2__status"></div>' +
' </div>' +
'</div>'
);
this.html.find('.movie-crew-v2__status').text(t('loading'));
this.load();
return this.html;
};
CrewComponent.prototype.load = function () {
var self = this;
if (!this.movie || !this.movie.id) {
this.showStatus(t('fail'));
return;
}
fetchCrew(this.movie, function (crew, aggregate) {
if (self.destroyed) return;
self.groups = groupByDepartment(crew || [], !!aggregate);
self.renderGroups();
}, function () {
if (!self.destroyed) {
self.showStatus(t('fail'));
}
});
};
CrewComponent.prototype.showStatus = function (message) {
if (!this.html) return;
var body = this.html.find('.movie-crew-v2__body');
body.empty();
$('<div class="movie-crew-v2__status"></div>')
.text(message)
.appendTo(body);
};
CrewComponent.prototype.scrollCardIntoView = function (element) {
var body = this.html &&
this.html.find('.movie-crew-v2__body')[0];
if (!body || !element || !element.getBoundingClientRect) return;
var itemRect = element.getBoundingClientRect();
var bodyRect = body.getBoundingClientRect();
if (itemRect.bottom > bodyRect.bottom) {
body.scrollTop += itemRect.bottom - bodyRect.bottom + 20;
} else if (itemRect.top < bodyRect.top) {
body.scrollTop -= bodyRect.top - itemRect.top + 20;
}
};
CrewComponent.prototype.renderGroups = function () {
var self = this;
var body = this.html.find('.movie-crew-v2__body');
body.empty();
var total = 0;
var i;
for (i = 0; i < this.groups.length; i++) {
total += this.groups[i].items.length;
}
if (!total) {
this.showStatus(t('empty'));
return;
}
this.groups.forEach(function (group) {
if (!group.items || !group.items.length) return;
var section = $('<section class="movie-crew-v2__section"></section>');
$('<div class="movie-crew-v2__dept"></div>')
.text(group.title + ' (' + group.items.length + ')')
.appendTo(section);
var grid = $('<div class="movie-crew-v2__grid"></div>');
group.items.forEach(function (person) {
var card = $(
'<div class="movie-crew-v2__card selector" tabindex="0">' +
' <div class="movie-crew-v2__photo"></div>' +
' <div class="movie-crew-v2__name"></div>' +
' <div class="movie-crew-v2__job"></div>' +
'</div>'
);
var photo = card.find('.movie-crew-v2__photo');
if (person.profile_path) {
var image = $('<img/>');
image.attr(
'src',
'https://image.tmdb.org/t/p/w185' + person.profile_path
);
image.attr('alt', person.name || '');
photo.append(image);
} else {
photo.html(PLACEHOLDER);
}
card.find('.movie-crew-v2__name').text(person.name || '');
card.find('.movie-crew-v2__job').text(person.jobs.join(', '));
bindFire(card, function () {
try {
Lampa.Router.call('actor', person.raw || person);
} catch (e) {}
});
card.on('hover:focus', function () {
self.scrollCardIntoView(card[0]);
});
grid.append(card);
});
section.append(grid);
body.append(section);
});
try {
if (Lampa.Controller.enabled() &&
Lampa.Controller.enabled().name === 'content') {
Lampa.Controller.collectionSet(this.html);
Lampa.Controller.collectionFocus(false, this.html);
}
} catch (e) {}
};
CrewComponent.prototype.render = function (asElement) {
return asElement ? this.html[0] : this.html;
};
CrewComponent.prototype.start = function () {
var self = this;
Lampa.Controller.add('content', {
toggle: function () {
Lampa.Controller.collectionSet(self.html);
Lampa.Controller.collectionFocus(false, self.html);
},
back: function () {
Lampa.Activity.backward();
},
up: function () {
if (window.Navigator && window.Navigator.canmove('up')) {
window.Navigator.move('up');
} else {
Lampa.Controller.toggle('head');
}
},
down: function () {
if (window.Navigator) window.Navigator.move('down');
},
left: function () {
if (window.Navigator && window.Navigator.canmove('left')) {
window.Navigator.move('left');
} else {
Lampa.Controller.toggle('menu');
}
},
right: function () {
if (window.Navigator) window.Navigator.move('right');
}
});
Lampa.Controller.toggle('content');
};
CrewComponent.prototype.pause = function () {};
CrewComponent.prototype.stop = function () {};
CrewComponent.prototype.destroy = function () {
this.destroyed = true;
if (this.html) {
this.html.remove();
}
};
/* Integration with the native Full card */
function onFullBuild(event) {
if (!event || event.type !== 'build' || event.name !== 'persons') return;
if (!event.data || !isActorsTitle(event.data.title)) return;
if (!event.link || typeof event.link.emit !== 'function') return;
if (event.link.__movieCrewV2Added) return;
var movie = getMovieFromBuild(event);
if (!movie || !movie.id) return;
var row = new CrewNativeRow(movie);
try {
event.link.emit('append', row);
event.link.__movieCrewV2Added = true;
} catch (error) {
try {
console.log('[MovieCrew] Could not append native row', error);
} catch (e) {}
}
}
function start() {
if (window.movie_crew_plugin_v2_started) return;
window.movie_crew_plugin_v2_started = true;
addStyle();
Lampa.Component.add(COMPONENT, CrewComponent);
Lampa.Listener.follow('full', onFullBuild);
}
if (window.appready) {
start();
} else {
Lampa.Listener.follow('app', function (event) {
if (event && event.type === 'ready') {
start();
}
});
}
})();23,868 chars · codepastes.com