SCP Artwork Hub Show Image

Show Image For SCP Artwork Hub .

2022-01-05 يوللانغان نەشرى. ئەڭ يېڭى نەشرىنى كۆرۈش.

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==
// @namespace    https://greatest.deepsurf.us/zh-TW/users/142344-jasn-hr
// @name         SCP Artwork Hub Show Image
// @description  Show Image For SCP Artwork Hub .
// @copyright    2022, HrJasn (https://greatest.deepsurf.us/zh-TW/users/142344-jasn-hr)
// @license      GPL-3.0-or-later
// @version      1.1
// @icon         https://www.google.com/s2/favicons?domain=wikidot.com
// @include      http*://*scp*.wikidot.com/*art*
// @include      http://ko.scp-wiki.net/scp-artwork-hub-ko
// @grant        none
// ==/UserScript==

window.onload = function(){

    const ArtImageWindow = document.body.appendChild(document.createElement('img'));
    ArtImageWindow.style = 'position:fixed;right:5px;bottom:5px;border:0px;max-height:20%;max-width:20%;background-color:white;';
    ArtImageWindow.style.display = 'none';
    ArtImageWindow.addEventListener('mouseleave',function(e){
        ArtImageWindow.style.display = 'none';
        ArtImageWindow.style.right = '0px';
        ArtImageWindow.style.bottom = '0px';
        ArtImageWindow.src = '';
    });

    const loadImage = function(e){
        e.target.style.cursor = 'wait';
        let fetchURL = e.target.href;
        fetchURL = fetchURL.replace(/^(https?:\/\/[^\/]+\/adult:.*)$/,"$1/noredirect/true");
        fetch(fetchURL,{method:'GET',}).then(function(res){
            return res.text();
        }).then(function(resText){
            let parser = new DOMParser();
            let resDom = parser.parseFromString(resText,"text/html");
            let resDomBody = resDom.body;
            let ArtworkImage = resDomBody.querySelector('#page-content div.image-container img') ||
                resDomBody.querySelector('#page-content img.image:not([src="http://scp-jp.wikidot.com/local--files/nav:side/blank.png"]):not([src="http://scp-idn.wdfiles.com/local--files/shaun159-pixel-artpage/ball.jpg"])') ||
                resDomBody.querySelector('#page-content img.fillpg');
            let ArtworkImageSrc = ArtworkImage.src;
            ArtImageWindow.src = ArtworkImageSrc;
            let newright = window.innerWidth - e.clientX;
            let newbottom = window.innerHeight - e.clientY;
            ArtImageWindow.style.right = newright + 'px';
            ArtImageWindow.style.bottom = newbottom + 'px';
            ArtImageWindow.style.display = '';
            e.target.style.cursor = 'auto';
        });
    }

    const moveImage = function(e){
        let newright = window.innerWidth - e.clientX;
        let newbottom = window.innerHeight - e.clientY;
        ArtImageWindow.style.right = newright + 'px';
        ArtImageWindow.style.bottom = newbottom + 'px';
    }

    const takeoutImage = function(e){
        ArtImageWindow.style.display = 'none';
        ArtImageWindow.style.right = '0px';
        ArtImageWindow.style.bottom = '0px';
        ArtImageWindow.src = '';
    }

    let divContents = [
        document.querySelectorAll('div.content-type-description tr'),
        document.querySelectorAll('div.content-type-description-2 tr')
    ]
    let divContentTypeDescriptionTrs = divContents.reduce(function(a, b){return a.length > b.length ? a : b ;});
    for(let i=0;i<divContentTypeDescriptionTrs.length;i++){
        let artworkLinkOBJ = divContentTypeDescriptionTrs[i].querySelector('td:first-child a');
        console.log(artworkLinkOBJ);
        if(artworkLinkOBJ){
            artworkLinkOBJ.addEventListener('mouseenter',loadImage);
            artworkLinkOBJ.addEventListener('mousemove',moveImage);
            artworkLinkOBJ.addEventListener('mouseleave',takeoutImage);
        }
    }

}