Sankaku Channel Access Rights

Access blocked images on Sankaku Channel (does not support thumbnails)

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         Sankaku Channel Access Rights
// @namespace    http://tampermonkey.net/
// @version      20210312
// @description  Access blocked images on Sankaku Channel (does not support thumbnails)
// @author       Couchy (original author) & WujekTadek (modified an existing script)
// @updated by   WujekTadek
// @match        https://chan.sankakucomplex.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function unblockThumbs(target) {
        const thumbs = target.querySelectorAll("span.thumb");
        for (const thumb of thumbs) {
            var thumbnailReadyLink //DAS IST MEIN

            const link = thumb.firstElementChild;
            if (!link || link.href != "https://get.sankaku.plus/") {
                continue;
            }
            const id = thumb.id.substring(1); //READS ALL IMG ID'S CURRENTLY ON WEBPAGE
            link.href = `/post/show/${id}`;
            link.removeAttribute("target");
            const oReq = new XMLHttpRequest(); 
            oReq.addEventListener("load", function(){
                //console.log(oReq.responseText);
                const data = JSON.parse(oReq.responseText)[0];
                //alert(data); 
                //console.log(data);
                let scale = 1;
                if (data.preview_width > 150 || data.preview_height > 150) {
                    scale = 1 / Math.max(data.preview_width, data.preview_height);
                }

                const previewElem = thumb.children[0].children[0];
                //console.log(previewElem);
                previewElem.width = 150;
                previewElem.height = 150;
                previewElem.src = "https://chan.sankakucomplex.com/post/show/"+id+"";
                //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 = ""; //this
        const id = document.querySelector('meta[property~="og:image"][content]').content.slice(5);
        var properLink = "//s.s";
        properLink += id;
        window.open(properLink,"_self");
    }

    if (document.querySelector("span.thumb")) {
        unblockThumbs(document);
    }

    const content = document.getElementById("post-content");
    if (content && content.querySelector(".post-content-notification")) {
        unblockLarge(content);
    }
    //idk what that stuff below does --WujekTadek
    //and now it makes everything work again, while before it had to be commented...
    const list = document.getElementById("post-list");
    if (list) {
        const callback = function (mutations){
            for (const mutation of mutations) {
                if (mutation.addedNodes.length > 0 && mutation.addedNodes[0].className == "content-page") {
                    console.log(mutation.addedNodes[0]);
                    unblockThumbs(mutation.addedNodes[0]);
                }
            }
        };
        const observer = new MutationObserver(callback);
        observer.observe(list, {childList: true, subtree: true});
    }

    // Fix Sankaku's shit
    /*
var parts = /(.*) Rating:(\w)\w+ Score:(\S+) Size:(\d+)x(\d+) User:(.*)/.exec(title);
				o.tags = parts[1];
				o.rating = parts[2].toLowerCase();
				o.score = parseFloat(parts[3]);
				o.width = parseInt(parts[4]);
				o.height = parseInt(parts[5]);
				o.author = parts[6];
*/
    /*
const realExec = RegExp.prototype.exec;
RegExp.prototype.exec = function(str){
    let result = realExec.apply(this, [str]);
    if (!result && this.source.indexOf("Rating") > -1) {
        result = ["","","e","0","0","0",""];
    }
    return result;
};*/

})();