Sankaku Channel Access Rights

Access blocked images on Sankaku Channel

Από την 13/10/2020. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Sankaku Channel Access Rights
// @namespace    http://tampermonkey.net/
// @version      20201013
// @description  Access blocked images on Sankaku Channel
// @author       Couchy
// @match        https://chan.sankakucomplex.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

function unblockThumbs(target) {
    let thumbs = target.querySelectorAll("span.thumb");
    for (let thumb of thumbs) {
        let link = thumb.firstElementChild;
        if (!link || link.href != "https://get.sankaku.plus/") {
            continue;
        }
        let id = thumb.id.replace("p","");
        link.href = `/post/show/${id}`;
        link.removeAttribute("target");
        let oReq = new XMLHttpRequest();
        //console.log(previewElem);
        oReq.addEventListener("load", function(){
            //console.log(oReq.responseText);
            let data = JSON.parse(oReq.responseText)[0];
            //console.log(data);
            let scale = 1;
            if (data.preview_width > 150 || data.preview_height > 150) {
                scale = 150 / Math.max(data.preview_width, data.preview_height);
            }

            let previewElem = thumb.children[0].children[0];
            //console.log(previewElem);
            previewElem.width = data.preview_width * scale;
            previewElem.height = data.preview_height * scale;
            previewElem.src = data.preview_url;

            let title = "";
            for (let tag of data.tags) {
                title += `${tag.name_en} `;
            }
            //TODO: other info in title
            previewElem.title = title;
        });
        oReq.open("GET", `https://capi-v2.sankakucomplex.com/posts?lang=en&page=1&limit=1&tags=id_range:${id}`);
        oReq.send();
    }
}

function unblockLarge(content) {
    content.innerHTML = "";
    let id = document.querySelector('meta[property~="og:title"][content]').content.slice(5);
    let oReq = new XMLHttpRequest();
        oReq.addEventListener("load", function(){
            //console.log(oReq.responseText);
            let data = JSON.parse(oReq.responseText)[0];
            //console.log(data);
            let scale = 1;
            if (data.sample_width > 1000 || data.sample_height > 1000) {
                scale = 1000 / Math.max(data.sample_width, data.sample_height);
            }

            let img;
            if (!data.file_type) { //Flash
                img = document.createElement("object");
                let embed = document.createElement("embed");
                embed.src = data.sample_url;
                embed.width = data.sample_width * scale;
                embed.height = data.sample_height * scale;
                img.appendChild(embed);
            }
            else if (data.file_type.startsWith("image")){
                img = document.createElement("img");
                img.src = data.sample_url;
            }
            else if (data.file_type.startsWith("video")) {
                img = document.createElement("video");
                img.controls = true;
                img.autoplay = false;
                img.src = data.sample_url;
            }

            if (img) {
                img.width = data.sample_width * scale;
                img.height = data.sample_height * scale;

                let full = document.createElement("a");
                full.href = data.file_url;
                full.target = "_blank";
                full.appendChild(img);
                content.appendChild(full);
            }
            else {
                console.log(`Unhandled file type: ${data.file_type}`);
            }
        });
        //console.log(`querying id: ${id}`);
        oReq.open("GET", `https://capi-v2.sankakucomplex.com/posts?lang=en&page=1&limit=1&tags=id_range:${id}`);
        oReq.send();
}

let content = document.getElementById("post-content");
if (content && content.innerHTML.indexOf("access rights") > 0) {
    unblockLarge(content);
}
if (document.querySelector("span.thumb")) {
    unblockThumbs(document);
}

})();