Sankaku Channel Access Rights

Access blocked images on Sankaku Channel

Fra og med 12.10.2020. Se den nyeste version.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

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

(function() {
    'use strict';

function unblockThumbs(target) {
    let blocked = [];
    let thumbs = target.querySelectorAll("span.thumb");
    for (let i = 0; i < thumbs.length; i++) {
        let link = thumbs[i].firstElementChild;
        if (link && link.href == "https://get.sankaku.plus/") {
            let id = thumbs[i].id.replace("p","");
            link.href = "/post/show/" + id;
            blocked.push(id);
        }
    }
    for (let i = 0; i < blocked.length; i++) {
        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.preview_width > 150 || data.preview_height > 150) {
                scale = 150 / Math.max(data.preview_width, data.preview_height);
            }
            let img = document.getElementById("p" + blocked[i]).getElementsByTagName("img")[0];
            img.width = data.preview_width * scale;
            img.height = data.preview_height * scale;
            img.src = data.preview_url;

            let title = "";
            for (let j = 0; j < data.tags.length; j++) {
                title += data.tags[j].name_en + " ";
            }
            //TODO: other info in title
            img.title = title;
        });
        oReq.open("GET", "https://capi-v2.sankakucomplex.com/posts?lang=en&page=1&limit=1&tags=id_range:" + blocked[i]);
        oReq.send();
    }
}

function unblockLarge(content) {
    content.innerHTML = "";
    let id = document.getElementById("post-view").firstElementChild.textContent;
    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 = document.createElement("img");
            img.width = data.sample_width * scale;
            img.height = data.sample_height * scale;
            img.src = data.sample_url;

            let full = document.createElement("a");
            full.href = data.file_url;
            full.target = "_blank";
            full.appendChild(img);
            content.appendChild(full);
        });
        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);
}

})();