// ==UserScript==
// @name 西瓜Down - 西瓜视频下载工具
// @namespace Violentmonkey Scripts
// @match https://www.ixigua.com/*
// @grant none
// @version 1.4
// @license MIT
// @author Apollo Wang
// @description 2021/7/30 下午9:01:58
// @downloadURL https://update.greasyfork.icu/scripts/433783/%E8%A5%BF%E7%93%9CDown%20-%20%E8%A5%BF%E7%93%9C%E8%A7%86%E9%A2%91%E4%B8%8B%E8%BD%BD%E5%B7%A5%E5%85%B7.user.js
// @updateURL https://update.greasyfork.icu/scripts/433783/%E8%A5%BF%E7%93%9CDown%20-%20%E8%A5%BF%E7%93%9C%E8%A7%86%E9%A2%91%E4%B8%8B%E8%BD%BD%E5%B7%A5%E5%85%B7.meta.js
// ==/UserScript==
function HTMLInit() {
let head = document.querySelector("head")
let newStyle = document.createElement("style")
newStyle.innerHTML = "body{margin:0;}.left{position:fixed;width:200px;height:100%;left:-200px;background:whitesmoke;z-index:1000;box-shadow:5px 0px 10px rgba(0,0,0,.2);transition:all 0.3s;text-align:center;z-index:9998;}.left.left-open{left:0;margin:0;object-fit:fill;z-index:9998;}.mask{display:none;position:fixed;height:100%;width:100%;background:rgba(0,0,0,.5);z-index:9996;}#open{position:fixed;top:calc(50vh);background:transparent;z-index:9997;cursor:pointer;}.open-svg{height:50%;width:50%;margin-left:-20px;z-index:9997;}"
head.appendChild(newStyle)
let body = document.querySelector("body")
let ext_btn = document.createElement('div')
let first = document.body.firstChild;
ext_btn.innerHTML = '
'
body.insertBefore(ext_btn, first)
let open = document.getElementById("open");
let left = document.querySelector(".left");
let mask = document.querySelector(".mask");
open.onclick = function() {
open.style.display = "none";
left.className += " left-open";
mask.style.display = "block";
}
mask.onclick = function() {
left.className += "left";
mask.style.display = "none";
open.style.display = "block"
}
}
function txt_generate(data, name) {
const file = new Blob(data, { type: 'text/plain' });
a.href = URL.createObjectURL(file);
a.download = name;
}
if (document.location.toString() !== "https://www.ixigua.com/") {
HTMLInit();
const place = document.getElementsByClassName('left')[0];
const map = new Map();
function GetUrlRelativePath() {
let url = document.location.toString();
let arrUrl = url.split("//");
let start = arrUrl[1].indexOf("/");
let relUrl = arrUrl[1].substring(start); //stop省略,截取从start开始到结尾的所有字符
if (relUrl.indexOf("?id") != -1) {
relUrl = relUrl.split("?id")[1];
} else if (relUrl.indexOf("?") != -1) {
relUrl = relUrl.split("?")[0];
}
return relUrl;
}
let url = "https://www.ixigua.com/api/public/videov2/brief/details?group_id=" + GetUrlRelativePath().substr(1)
const Http = new XMLHttpRequest()
Http.open("GET", url)
Http.send()
Http.onreadystatechange = (e) => {
if (Http.readyState === XMLHttpRequest.DONE && Http.status === 200) {
let json = JSON.parse(Http.responseText)
let videoUrls = json['data']['videoResource']['normal']['video_list']
for (var p in videoUrls) { //遍历json对象的每个key/value对,p为key
map.set(videoUrls[p]['definition'], atob(videoUrls[p]['main_url']));
let pTag = document.createElement('p');
let a = document.createElement('a');
a.text = videoUrls[p]['definition'];
a.href = atob(videoUrls[p]['main_url']);
pTag.appendChild(a);
pTag.style = "padding-top: 20px;"
place.appendChild(pTag);
}
}
}
}