// ==UserScript==
// @license MIT
// @name 含羞草研究所免费看
// @namespace http://tampermonkey.net/
// @version 0.2.2
// @description 针对 含羞草研究所 的优化脚本,此脚本可以让用户观看VIP视频
// @author You
// @match https://www.hxcbb101.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=hxcbb101.com
// @grant none
// ==/UserScript==
function importLib() {
//importJS("https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.0.0/crypto-js.min.js")
importJS("https://cdn.jsdelivr.net/npm/hls.js")
importJS("https://cdn.jsdelivr.net/npm/dplayer")
}
function importJS(src) {
let script = document.createElement('script');
script.src = src;
document.head.appendChild(script);
}
async function getPreUrl(token, videoId) {
var myHeaders = new Headers();
myHeaders.append("auth", token);
myHeaders.append("Content-Type", "application/json");
var raw = JSON.stringify({
"videoId": parseInt(videoId)
});
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
let res = await fetch("https://www.hxc-api.com/videos/getPreUrl", requestOptions);
res = res.text();
return res;
}
function getVideoId() {
let url = window.location.href;
let urlSplited = url.split("/");
let videoId = urlSplited[urlSplited.length - 1];
return videoId;
}
function getStorage() {
let storage = localStorage.getItem("newPCVideoNoLiveStore")
let json = JSON.parse(storage);
return json;
}
function getToken(storage) {
let res = storage;
let token = res.userToken;
return token;
}
function play(playerUrl, pic) {
document.querySelector(".split").style = "width: 1200px; height: 550px;"
let dp = new DPlayer({
element: document.querySelector(".split"), // 可选,player元素
autoplay: false, // 可选,自动播放视频,不支持移动浏览器
theme: '#FADFA3', // 可选,主题颜色,默认: #b7daff
loop: true, // 可选,循环播放音乐,默认:true
lang: 'zh', // 可选,语言,`zh'用于中文,`en'用于英语,默认:Navigator language
screenshot: true, // 可选,启用截图功能,默认值:false,注意:如果设置为true,视频和视频截图必须启用跨域
hotkey: true, // 可选,绑定热键,包括左右键和空格,默认值:true
preload: 'auto', // 可选,预加载的方式可以是'none''metadata''auto',默认值:'auto'
video: { // 必需,视频信息
url: playerUrl, // 必填,视频网址
pic: pic, // 可选,视频截图
type: 'hls'
}
});
}
async function loadAndPlay(playerUrl, pic){
let intervalNum = setInterval(() => {
if(typeof DPlayer !== 'undefined'){
clearInterval(intervalNum);
play(playerUrl, pic)
}
}, 1000);
}
function isLogin() {
let storage = getStorage()
if (storage) {
let isLogin = storage.isLogin
return isLogin;
}
return false;
}
function randomPhoneNumber() {
let prefixArray = new Array("130", "131", "132", "133", "135", "137", "138", "170", "187", "189");
let i = parseInt(10 * Math.random());
let prefix = prefixArray[i];
for (var j = 0; j < 8; j++) {
undefined
prefix = prefix + Math.floor(Math.random() * 10);
}
return prefix;
}
function getAccount() {
let account = {};
let storage = getStorage()
if (storage) {
account.userName = storage.userName;
account.password = storage.password;
return account;
}
return null;
}
function genAccount() {
let account = {};
let phone = randomPhoneNumber();
account.userName = phone;
account.password = "123456";
return account;
}
function register(account) {
document.querySelectorAll(".topLoginButtonLine > p")[1].click();
setTimeout(() => {
let event = new Event('input', { bubbles: true, cancelable: true, composed: true });
let accountDom = document.querySelectorAll(".el-form input")[0]
accountDom.value = account.userName;
accountDom.dispatchEvent(event)
let passwordDom = document.querySelectorAll(".el-form input")[1]
passwordDom.value = account.password;
passwordDom.dispatchEvent(event)
let confirmPasswordDom = document.querySelectorAll(".el-form input")[2]
confirmPasswordDom.value = account.password;
confirmPasswordDom.dispatchEvent(event)
document.querySelectorAll(".el-form button")[0].click()
}, 600);
}
function login(account) {
document.querySelectorAll(".topLoginButtonLine > p")[0].click();
setTimeout(() => {
let event = new Event('input', { bubbles: true, cancelable: true, composed: true });
let accountDom = document.querySelector("input[placeholder='请输入手机号/电子邮箱']")
accountDom.value = account.userName;
accountDom.dispatchEvent(event);
let passwordDom = document.querySelector("input[type='password'")
passwordDom.value = account.password;
passwordDom.dispatchEvent(event);
document.querySelectorAll(".el-form button")[0].click()
},600)
}
async function init() {
if (!isLogin()) {
let account = getAccount();
if (account !== null) {
login(account);
} else {
account = genAccount()
registerLogin(account);
}
}
let storage = getStorage()
let token = getToken(storage)
let videoId = getVideoId()
let preUrl = await getPreUrl(token, videoId)
preUrl = JSON.parse(preUrl)
if (preUrl.code === 0) {
let m3u8Url = preUrl.data.url
let splited = m3u8Url.split("?")
let m3u8UrlParams = splited[1]
let urlSearchParams = new URLSearchParams(m3u8UrlParams)
urlSearchParams.delete("start")
urlSearchParams.delete("end")
let newM3U8Url = splited[0] + "?" + urlSearchParams.toString()
let pic = document.querySelector(".backImg img").getAttribute("src")
loadAndPlay(newM3U8Url, pic)
}
}
(function () {
'use strict';
importLib();
setTimeout(() => {
init();
}, 1200)
})();