Rule34Hentai Improved

Fixes stuff, adds like and favorite under images, highlights animated, makes the site more compact, etc.

Stan na 14-06-2019. Zobacz najnowsza wersja.

// ==UserScript==
// @name         Rule34Hentai Improved
// @namespace    http://tampermonkey.net/
// @version      0.5.3
// @icon         https://i.imgur.com/Aea35p5.png
// @description  Fixes stuff, adds like and favorite under images, highlights animated, makes the site more compact, 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========//
	/*       video/image       */
    var HighlightVideos = true;
    var AutoplayVideos = true;
    var StopHidingMyCursorOnVideo = true;
    var PauseVideoOnClick = true;
    var DownsizeToFit = true;
    var NextPrevWithArrowKeys = true;

	/*      Compact site       */
    var CompactHeader = true;
    var MinimizeHeaderFurtherAndShowOnHover = true;
    var HideEmptySections = true;
    var HideLog = true;
    var HideImageVideoHeader = true;

	/*      like/favorite      */
    var EnableLikeFavoriteButtonsBelowImage = true;
    var UseAJAXForLikeFavoriteButtons = 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;
			float: left;
		}

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

    if(StopHidingMyCursorOnVideo)
        addGlobalStyle(`#video-id { cursor: auto !important; }`);

    if(HideImageVideoHeader)
        addGlobalStyle(`#Imagemain > h3, #Videomain > h3 { display: none; }`);

	if(MinimizeHeaderFurtherAndShowOnHover) {
		addGlobalStyle(`
			header {
				overflow-y: hidden; height: 55px;
			}
			header:hover {height: auto;}
		`);

		if(DownsizeToFit) {
			addGlobalStyle(`
				header + nav + article #fluid_video_wrapper_video-id,
				header + nav + article #main_image {
					max-height: calc(90vh - 130px` + (HideImageVideoHeader ? ` + 41px` : ``) + `) !important; max-width: 100% !important;
				}

				header:hover + nav + article #fluid_video_wrapper_video-id,
				header:hover + nav + article #main_image {
					max-height: calc(90vh - 220px` + (HideImageVideoHeader ? ` + 41px` : ``) + `) !important; max-width: 100% !important;
				}
			`);
		}
	}

    if(!MinimizeHeaderFurtherAndShowOnHover && DownsizeToFit) {
        addGlobalStyle(`
		#fluid_video_wrapper_video-id, #main_image {
			max-height: calc(90vh - 220px` + (HideImageVideoHeader ? ` + 41px` : ``) + `) !important; max-width: 100% !important;
		}
		`);
    }

    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;
			}
		`);

    if(HideLog)
        addGlobalStyle(`b#flash { display: none; }`);

    setTimeout(function(){
        if(NextPrevWithArrowKeys) {
            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
        }

        if(PauseVideoOnClick) {
            $("#video-id").click(function(){
                $("#video-id_fluid_control_playpause").click();
            });
        }

        if(HighlightVideos)
            $("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;");

        //if logged in
        if($("#Loginhead").length == 0 && EnableLikeFavoriteButtonsBelowImage)
        {
            let insertHTML = `<div class="customButtonDiv"><img id="like-butt" class="custom-button" src="https://i.imgur.com/Kh1HzGr.png" alt="like"><span id="customLikeButtonText" 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 id="customFavButtonText" 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() {
                if(UseAJAXForLikeFavoriteButtons) {
                    let auth = $("#Image_Scoreleft form input[value='Vote Up']").parent().find("input[name='auth_token']").prop("value");
                    let id = $("#Image_Scoreleft form input[value='Vote Up']").parent().find("input[name='image_id']").prop("value");
                    $("#customLikeButtonText").text("...");
                    $.post( "/numeric_score_vote", { auth_token: auth, image_id: id, vote: "up" }, function(data){
                        $("#customLikeButtonText").text($(data).find("#Image_Scoreleft > .blockbody").text().trim().replace(/[^0-9]/g, ""));
                    }).fail(function(){
                        $("#customLikeButtonText").text("error");
                    });
                }
                else
                    $("#Image_Scoreleft form input[value='Vote Up']").click();
            });
            $("#favorite-butt").click(function() {
                if(UseAJAXForLikeFavoriteButtons) {
                    let auth = $("#Image_Controlsleft form input[value='Favorite']").parent().find("input[name='auth_token']").prop("value");
                    let id = $("#Image_Controlsleft form input[value='Favorite']").parent().find("input[name='image_id']").prop("value");
                    $("#customFavButtonText").text("...");
                    $.post( "/change_favorite", { auth_token: auth, image_id: id, favorite_action: "set" }, function(data){
                        $("#customFavButtonText").text($(data).find("#Favorited_Byleft > .blockbody").text().split(":")[0].trim().replace(/[^0-9]/g, ""));
                    }).fail(function(){
                        $("#customFavButtonText").text("error");
                    });
                }
                else
                    $("#Image_Controlsleft form input[value='Favorite']").click();
            });
        }

        if(NextPrevWithArrowKeys && 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(){
                //alert($(this).find("*:visible").length);
                //alert($(this).find("*:visible").not("p:empty").length);
                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");
    }
})();