Sleazy Fork is available in English.

Rule34Hentai Improved

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

Fra og med 22.01.2020. Se den nyeste version.

// ==UserScript==
// @name         Rule34Hentai Improved
// @namespace    http://tampermonkey.net/
// @author       Hentiedup
// @version      0.6.5
// @icon         https://i.imgur.com/Aea35p5.png
// @description  Fixes stuff, adds like and favorite under images, highlights animated, makes the site more compact, etc.
// @include      https://rule34hentai.net*
// @require      https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_deleteValue
// @grant        GM_listValues
// ==/UserScript==

(function() {
    'use strict';

    /*============================================*/
    /*============================================*/
    /*=*|      The settings are now found      |*=*/
    /*=*|          on the actual site          |*=*/
    /*=*|      in the "My Profile" section     |*=*/
    /*============================================*/
    /*============================================*/





    /* Don't edit anything below */
    /*===========================*/
	/*       video/image       */
    var HighlightVideos = GM_getValue("HighlightVideos", true);
    var AutoplayVideos = GM_getValue("AutoplayVideos", true);;
    var StopHidingMyCursorOnVideo = GM_getValue("StopHidingMyCursorOnVideo", true);
    var PauseVideoOnClick = GM_getValue("PauseVideoOnClick", true);
    var DownsizeToFit = GM_getValue("DownsizeToFit", true);
    var NextPrevWithArrowKeys = GM_getValue("NextPrevWithArrowKeys", true);
    var AllowContextMenuOnImages = GM_getValue("AllowContextMenuOnImages", true);

	/*      Compact site       */
    var CompactHeader = GM_getValue("CompactHeader", true);
    var MinimizeHeaderFurtherAndShowOnHover = GM_getValue("MinimizeHeaderFurtherAndShowOnHover", false);
    var HideEmptySections = GM_getValue("HideEmptySections", true);
    var HideLog = GM_getValue("HideLog", true);
    var HideImageVideoHeader = GM_getValue("HideImageVideoHeader", true);
    var RemoveSomeSneakyAds = GM_getValue("RemoveSomeSneakyAds", true);
    var CenterContent = GM_getValue("CenterContent", false);

    /*   Sidepanel   */
    var HideSidepanel = GM_getValue("HideSidepanel", "no");
    var HideNavigationInSidePanel = GM_getValue("HideNavigationInSidePanel", false);
    var HideFeaturedImgInSidePanel = GM_getValue("HideFeaturedImgInSidePanel", false);
    var HideNewsInSidePanel = GM_getValue("HideNewsInSidePanel", false);
    var HideCommentsInSidePanel = GM_getValue("HideCommentsInSidePanel", false);
    var HidePopularTagsInSidePanel = GM_getValue("HidePopularTagsInSidePanel", false);
    var HideTagsInSidePanel = GM_getValue("HideTagsInSidePanel", false);
    var HideLikesInSidePanel = GM_getValue("HideLikesInSidePanel", true);
    var HideFavByInSidePanel = GM_getValue("HideFavByInSidePanel", false);
    var HideReportInSidePanel = GM_getValue("HideReportInSidePanel", false);
    var HideImgControlInSidePanel = GM_getValue("HideImgControlInSidePanel", false);

	/*      like/favorite      */
    var EnableLikeFavoriteButtonsBelowImage = GM_getValue("EnableLikeFavoriteButtonsBelowImage", true);

    if(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: auto;
				display: block;
				text-align: center;
			}
			.customButtonDiv {
				display: inline-block;
				margin: 0;
				padding: 0;
				width: auto;
				float: left;
			}
			.customButtonDiv:nth-of-type(1) { margin-right: 10px; }
			.customButtonDiv:nth-of-type(2) { margin-left: 10px; }

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

			#r34hi_settings label
			{
				display: block;
			}
			#r34hi_settings input[type="checkbox"]
			{
				transform: scale(1.2);
			}
			#r34hi_settings select
			{
				width: auto;
			}
			#r34hi_settings > .blockbody
			{
				padding-bottom: 30px;
			}
			#r34hi_settings h4
			{
				margin: 23px 0 15px 0;
			}
		`);

		if(RemoveSomeSneakyAds)
			addGlobalStyle(`
				/*The site only uses iframes for ads, so might as well hide all of them*/
				iframe { display: none; }
				#header td:nth-of-type(1) center:nth-of-type(2) > div { display: none; }

				/*As far as I can tell the "Recommended" div is only for ads*/
				#Recommended_for_youleft { display: none; }

				/*Hiding some links from the header that are pretty much just ads*/
				#header td ul > li a:not([href^="https://rule34hentai.net"]):not([href^="#"]) { display: none; }
                #header td ul > li img[src^="https://theporndude.com"] { display: none; }
			`);

        if(CenterContent)
            addGlobalStyle(`
				#fluid_video_wrapper_video-id, #main_image
				{
					display: block;
					margin: auto;
				}

				#Imagemain + section > .blockbody, #Videomain + section > .blockbody
				{
					width: 720px;
					display: block;
					margin: auto;
				}
			`);

        if(HideSidepanel == "all")
            addGlobalStyle(`
				body > nav { display: none; }
				body > article { margin-left: 16px; }
			`);
        if(HideNavigationInSidePanel)
            addGlobalStyle(`#Navigationleft { display: none; }`);
        if(HideFeaturedImgInSidePanel)
            addGlobalStyle(`#Featured_Imageleft { display: none; }`);
        if(HideNewsInSidePanel)
            addGlobalStyle(`#Newsleft { display: none; }`);
        if(HideCommentsInSidePanel)
            addGlobalStyle(`#commentlistrecent { display: none; }`);
        if(HidePopularTagsInSidePanel)
            addGlobalStyle(`#Popular_Tagsleft { display: none; }`);
        if(HideTagsInSidePanel)
            addGlobalStyle(`#Tagsleft { display: none; }`);
        if(HideFavByInSidePanel)
            addGlobalStyle(`#Favorited_Byleft { display: none; }`);
        if(HideReportInSidePanel)
            addGlobalStyle(`#Report_Imageleft { display: none; }`);
        if(HideImgControlInSidePanel)
            addGlobalStyle(`#Image_Controlsleft { display: none; }`);
		if(HideLikesInSidePanel)
			addGlobalStyle(`#Image_Scoreleft { display: none; }`);

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

    if(HideSidepanel == "vid-img" && window.location.href.includes("/post/view/"))
    {
        addGlobalStyle(`
			body > nav { display: none; }
			body > article { margin-left: 16px; }
		`);
    }

    setTimeout(function(){

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

        if(window.location.pathname == "/user")
        {
            $("#Optionsmain").after(`<section id="r34hi_settings"><h3 data-toggle-sel="#Optionsmain">R34H Improved Settings</h3><div class="blockbody"><form action="#">` +
                                    `<h4>Video/Image</h4>` +
                                    `<label><input type="checkbox" name="HighlightVideos" `+(HighlightVideos ? "checked" : "")+`> Highlight videos</label>` +
                                    `<label><input type="checkbox" name="AutoplayVideos" `+(AutoplayVideos ? "checked" : "")+`> Autoplay videos</label>` +
                                    `<label><input type="checkbox" name="StopHidingMyCursorOnVideo" `+(StopHidingMyCursorOnVideo ? "checked" : "")+`> Show cursor on videos</label>` +
                                    `<label><input type="checkbox" name="PauseVideoOnClick" `+(PauseVideoOnClick ? "checked" : "")+`> Pause videos on click</label>` +
                                    `<label><input type="checkbox" name="DownsizeToFit" `+(DownsizeToFit ? "checked" : "")+`> Downsize images/videos to fit on screen</label>` +
                                    `<label><input type="checkbox" name="NextPrevWithArrowKeys" `+(NextPrevWithArrowKeys ? "checked" : "")+`> Go to next/previous image/video with left/right arrow</label>` +
                                    `<label><input type="checkbox" name="AllowContextMenuOnImages" `+(AllowContextMenuOnImages ? "checked" : "")+`> Allow context-menu/right-click on images</label>` +
                                    `<label><input type="checkbox" name="EnableLikeFavoriteButtonsBelowImage" `+(EnableLikeFavoriteButtonsBelowImage ? "checked" : "")+`> Enable like/dislike/favorite/unfavorite buttons below images/videos</label>` +
                                    `<label><input type="checkbox" name="CenterContent" `+(CenterContent ? "checked" : "")+`> Center video/image and info-box below it</label>` +
                                    `<h4>Compact Site</h4>` +
                                    `<label><input type="checkbox" name="CompactHeader" `+(CompactHeader ? "checked" : "")+`> Make the header more compact</label>` +
                                    `<label><input type="checkbox" name="MinimizeHeaderFurtherAndShowOnHover" `+(MinimizeHeaderFurtherAndShowOnHover ? "checked" : "")+`> Minimize the header even more and show more on hover</label>` +
                                    `<label><input type="checkbox" name="HideEmptySections" `+(HideEmptySections ? "checked" : "")+`> Hide Empty site sections</label>` +
                                    `<label><input type="checkbox" name="HideLog" `+(HideLog ? "checked" : "")+`> Hide the yellow log</label>` +
                                    `<label><input type="checkbox" name="HideImageVideoHeader" `+(HideImageVideoHeader ? "checked" : "")+`> Hide the image/video header</label>` +
                                    `<label><input type="checkbox" name="RemoveSomeSneakyAds" `+(RemoveSomeSneakyAds ? "checked" : "")+`> Remove some sneaky ads</label>` +
                                    `<h4>Sidepanel</h4>` +
                                    `<label> <select name="HideSidepanel">` +
									`<option value="no">Don't Hide</option>` +
									`<option value="all">Always Hide</option>` +
									`<option value="vid-img">Hide in img-video pages</option></select>  Hide the entire sidepanel</label>` +
                                    `<label><input type="checkbox" name="HideNavigationInSidePanel" `+(HideNavigationInSidePanel ? "checked" : "")+`> Hide the Navigation section in the sidepanel</label>` +
                                    `<label><input type="checkbox" name="HideFeaturedImgInSidePanel" `+(HideFeaturedImgInSidePanel ? "checked" : "")+`> Hide the Featured image section in the home page sidepanel</label>` +
                                    `<label><input type="checkbox" name="HideNewsInSidePanel" `+(HideNewsInSidePanel ? "checked" : "")+`> Hide the News section in the homepage sidepanel</label>` +
                                    `<label><input type="checkbox" name="HideCommentsInSidePanel" `+(HideCommentsInSidePanel ? "checked" : "")+`> Hide the Comments section in the homepage sidepanel</label>` +
                                    `<label><input type="checkbox" name="HidePopularTagsInSidePanel" `+(HidePopularTagsInSidePanel ? "checked" : "")+`> Hide the Popular tags section in the homepage sidepanel</label>` +
                                    `<label><input type="checkbox" name="HideTagsInSidePanel" `+(HideTagsInSidePanel ? "checked" : "")+`> Hide the Tags section in the sidepanel</label>` +
                                    `<label><input type="checkbox" name="HideLikesInSidePanel" `+(HideLikesInSidePanel ? "checked" : "")+`> Hide the Likes/Score section in the site sidepanel</label>` +
                                    `<label><input type="checkbox" name="HideFavByInSidePanel" `+(HideFavByInSidePanel ? "checked" : "")+`> Hide the Favorited by section in the site sidepanel</label>` +
                                    `<label><input type="checkbox" name="HideReportInSidePanel" `+(HideReportInSidePanel ? "checked" : "")+`> Hide the Report image section in the site sidepanel</label>` +
                                    `<label><input type="checkbox" name="HideImgControlInSidePanel" `+(HideImgControlInSidePanel ? "checked" : "")+`> Hide the Image controls section in the site sidepanel</label>` +
                                    `</form></div></section>`);

            $("#r34hi_settings select[name='HideSidepanel'] > option[value='"+HideSidepanel+"']").attr("selected", "selected");

            $("#r34hi_settings input").change(function(){
                GM_setValue($(this).attr("name"), $(this).is(':checked'));
            });
            $("#r34hi_settings select").change(function(){
                GM_setValue($(this).attr("name"), $(this).val());
            });
        }
        else
        {
            if(AutoplayVideos) {
                $("#video-id_fluid_state_button").click();
                $("body").click(); //remove focus from player
            }

            if(!PauseVideoOnClick) {
                $("#video-id_fluid_initial_play_button").remove();
                $("#video-id").click(function(e){
                    $("#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" title="like">` +
                    `<img id="dislike-butt" class="custom-button" src="https://i.imgur.com/b4syBNK.png" alt="dislike" title="dislike"><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` +
                    ($("#Image_Controlsleft form input[value='Un-Favorite']").length > 0 ? " unfavorite" : "") + `" src="` +
                    ($("#Image_Controlsleft form input[value='Un-Favorite']").length > 0 ? "https://i.imgur.com/wAB0t48.png" : "https://i.imgur.com/dTpBrIj.png") +
                    `" alt="` + ($("#Image_Controlsleft form input[value='Un-Favorite']").length > 0 ? "unfavorite" : "favorite") +
                    `" title="` + ($("#Image_Controlsleft form input[value='Un-Favorite']").length > 0 ? "unfavorite" : "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() {
                    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");
                    });
                });
                $("#dislike-butt").click(function() {
                    let auth = $("#Image_Scoreleft form input[value='Remove Vote']").parent().find("input[name='auth_token']").prop("value");
                    let id = $("#Image_Scoreleft form input[value='Remove Vote']").parent().find("input[name='image_id']").prop("value");
                    $("#customLikeButtonText").text("...");
                    $.post( "/numeric_score_vote", { auth_token: auth, image_id: id, vote: "down" }, function(data){
                        $("#customLikeButtonText").text($(data).find("#Image_Scoreleft > .blockbody").text().trim().replace(/[^0-9]/g, ""));
                    }).fail(function(){
                        $("#customLikeButtonText").text("error");
                    });
                });

                $("#favorite-butt").click(function() {
                    if($(this).hasClass("unfavorite"))
                    {
                        let auth = $("#Image_Controlsleft form input[value='Un-Favorite']").parent().find("input[name='auth_token']").prop("value");
                        let id = $("#Image_Controlsleft form input[value='Un-Favorite']").parent().find("input[name='image_id']").prop("value");
                        $("#customFavButtonText").text("...");
                        $.post( "/change_favorite", { auth_token: auth, image_id: id, favorite_action: "unset" }, function(data){
                            $("#customFavButtonText").text($(data).find("#Favorited_Byleft > .blockbody").text().split(":")[0].trim().replace(/[^0-9]/g, ""));
                            $("#favorite-butt").attr("src", "https://i.imgur.com/dTpBrIj.png");
                            $("#favorite-butt").attr("alt", "favorite");
                            $("#favorite-butt").attr("title", "favorite");
                            $("#Image_Controlsleft form input[value='Un-Favorite']").attr("value", "Favorite");
                            $("#Image_Controlsleft form input[name='favorite_action']").attr("value", "set");
                            $("#favorite-butt").removeClass("unfavorite");
                        }).fail(function(){
                            $("#customFavButtonText").text("error");
                        });
                    }
                    else
                    {
                        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, ""));
                            $("#favorite-butt").attr("src", "https://i.imgur.com/wAB0t48.png");
                            $("#favorite-butt").attr("alt", "unfavorite");
                            $("#favorite-butt").attr("title", "unfavorite");
                            $("#Image_Controlsleft form input[value='Favorite']").attr("value", "Un-Favorite");
                            $("#Image_Controlsleft form input[name='favorite_action']").attr("value", "unset");
                            $("#favorite-butt").addClass("unfavorite");
                        }).fail(function(){
                            $("#customFavButtonText").text("error");
                        });
                    }
                });
            }

            if(NextPrevWithArrowKeys && window.location.href.includes("/post/view/")) {
                $("body").keyup(function(event){
                    if($("textarea:focus, input[type=text]:focus").length == 0)
                    {
                        console.log("keypress");
                        if(event.which == 39) {
                            console.log("right");
                            $("#nextlink")[0].click();
                        }
                        else if(event.which == 37) {
                            console.log("left");
                            $("#prevlink")[0].click();
                        }
                    }
                });
            }

            if(AllowContextMenuOnImages)
                $("#main_image").replaceWith($("#main_image").clone());

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

    }, 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);
    }
})();