IP2 ENHANCER

This script adds video thumbnails to IP2 and fixes various issues with video playback. Message /u/ChangThunderwang for bugs and anything related to this.

As of 2022-01-08. See the latest version.

Author
changthunderwang
Ratings
0 0 0
Version
2.3
Created
2021-04-25
Updated
2022-01-08
Size
7.64 KB
License
N/A
Applies to

// ==UserScript==
// @name IP2 VideoFix
// @description This script ads video thumbnails to IP2 and fixes various issues with video playback. Message /u/ChangThunderwang for bugs and anything related to this.
// @grant GM_addStyle
// @version 1.1
// @match *://ip2always.win/*
// @match *://communities.win/*
// @namespace https://greasyfork.org/users/764563
// ==/UserScript==
/*jshint esversion: 6 */


// Fixes video CSS so that videos don't get cut off
GM_addStyle(`
@media only screen and (min-width:973px) {
body .post-list div.content.link div.inner{
background: rgba(0,0,0,0)!important;
}
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}
.post-list .content {
margin: 8px 0 0 180px;
}
.post-list .content .inner {
padding: 0
}
.video-container.iframe-parent{
position: relative;
overflow: hidden;
width: 100%;
padding-top: 56.25%;
}
.video-container.iframe-parent > .responsive-iframe {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
width: 100%;
height: 100%;
}
.video-container {
margin: 0px;
padding: 0px;
overflow: inherit;
height: auto;
}
.video-container video{
max-height: 33vw;
}
}
`);

//Removes old handler for the expand buttons on videos upon mouseover. This is delayed to allow the site code to load first.
var once = false;
$(document).on("mouseover", '[data-action="expand"]', function () {
if (!once) {
$(document).off("click", '[data-action="expand"]');
once = true;
} else {
$(document).off("mouseover", '[data-action="expand"]');
}
});

window.onload = function () {
$(document).off("click", '[data-action="expand"]');
}

//Assigns new improved handler for video embeds which removes video tags upon closing
$(document).on("click", 'a[data-action="expand"], .thumb[data-action="expand"]', function () {
$(document).off("click", '[data-action="expand"]');
content = $(this).closest(".post").find(".content").first();
if (content.attr("data-opened") != null) {
return;
}
content.attr("data-opened", true);
if (
content.find("img").first().length &&
content.find("img").first().attr("src") === ""
) {
content
.find("img")
.first()
.attr("src", content.find("img").first().data("src"));
} else if (content.find(".video-container").first().length) {
var first = content.find(".video-container").first();
if ($.trim(content.find(".video-container").first().html()) === "") {
if (
first.hasClass("mp4") ||
/.+(\.mp4|\.mov|\.webm)/i.test(first.data("src"))
) {
content
.find(".video-container")
.first()
.append(
''
);
var vid = content.find(".video-container > video.child-content");
} else {
content
.find(".video-container")
.first()
.append(
''
);
content
.find(".video-container")
.first().addClass('iframe-parent')
}
}
}
content.find("img").first().removeAttr("data-src");
content.find("img").first().removeData("src");
content.slideToggle(0, function () {
content.removeAttr("data-opened");
if (content.is(":hidden")) {
var children = content.find(".child-content");
children.remove();
}
});
});