Skip to content

Commit

Permalink
hololive fc
Browse files Browse the repository at this point in the history
  • Loading branch information
stu43005 committed Aug 18, 2022
1 parent d624d13 commit 339c558
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 0 deletions.
57 changes: 57 additions & 0 deletions hololive_fc_get_m3u8.user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// ==UserScript==
// @name Hololive FC get m3u8 url
// @description get m3u8 url on Hololive FC
// @version 1.0.0
// @include https://hololive-fc.com/live/*
// @include https://hololive-fc.com/video/*
// @run-at document-start
// ==/UserScript==
'use strict';

const xml_http_request = 'xml_http_request';
const xml_http_response = 'xml_http_response';

function trigger(name, data) {
var event = new CustomEvent(name, {
'detail': data
});
return document.dispatchEvent(event);
}

function initXMLHttpRequest() {
const open = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function (...args) {
const send = this.send;
const _this = this;
let post_data = [];
this.send = function (...data) {
post_data = data;
return send.apply(_this, data);
}
trigger(xml_http_request, args);

this.addEventListener('readystatechange', function () {
if (this.readyState === 4) {
const config = {
url: args[1],
status: this.status,
method: args[0],
data: post_data
};
trigger(xml_http_response, { config, response: this.response });
}
}, false);
return open.apply(this, args);
}
}
initXMLHttpRequest();

document.addEventListener(xml_http_request, (event) => {
const [method, url] = event.detail;
if (url.includes(".m3u8")) {
console.log(xml_http_request, event.detail);
const div = document.createElement("div");
div.innerHTML = url;
document.getElementById("player").insertAdjacentElement('afterend', div);
}
});
26 changes: 26 additions & 0 deletions hololive_fc_remove_comment.user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// ==UserScript==
// @name Hololive FC remove comment
// @description remove comment on Hololive FC
// @version 1.0.0
// @include https://hololive-fc.com/live/*
// @include https://hololive-fc.com/video/*
// @run-at document-end
// ==/UserScript==
'use strict';

const timer = setInterval(() => {
for (const element of document.querySelectorAll("h6.MuiTypography-subtitle2")) {
if (element.innerText.includes("コメント")) {
let node = element;
for (;;) {
if (!node.parentNode.getElementsByTagName("video").length) {
node = node.parentNode;
} else {
break;
}
}
node.parentNode.removeChild(node);
clearInterval(timer);
}
}
}, 1000);
84 changes: 84 additions & 0 deletions screenshot/hololive_fc_screenshot.user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// ==UserScript==
// @name Hololive FC screenshot
// @description Add a button under the video to screenshot the video on Hololive FC
// @namespace ScreenshotTools
// @version 1.0.0
// @include https://hololive-fc.com/live/*
// @include https://hololive-fc.com/video/*
// @run-at document-end
// ==/UserScript==
'use strict';

const spacerButton = document.createElement("div");
spacerButton.className = "nfcp-button screenshotButton";
spacerButton.style.fontSize = "20px";
spacerButton.style.padding = "0";
spacerButton.style.lineHeight = "18px";
spacerButton.style.cursor = "pointer";
spacerButton.innerHTML = '📷';
spacerButton.onclick = captureScreenshot;

function addSpacerButton() {
const spacerElem = document.querySelector(".nfcp-controls .nfcp-controls-right");
if (spacerElem) {
spacerElem.insertAdjacentElement('afterbegin', spacerButton);
} else {
setTimeout(() => { addSpacerButton() }, 1000);
}
}
addSpacerButton();

function captureScreenshot() {
const players = document.getElementsByTagName("video");
const player = Array.prototype.filter.call(players, (p) => p.src != "" && p.offsetParent)[0];

const canvas = document.createElement("canvas");
canvas.width = player.videoWidth;
canvas.height = player.videoHeight;
canvas.getContext('2d').drawImage(player, 0, 0, canvas.width, canvas.height);

canvas.toBlob(async function (blob) {
const downloadLink = document.createElement("a");
downloadLink.download = getFileName(player);
downloadLink.href = URL.createObjectURL(blob);
downloadLink.click();
}, 'image/png');
}

function getFileName(player) {
const ext = ".png";
const time = formatTime(player.currentTime);
return `Hololive FC screenshot ${time}${ext}`;
}

function formatTime(time) {

var seconds = Math.floor(time);

if (seconds < 60) {
return seconds + "s";
}

var minutes = Math.floor(seconds / 60);
seconds = seconds % 60;

if (minutes < 60) {
return minutes + "m" + paddingTwoZero(seconds) + "s";
}

var hours = Math.floor(minutes / 60);
minutes = minutes % 60;

if (hours < 24) {
return hours + "h" + paddingTwoZero(minutes) + "m" + paddingTwoZero(seconds) + "s";
}

var days = Math.floor(hours / 24);
hours = hours % 24;

return days + "d" + paddingTwoZero(hours) + "h" + paddingTwoZero(minutes) + "m" + paddingTwoZero(seconds) + "s";
}

function paddingTwoZero(num) {
return ('00' + num).slice(-2);
}

0 comments on commit 339c558

Please sign in to comment.