Sankaku Channel Access Rights

Access blocked images on Sankaku Channel

2020-10-12 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==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);
}

})();