Created
December 18, 2018 12:20
-
-
Save extensionsapp/570ffb1b67dd324bf0967e6bcbd74ad2 to your computer and use it in GitHub Desktop.
Кнопка автозаполнения информации о фильме в CinemaPress ACMS.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name cinemapress | |
// @description Кнопка автозаполнения информации о фильме в CinemaPress ACMS. | |
// @author ExtensionsApp | |
// @homepageURL https://cinemapress.org/ | |
// @supportURL https://enota.club/ | |
// @icon https://avatars3.githubusercontent.com/u/16612433?s=200 | |
// @license MIT | |
// @version 2.0.19 | |
// @run-at document-end | |
// @include http://*/*/movies?kp_id=* | |
// @include https://*/*/movies?kp_id=* | |
// @grant GM_setValue | |
// @grant GM_getValue | |
// @grant GM_xmlhttpRequest | |
// ==/UserScript== | |
let newItem = document.createElement('a'); | |
newItem.setAttribute('class', 'btn addInformation'); | |
newItem.setAttribute('href', 'javascript:void(0)'); | |
let newText = document.createTextNode(' Заполнить информацию'); | |
let newIcon = document.createElement('span'); | |
newIcon.setAttribute('class', 'fa fa-file-text-o'); | |
newItem.appendChild(newIcon); | |
newItem.appendChild(newText); | |
let right = document.querySelector('.window > .actionbar > .pull-right > a'); | |
right.parentNode.insertBefore(newItem, right); | |
let el = document.querySelector('.addInformation'); | |
el.addEventListener('click', () => { | |
document.querySelector('.addInformation > span').setAttribute('class', 'fa fa-spinner fa-spin'); | |
let kp_id = document.querySelector('[name="movie.kp_id"]').value; | |
if (!kp_id) { | |
document.querySelector('.addInformation > span').setAttribute('class', 'fa fa-bug'); | |
console.log('ID КиноПоиск не заполнено!'); | |
return; | |
} | |
GM_xmlhttpRequest({ | |
method: 'GET', | |
url: 'https://streamguard.cc/api/videos.json?&api_token=6eb82f15e2d7c6cbb2fdcebd05a197a2&kinopoisk_id=' + kp_id, | |
onload: function (response) { | |
if (response.readyState === 4 && response.status === 200) { | |
let res = (response && response.responseText) ? JSON.parse(response.responseText) : {}; | |
if (!res || res.error || !res.length) { | |
document.querySelector('.addInformation > span').setAttribute('class', 'fa fa-bug'); | |
console.log('Нет информации о фильме!'); | |
return; | |
} | |
let m = {}; | |
for (let i = 0; i < res.length; i++) { | |
if (res[i].material_data && !(/укр/i.test(res[i].translator)) && !m.material_data) { | |
m = res[i]; | |
} | |
} | |
if (!m.material_data) { | |
document.querySelector('.addInformation > span').setAttribute('class', 'fa fa-bug'); | |
console.log('Нет информации о фильме!'); | |
return; | |
} | |
if (m.title_ru) { | |
document.querySelector('[name="movie.title_ru"]').value = m.title_ru; | |
} | |
if (m.title_en) { | |
document.querySelector('[name="movie.title_en"]').value = m.title_en; | |
} | |
if (m.title_ru && m.title_ru.indexOf('(видео)')+1) { | |
document.querySelector('[name="movie.type"]').value = 2; | |
document.querySelector('[name="movie.title_ru"]').value = (m.title_ru.split('(')[0]).trim(); | |
} | |
else if (m.title_ru && m.title_ru.indexOf('(ТВ)')+1) { | |
document.querySelector('[name="movie.type"]').value = 3; | |
document.querySelector('[name="movie.title_ru"]').value = (m.title_ru.split('(')[0]).trim(); | |
} | |
else if (m.type) { | |
document.querySelector('[name="movie.type"]').value = m.type === 'serial' ? 1 : 0; | |
} | |
if (m.translator) { | |
document.querySelector('[name="movie.translate"]').value = m.translator; | |
} | |
if (m.source_type) { | |
document.querySelector('[name="movie.quality"]').value = m.source_type; | |
} | |
if (m.material_data.year) { | |
document.querySelector('[name="movie.year"]').value = m.material_data.year; | |
} | |
if (m.material_data.description && | |
document.querySelector('[name="movie.description"]').value.length < 900) { | |
document.querySelector('[name="movie.description"]').value = m.material_data.description; | |
} | |
if (m.material_data.countries && m.material_data.countries.length) { | |
document.querySelector('[name="movie.country"]').value = m.material_data.countries.join(','); | |
} | |
if (m.material_data.genres && m.material_data.genres.length) { | |
document.querySelector('[name="movie.genre"]').value = m.material_data.genres.join(','); | |
} | |
if (m.material_data.actors && m.material_data.actors.length) { | |
document.querySelector('[name="movie.actor"]').value = m.material_data.actors.join(','); | |
} | |
if (m.material_data.directors && m.material_data.directors.length) { | |
document.querySelector('[name="movie.director"]').value = m.material_data.directors.join(','); | |
} | |
if (m.material_data.kinopoisk_rating) { | |
document.querySelector('[name="movie.kp_rating"]').value = parseInt(m.material_data.kinopoisk_rating*10); | |
} | |
if (m.material_data.kinopoisk_votes) { | |
document.querySelector('[name="movie.kp_vote"]').value = m.material_data.kinopoisk_votes; | |
} | |
if (m.material_data.imdb_rating) { | |
document.querySelector('[name="movie.imdb_rating"]').value = parseInt(m.material_data.imdb_rating*10); | |
} | |
if (m.material_data.imdb_votes) { | |
document.querySelector('[name="movie.imdb_vote"]').value = m.material_data.imdb_votes; | |
} | |
document.querySelector('.addInformation > span').setAttribute('class', 'fa fa-file-text-o'); | |
} | |
else { | |
document.querySelector('.addInformation > span').setAttribute('class', 'fa fa-bug'); | |
console.log('Нет информации о фильме!'); | |
} | |
} | |
}); | |
}, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment