ShikiToAnime365

Редирект-кнопка для Шикимори, которая перенаправляет на Anime365

目前為 2021-11-12 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name            ShikiToAnime365
// @description     Редирект-кнопка для Шикимори, которая перенаправляет на Anime365
// @description:en  Redirect button for Shikimori that redirects to Anime 365
// @namespace       https://shikimori.one/animes
// @include         /^https?://shikimori\.o(?:ne|rg)/(.*)$/
// @connect         smotret-anime.online
// @grant           GM_xmlhttpRequest
// @compatible      chrome
// @icon            https://www.google.com/s2/favicons?domain=shikimori.one
// @author          Jogeer
// @license         MIT
// @version         1.3
// @contributionURL https://paypal.me/Jogeer
// @contributionAmount 5
// ==/UserScript==

var debug = true
var regexUrl = new RegExp(/^https?:\/\/shikimori\.o(?:ne|rg)\/animes\/[A-z]?(\d*)-(.*)$/mg)
var apiUrl = 'https://smotret-anime.online/api/'

function log(message) {
    if (!debug) {
        return
    }
    console.log('App: ' + message)
}

function addButton(link, data = '') {
    var dom = document.querySelector('.c-info-right')
    let elem = `<div class=\"watch-online\" id=\"anime365-inject\">
                    <div class=\"line\">
                        <a class=\"b-link_button dark\" href=\"${link}\" target=\"_blank\">Смотреть онлайн</a>
                    </div>
                    <div class=\"kind\">Anime 365 ${data}</div>
                </div>`
    dom.insertAdjacentHTML('beforeend', elem)
}

async function getApiData(shikimoriLink) {
    let matches = regexUrl.exec(shikimoriLink)

    await GM_xmlhttpRequest({
        method: 'GET',
        headers: { "Content-type": "application/x-www-form-urlencoded" },
        url: `${apiUrl}series?myAnimeListId=${matches[1]}`,
        data: `myAnimeListId=${matches[1]}`,
        onload: (e) => {
            log('Get response')
            let obj = JSON.parse(e.response).data[0]
            console.log(obj)

            // Логика обработки нахождения
            let cEp = 0
            obj.episodes.forEach(el => {el.episodeType === obj.type && el.isFirstUploaded ? cEp++ : null})

            log('Response parsed')
            addButton(obj.url, `[Eps:${cEp}]`)
            log('Button placed')
        }
    })
}

async function main() {
    var currentUrl = window.location.href
    if (!currentUrl.match(regexUrl)) {
        log('Not Passed')
        return
    }

    log('Send request')
    await getApiData(currentUrl)
}

function ready(func) {
    document.addEventListener('page:load', func)
    document.addEventListener('turbolinks:load', func)

    if (document.attachEvent ? document.readyState === "complete" : document.readyState !== "loading") {
        func()
    } else {
        document.addEventListener('DOMContentLoaded', func)
    }
}

ready(main)