// ==UserScript==
// @name pikpak助手
// @namespace http://tampermonkey.net/
// @version 0.1
// @description pikpak网盘助手,绕过ip限制,支持aria2下载!
// @author xiaoziguys
// @match https://mypikpak.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=mypikpak.com
// @grant unsafeWindow
// @grant GM_xmlhttpRequest
// @run-at document-start
// @license MIT
// @downloadURL none
// ==/UserScript==
function Toast(dom, value) {
dom.innerText = value
dom.style.visibility = 'visible'
setTimeout(() => {dom.style.visibility = 'hidden'}, 1000)
}
function addStyle(id, tag, css) {
tag = tag || 'style';
let doc = document, styleDom = doc.getElementById(id);
if (styleDom) return;
let style = doc.createElement(tag);
style.rel = 'stylesheet';
style.id = id;
tag === 'style' ? style.innerHTML = css : style.href = css;
doc.getElementsByTagName('head')[0].appendChild(style);
}
function post(url, data, headers, type) {
data = JSON.stringify(data);
return new Promise((resolve, reject) => {
GM_xmlhttpRequest({
method: "POST", url, headers, data,
responseType: type || 'json',
onload: (res) => {
type === 'blob' ? resolve(res) : resolve(res.response || res.responseText);
},
onerror: (err) => {
reject(err);
},
});
});
}
async function postData(url = '', data = {}, customHeaders = {}, method = 'GET') {
// Default options are marked with *
let options = {
method: method, // *GET, POST, PUT, DELETE, etc.
mode: 'cors', // no-cors, *cors, same-origin
cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
credentials: 'same-origin', // include, *same-origin, omit
headers: {
'Content-Type': 'application/json',
// 'Content-Type': 'application/x-www-form-urlencoded',
...customHeaders
},
redirect: 'follow', // manual, *follow, error
referrerPolicy: 'no-referrer'
}
method === 'POST' && (options.body = JSON.stringify(data))
const response = await fetch(url, {
method: 'GET', // *GET, POST, PUT, DELETE, etc.
mode: 'cors', // no-cors, *cors, same-origin
cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
credentials: 'same-origin', // include, *same-origin, omit
headers: {
'Content-Type': 'application/json',
// 'Content-Type': 'application/x-www-form-urlencoded',
...customHeaders
},
redirect: 'follow', // manual, *follow, error
referrerPolicy: 'no-referrer', // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
});
return response.json(); // parses JSON response into native JavaScript objects
}
(function() {
'use strict';
// divert region limit
document.cookie = "pp_access_to_visit=true"
let flag = setInterval(() => {
let container = document.getElementsByClassName('context-menu')
if (container[0]) {
clearInterval(flag)
// ready
let ariaHost = window.localStorage.getItem('ariaHost') || ''
let ariaPath = window.localStorage.getItem('ariaPath') || ''
// add download btn
let aria2Btn = document.createElement('button')
aria2Btn.innerText = '推送到aria2'
aria2Btn.className = 'el-button el-button--primary'
aria2Btn.style.marginTop = '10px'
container[0].append(aria2Btn)
// aria2配置dom
let btnBox = document.getElementsByClassName('add-resources')[0]
let configBtn = document.createElement('button')
configBtn.innerText = '配置aira2'
configBtn.className = 'el-button el-button--primary'
configBtn.style.marginTop = '10px'
btnBox.append(configBtn)
// form
let form = document.createElement('div')
form.id = 'aria2form'
addStyle('','',`
#aria2form {
top: 20vh;
position: fixed;
background: #fff;
left: calc(50vw - 50px);
/* height: 30px; */
padding: 20px;
box-shadow: 0 2px 8px rgb(0 0 0 / 10%);;
border-radius: 4px;
visibility: hidden;
}
.xz-input {
border: #d9d9d9 1px solid;
margin-bottom: 10px;
padding: 5px;
margin-top: 5px;
}
#aria2Toast {
top: 5vh;
position: fixed;
background: #fff;
left: 50%;
transform: translate(-50%, 0);
/* height: 30px; */
padding: 20px;
box-shadow: 0 2px 8px rgb(0 0 0 / 10%);;
border-radius: 4px;
visibility: hidden;
}
`)
document.body.append(form)
form.innerHTML = `
服务器: