Rule34Hentai Improved

Fixes stuff, adds like and favorite under images, highlights animated, compact header, etc.

目前為 2019-05-26 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Rule34Hentai Improved
// @namespace    http://tampermonkey.net/
// @version      0.4
// @icon         https://i.imgur.com/Aea35p5.png
// @description  Fixes stuff, adds like and favorite under images, highlights animated, compact header, etc.
// @author       Hentiedup
// @match        https://rule34hentai.net/post/*
// @require      https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    //=========Settings========//
    var autoplayVideos = true;
    var nextPrevImageWithArrowKeys = true;
    var CompactHeader = true;
    var hideEmptySections = true;
    //=========================//

    addGlobalStyle(`
		a.shm-thumb-link > img {
			padding: 0;
		}
		a.tagit-close {
			display: inline;
			padding: 0;
		}
		.custom-button {
			cursor: pointer;
			width: 35px;
			padding: 3px;
			margin: 0;
			border-radius: 20px;
		}
		.custom-button:hover {
			background-color: rgba(255,255,255,.75);
		}
		.customButtonText {
			position: relative;
			top: -5px;
			width: 41px;
			display: inline-block;
			text-align: center;
		}
		.customButtonDiv {
			display: inline-block;
			margin: 0;
			padding: 0;
			width: 41px;
		}

		#Uploadhead > .blockbody > .mini_upload > form > ul {
			width: 100%;
			margin: 0;
			resize: vertical;
		}
	`);

    if(CompactHeader)
        addGlobalStyle(`
			header {margin: 0; padding: 0;}
			header p {display: none;}
			header ul.ui-widget {
				margin: 5px;
				display: inline-block;
				vertical-align: middle;
				box-sizing: border-box;
				width: calc(100% - 100px);
			}
			header form > input[value=Search],
			header form > input[value=Search]:visited {
				vertical-align: middle;
				height: 36px;
				border-radius: 8px;
				background-color: #dec4a0;
				border-color: #725327;
				font-weight: 700;
				cursor: pointer;
			}
			header form > input[value=Search]:hover,
			header form > input[value=Search]:active {
				background-color: #dabc92;
			}
			#header h1 {font-size: 14px;}
			#header img.wp-image-67962 {
				height: 50px;
				width: auto;
			}
			#header img.wp-image-69454 {
				display: none;
			}
			#header td > center > ul {margin: 2px 0 0 0;}

			#Uploadhead > .blockbody > .mini_upload > small,
			#Uploadhead > .blockbody > .mini_upload > form > ul,
			#Uploadhead > .blockbody > .mini_upload > form > input[type=submit]
			{
				display: none;
			}

			#Loginhead > .blockbody {
				display: none;
			}
			#Loginhead > h3 {
				cursor: pointer;
			}
		`);

    setTimeout(function(){
        if(nextPrevImageWithArrowKeys) {
            var currentImage = window.location.href;
            if(currentImage.includes("/post/view/"))
                currentImage = parseInt(currentImage.split("/post/view/")[1], 10);
            else
                currentImage = null;
        }

        if(autoplayVideos) {
            $("#video-id_fluid_state_button").click();
            $("body").click(); //remove focus from player
        }

        $("a.shm-thumb-link > img[title*='// webm'], a.shm-thumb-link > img[title*='// mp4'], a.shm-thumb-link > img[title*='// gif']").attr("style", "border: solid 2px #fb2ccc !important; box-shadow: 0 0 5px 1px red;");

        let insertHTML = `<div class="customButtonDiv"><img id="like-butt" class="custom-button" src="https://i.imgur.com/Kh1HzGr.png" alt="like"><span class="customButtonText">` +
            $("#Image_Scoreleft > .blockbody").text().trim().replace(/[^0-9]/g, "") +
            `</span></div><div class="customButtonDiv"><img id="favorite-butt" class="custom-button" src="https://i.imgur.com/dTpBrIj.png" alt="favorite"><span class="customButtonText">` +
            $("#Favorited_Byleft > .blockbody").text().split(":")[0].trim().replace(/[^0-9]/g, "") + `</span></div>`;

        $(".image_info").parent().parent().prepend(insertHTML);
        $("#like-butt").click(function() {
            $("#Image_Scoreleft form input[value='Vote Up']").click();
        });
        $("#favorite-butt").click(function() {
            $("#Image_Controlsleft form input[value='Favorite']").click();
        });

        if(nextPrevImageWithArrowKeys && currentImage) {
            $("body").keyup(function(event){
                console.log("keypress");
                if(event.which == 39) {
                    ChangeImage(currentImage);
                }
                else if(event.which == 37) {
                    ChangeImage(currentImage, false);
                }
            });
        }

        if(hideEmptySections) {
            $("article > section > .blockbody").each(function(){
                if($(this).find("*:visible").not("p:empty").length == 0)
                    $(this).parent().hide();
            });
        }

        if(CompactHeader)
        {
            $("#Uploadhead #data0").change(function(){
                $("#Uploadhead > .blockbody > .mini_upload > small, #Uploadhead > .blockbody > .mini_upload > form > ul, #Uploadhead > .blockbody > .mini_upload > form > input[type=submit]").show(100);
            });

            $("#Loginhead > h3").click(function(){
                $(this).next(".blockbody").toggle(100);
            });
        }

    }, 200);

    function addGlobalStyle(css) {
        var head, style;
        head = document.getElementsByTagName('head')[0];
        if (!head) { return; }
        style = document.createElement('style');
        style.type = 'text/css';
        style.innerHTML = css;
        head.appendChild(style);
    }
    function ChangeImage(currentImg, next = true) {
        window.open("https://rule34hentai.net/post/view/" + (currentImg+(next ? 1 : -1)) + "","_self");
    }
})();