// ==UserScript==
// @name pixiv快速打开原图&自动收藏&原图链接打包下载
// @description 通过“Ctrl+右键”快速打开pixiv图片原图(支持打开动态图的封面,但无法打开动态图),“Alt+右键”收藏此图片,并储存该图片下载链接,“Ctrl+Alt+右键”下载打包为txt的下载链接至本地,。在页面左侧出现三个悬浮按钮,最上面的一个“↓”对应“以txt格式下载已储存的图片链接”,即“ctrl+alt+右键”的功能,键盘快捷键并没有被删除。第二个画着黑色饼干的是删除上一个存储的pixiv图片链接。最后一个画有红色饼干的是清除全部已存储的图片链接,第一次点击会在页面顶部有提示,如果确认要清空,则再次点击该按钮即可,并在删除后再次在顶部出现已删除的提示。
// @version 1.1
// @namespace akari
// @author Pikaqian
// @include *://www.pixiv.net/*
// @include *://www.pixivision.net/*
// @icon https://static.hdslb.com/images/akari.jpg
// @grant GM_setClipboard
// ==/UserScript==
(function() {
'use strict';
var match_rules=[
/([_=:;&\-\/\.\?\d\w]+?illust_id=(\d+)(?:&|$|))/,
/(http(?:s|):\/\/[_\-\/\.\d\w]+?\/(\d{4,})_p\d{1,4}[_\-\/\.\d\w]*)/
];
let styleE = document.createElement('style'),rightButton,centerWrap,number=1,elem,deleteCookie,deleteAll,alert_count=0
document.body.appendChild(styleE);
styleE.textContent=`
#rightButton{
height:21px;
width:21px;
border-bottom-right-radius:21px;
border-top-right-radius:21px;
color:#fff;
padding:6px;
opacity:.15;
left:-20px;
cursor:pointer
}
#rightButton{
position:fixed;
z-index:1;
font-size:14px}
#rightButton{top:38%;background:#000}
#deleteCookie{
height:21px;
width:21px;
border-bottom-right-radius:21px;
border-top-right-radius:21px;
color:#fff;
padding:6px;
opacity:.15;
left:-20px;
cursor:pointer
}
#deleteCookie{
position:fixed;
z-index:1;
font-size:14px}
#deleteCookie{top:45%;background:#000}
#deleteAll{
height:21px;
width:21px;
border-bottom-right-radius:21px;
border-top-right-radius:21px;
color:#fff;
padding:6px;
opacity:.15;
left:-20px;
cursor:pointer
}
#deleteAll{
position:fixed;
z-index:1;
font-size:14px}
#deleteAll{top:52%;background:#f00}
`;
function lastcookie(){
var matchrule=/pixivid/
var cookie_separate=document.cookie.split(";")
for(var r=0;r<cookie_separate.length;r++){
if(cookie_separate[r].match(/pixivid/)!=null){
var results=cookie_separate[r].match(/pixivid/)
var results_1=cookie_separate[r].split("=")[0].split("d")[1]
}
else{
continue
}
}
console.log(results)
if(results==null){
return 0
}
else{
return parseInt(results_1)+1
}
}
function getelemt(findelement){
//——————————————————————————
var elem_1 = document.getElementsByTagName("svg");
for(var h=0;h<elem_1.length;h++){
var match_result=elem_1[h].id.match(findelement)
if(match_result!=null){
return elem_1[h]
break
}
}
//——————————————————————————
}
function myMove() {
elem=getelemt("rightButton")
// var elem = document.getElementsByTagName("svg")[document.getElementsByTagName("svg").length-1];
var pos = -20;
var id = setInterval(frame, 5);
function frame(){
rightButton.addEventListener('mouseleave',()=>{
clearInterval(id)
})
if (pos == 0) {
clearInterval(id);
} else {
pos++;
elem.style.left = pos + "px";
}
}
}
function myOut() {
elem=getelemt("rightButton")
// var elem = document.getElementsByTagName("svg")[document.getElementsByTagName("svg").length-1];
var pose = 0;
var id = setInterval(frame, 5);
function frame(){
rightButton.addEventListener('mouseenter',()=>{
clearInterval(id)
})
if (pose == -20) {
clearInterval(id);
} else {
pose--;
elem.style.left = pose + "px";
}
}
}
function delMove() {
elem=getelemt("deleteCookie")
// var elem = document.getElementsByTagName("svg")[document.getElementsByTagName("svg").length-1];
var pos = -20;
var id = setInterval(frame, 5);
function frame(){
deleteCookie.addEventListener('mouseleave',()=>{
clearInterval(id)
})
if (pos == 0) {
clearInterval(id);
} else {
pos++;
elem.style.left = pos + "px";
}
}
}
function delOut() {
elem=getelemt("deleteCookie")
// var elem = document.getElementsByTagName("svg")[document.getElementsByTagName("svg").length-1];
var pose = 0;
var id = setInterval(frame, 5);
function frame(){
deleteCookie.addEventListener('mouseenter',()=>{
clearInterval(id)
})
if (pose == -20) {
clearInterval(id);
} else {
pose--;
elem.style.left = pose + "px";
}
}
}
function redMove() {
elem=getelemt("deleteAll")
// var elem = document.getElementsByTagName("svg")[document.getElementsByTagName("svg").length-1];
var pos = -20;
var id = setInterval(frame, 5);
function frame(){
deleteCookie.addEventListener('mouseleave',()=>{
clearInterval(id)
})
if (pos == 0) {
clearInterval(id);
} else {
pos++;
elem.style.left = pos + "px";
}
}
}
function redOut() {
elem=getelemt("deleteAll")
// var elem = document.getElementsByTagName("svg")[document.getElementsByTagName("svg").length-1];
var pose = 0;
var id = setInterval(frame, 5);
function frame(){
deleteCookie.addEventListener('mouseenter',()=>{
clearInterval(id)
})
if (pose == -20) {
clearInterval(id);
} else {
pose--;
elem.style.left = pose + "px";
}
}
}
function addRightButton () {
rightButton = document.createElementNS("http://www.w3.org/2000/svg", "svg");
var path2 = document.createElementNS("http://www.w3.org/2000/svg", 'path');
rightButton.setAttribute("aria-hidden","true");
rightButton.setAttribute('viewbox', '0 0 24 24');
rightButton.setAttribute('width', '24px');
rightButton.setAttribute('height', '24px');
//path2.setAttribute('d', 'M0 0 H 30 V 30 H 0 Z');
path2.setAttribute('d','M 10 4 L 12 4 L 12 19 L 10 19 Z M 4 11 L 5 11 L 10 16 L 10 19 L 4 13 Z M 18 11 L 17 11 L 12 16 L 12 19 L 18 13 Z')
path2.setAttribute('fill', '#fff');
rightButton.appendChild(path2);
rightButton.id = 'rightButton';
document.body.appendChild(rightButton);
deleteCookie = document.createElementNS("http://www.w3.org/2000/svg", "svg");
var path3 = document.createElementNS("http://www.w3.org/2000/svg", 'path');
deleteCookie.setAttribute("aria-hidden","true");
deleteCookie.setAttribute('viewbox', '0 0 24 24');
deleteCookie.setAttribute('width', '24px');
deleteCookie.setAttribute('height', '24px');
//path2.setAttribute('d', 'M0 0 H 30 V 30 H 0 Z');
path3.setAttribute('d','M 10.24 2.56 C 5.99893334 2.56 2.56 5.99893334 2.56 10.24 2.56 14.48106666 5.99893334 17.92 10.24 17.92 14.48106666 17.92 17.92 14.48106666 17.92 10.24 17.92 9.81333334 17.885866659999998 9.38666666 17.80906666 8.96 17.57866666 8.53333334 17.06666666 8.53333334 17.06666666 8.53333334 L 15.36 8.53333334 15.36 7.68 C 15.36 6.82666666 14.50666666 6.82666666 14.50666666 6.82666666 L 12.8 6.82666666 12.8 5.97333334 C 12.8 5.12 11.94666666 5.12 11.94666666 5.12 L 11.09333334 5.12 11.09333334 3.41333334 C 11.09333334 2.56 10.24 2.56 10.24 2.56 M 8.10666666 5.12 C 8.81493334 5.12 9.38666666 5.69173334 9.38666666 6.4 9.38666666 7.108266660000001 8.81493334 7.68 8.10666666 7.68 7.3984000000000005 7.68 6.82666666 7.108266660000001 6.82666666 6.4 6.82666666 5.69173334 7.3984000000000005 5.12 8.10666666 5.12 M 5.54666666 8.53333334 C 6.25493334 8.53333334 6.82666666 9.10506666 6.82666666 9.81333334 6.82666666 10.521600000000001 6.25493334 11.09333334 5.54666666 11.09333334 4.8384 11.09333334 4.26666666 10.521600000000001 4.26666666 9.81333334 4.26666666 9.10506666 4.8384 8.53333334 5.54666666 8.53333334 M 9.81333334 9.38666666 C 10.521600000000001 9.38666666 11.09333334 9.958400000000001 11.09333334 10.66666666 11.09333334 11.37493334 10.521600000000001 11.94666666 9.81333334 11.94666666 9.10506666 11.94666666 8.53333334 11.37493334 8.53333334 10.66666666 8.53333334 9.958400000000001 9.10506666 9.38666666 9.81333334 9.38666666 M 14.08 11.09333334 C 14.78826666 11.09333334 15.36 11.66506666 15.36 12.373333339999999 15.36 13.081600000000002 14.78826666 13.65333334 14.08 13.65333334 L 14.08 13.65333334 C 13.37173334 13.65333334 12.8 13.081600000000002 12.8 12.373333339999999 L 12.8 12.373333339999999 C 12.8 11.66506666 13.37173334 11.09333334 14.08 11.09333334 M 9.38666666 13.65333334 C 10.09493334 13.65333334 10.66666666 14.22506666 10.66666666 14.933333339999999 10.66666666 15.6416 10.09493334 16.21333334 9.38666666 16.21333334 8.6784 16.21333334 8.10666666 15.6416 8.10666666 14.933333339999999 8.10666666 14.22506666 8.6784 13.65333334 9.38666666 13.65333334 Z')
path3.setAttribute('fill', '#fff');
deleteCookie.appendChild(path3);
deleteCookie.id = 'deleteCookie';
document.body.appendChild(deleteCookie);
deleteAll = document.createElementNS("http://www.w3.org/2000/svg", "svg");
var path4 = document.createElementNS("http://www.w3.org/2000/svg", 'path');
deleteAll.setAttribute("aria-hidden","true");
deleteAll.setAttribute('viewbox', '0 0 24 24');
deleteAll.setAttribute('width', '24px');
deleteAll.setAttribute('height', '24px');
//path2.setAttribute('d', 'M0 0 H 30 V 30 H 0 Z');
path4.setAttribute('d','M 10.24 2.56 C 5.99893334 2.56 2.56 5.99893334 2.56 10.24 2.56 14.48106666 5.99893334 17.92 10.24 17.92 14.48106666 17.92 17.92 14.48106666 17.92 10.24 17.92 9.81333334 17.885866659999998 9.38666666 17.80906666 8.96 17.57866666 8.53333334 17.06666666 8.53333334 17.06666666 8.53333334 L 15.36 8.53333334 15.36 7.68 C 15.36 6.82666666 14.50666666 6.82666666 14.50666666 6.82666666 L 12.8 6.82666666 12.8 5.97333334 C 12.8 5.12 11.94666666 5.12 11.94666666 5.12 L 11.09333334 5.12 11.09333334 3.41333334 C 11.09333334 2.56 10.24 2.56 10.24 2.56 M 8.10666666 5.12 C 8.81493334 5.12 9.38666666 5.69173334 9.38666666 6.4 9.38666666 7.108266660000001 8.81493334 7.68 8.10666666 7.68 7.3984000000000005 7.68 6.82666666 7.108266660000001 6.82666666 6.4 6.82666666 5.69173334 7.3984000000000005 5.12 8.10666666 5.12 M 5.54666666 8.53333334 C 6.25493334 8.53333334 6.82666666 9.10506666 6.82666666 9.81333334 6.82666666 10.521600000000001 6.25493334 11.09333334 5.54666666 11.09333334 4.8384 11.09333334 4.26666666 10.521600000000001 4.26666666 9.81333334 4.26666666 9.10506666 4.8384 8.53333334 5.54666666 8.53333334 M 9.81333334 9.38666666 C 10.521600000000001 9.38666666 11.09333334 9.958400000000001 11.09333334 10.66666666 11.09333334 11.37493334 10.521600000000001 11.94666666 9.81333334 11.94666666 9.10506666 11.94666666 8.53333334 11.37493334 8.53333334 10.66666666 8.53333334 9.958400000000001 9.10506666 9.38666666 9.81333334 9.38666666 M 14.08 11.09333334 C 14.78826666 11.09333334 15.36 11.66506666 15.36 12.373333339999999 15.36 13.081600000000002 14.78826666 13.65333334 14.08 13.65333334 L 14.08 13.65333334 C 13.37173334 13.65333334 12.8 13.081600000000002 12.8 12.373333339999999 L 12.8 12.373333339999999 C 12.8 11.66506666 13.37173334 11.09333334 14.08 11.09333334 M 9.38666666 13.65333334 C 10.09493334 13.65333334 10.66666666 14.22506666 10.66666666 14.933333339999999 10.66666666 15.6416 10.09493334 16.21333334 9.38666666 16.21333334 8.6784 16.21333334 8.10666666 15.6416 8.10666666 14.933333339999999 8.10666666 14.22506666 8.6784 13.65333334 9.38666666 13.65333334 Z')
path4.setAttribute('fill', '#fff');
deleteAll.appendChild(path4);
deleteAll.id = 'deleteAll';
document.body.appendChild(deleteAll);
}
addRightButton ()
window.addEventListener('load', function(){
var cover_1=document.querySelector(".fvHsDQ")
var cover_2=document.querySelector(".hYvGvO")
var cover_3=document.querySelector(".cSAnog")
if(cover_2!=null){
cover_2.remove()
cover_1.style.position="unset";
cover_3.style.whiteSpace="unset"
var text=cover_3.innerHTML
cover_3.innerHTML="<strong>"+cover_3.innerHTML+"</strong>"
}
})
window.addEventListener('contextmenu',function (event){
//————————————————————————————————
//————————————————————————————————
var el=event.target
if(el!=null){
var url,pid,HTML,results
if(event.ctrlKey==true&&event.altKey!=true){
HTML=el.outerHTML
for(var i in match_rules){
results=HTML.match(match_rules[i])
if(results!=null&&results.length>1){
url=results[1]
pid=results[2]
break
}
}
//——————————————————————————————————————————————
if(results!=null){
var HTML_1=el.parentNode.previousSibling.childNodes[1]
var HTML_2="no results"
//多张图片打开↓↓↓
if(HTML_1!=undefined){
HTML_2=HTML_1.childNodes[0].childNodes[1].childNodes[0].data
if(HTML_2>=15){
var HTML_3=15
}
else{
HTML_3=HTML_2
}
for(var k=1;k<=HTML_3;k++){
var url_multiple="https://pixiv.cat/"+pid+"-"+k+".png"
window.open(url_multiple)
console.log(url_multiple)
}
}
//单张图片打开↓↓↓
else{
var url_single="https://pixiv.cat/"+pid+".png"
window.open(url_single)
console.log(url_single)
}
}
//——————————————————————————————————————————————
//动态图封面打开↓↓↓
else{
var ans=HTML.split(".jpg")[0]
var ans_1=ans.split("/")[ans.split("/").length-1]
var pid_2=ans_1.split("_")[0]
var url_single_gif="https://pixiv.cat/"+pid_2+".gif"
window.open(url_single_gif)
console.log(url_single_gif)
}
event.preventDefault()
console.log(HTML_2)
//——————————————————————————————————————————————
}
//ctrl事件结束,alt事件开始
if(event.altKey==true&&event.ctrlKey!=true){
HTML=el.outerHTML
for(var u in match_rules){
results=HTML.match(match_rules[u])
if(results!=null&&results.length>1){
url=results[1]
pid=results[2]
break
}
if(results==null){
var ans_alt=HTML.split(".jpg")[0]
var ans_alt1=ans_alt.split("/")[ans_alt.split("/").length-1]
pid=ans_alt1.split("_")[0]
console.log("alt事件pid:"+pid)
}
}
GM_setClipboard(pid);//复制pid至剪切板
//自动收藏↓↓↓
var HTML_click_1=el.parentNode.parentNode.parentNode.childNodes[1]
var HTML_click_2=HTML_click_1.childNodes[0].childNodes[0]
HTML_click_2.click()
event.preventDefault()
console.log("Complete click")
}
}
});
//————————————————————————————————————————————————————————————
var num=0
//————————————————————————————————创建cookie
function setCookie(cname,cvalue,exdays){
var cookie_all=cname
for(var i=0;i<20;i++){
cookie_all=cookie_all+"1"
}
exdays=-1
cookie_all=cname+"="+cvalue+"; "+exdays
var d = new Date();
d.setTime(d.getTime()+(exdays*24*60*60*1000));
var expires = "expires="+d.toGMTString();
document.cookie = cookie_all;
num=num+1
}
//————————————————————————————————调取cookie
function getCookie(cname){
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) {
var c = ca[i].trim();
if (c.indexOf(name)==0){
return c.substring(name.length,c.length);
}
}
return "";
}
//————————————————————————————————使用cookie
function checkCookie(){
window.addEventListener('contextmenu',function (event){
var el=event.target
////////////////////////////////////////////////////////
for(var i in match_rules){
var result=el.outerHTML.match(match_rules[i])
if(result!=null&&result.length>1){
var url_result=result[1]
var pid=result[2]
break
}
}
///////////////////////////////////////////////////////
var picture_num=el.parentNode.previousSibling.childNodes[1]
var picture_num_1="no results"
/*
var HTML_url=window.location.href
var HTML_url_pid=HTML_url.split("/")[HTML_url.split("/").length-1]
*/
if(picture_num!=undefined){
picture_num_1=picture_num.childNodes[0].childNodes[1].innerHTML
}
if(event.altKey==true&&event.ctrlKey!=true){
var url_cat="https://pixiv.cat/"
var url=url_cat
if(picture_num_1!="no results"){
for(var u=0;u<picture_num_1;u++){
if(url!=url_cat){
url=url+","+url_cat+pid+"-"+(u+1)+".png"
}
else{
url=url_cat+pid+"-"+(u+1)+".png"
}
}
}
else{
url=url_cat+pid+".png"
}
url=url+";"
num=lastcookie()
setCookie("pixivid"+num,url,30);
event.preventDefault()
}
var user=getCookie("pixivid");
var x = document.cookie
console.log(x)
})
//————————————————————————————————删除cookie
function delCookie(name){
var date = new Date();
date.setTime(date.getTime() - 10000);
document.cookie = name + "=a; expires=" + date.toGMTString();
}
//————————————————————————————————
window.addEventListener('contextmenu',function (event){
if(event.ctrlKey==true&&event.altKey==true){
//————————————————————————————————下载txt
function download(filename, text) {
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
//————————————————————————————————
var cookie_split=document.cookie.split(";")
var cookie_txt
var p=0
//————————————————————————————————从cookie中匹配pixivid相关cookie
for(var k=0;k<cookie_split.length;k++){
var cookie_match=cookie_split[k].match("pixivid")
if(cookie_match!=null){
var cookie_url=cookie_match.input.split("=")[1]
var cookie_url_split=cookie_url.split(",")
var cookie_url_recombine=cookie_url_split[0]
for(var y=1;y<cookie_url_split.length;y++){
cookie_url_recombine=cookie_url_recombine+"\n"+cookie_url_split[y]
}
if(cookie_txt!=null){
cookie_txt=cookie_txt+cookie_url_recombine+"\n"
p++
}
else{
cookie_txt=cookie_url_recombine+"\n"
}
event.preventDefault()
}
}
download("Pixiv Url.txt",cookie_txt);
for(var o=0;o<p+1;o++){
var pixiv_preurl
if(pixiv_preurl==null){
pixiv_preurl=getCookie("pixivid"+o)+","
}
else{
pixiv_preurl=pixiv_preurl+getCookie("pixivid"+o)+","
}
delCookie("pixivid"+o)
}
setCookie("pixiv_preurl",pixiv_preurl,-1)
}
})
rightButton.addEventListener('mouseenter',()=>{
myMove()
})
rightButton.addEventListener('mouseleave',()=>{
myOut()
})
deleteCookie.addEventListener('mouseenter',()=>{
delMove()
})
deleteCookie.addEventListener('mouseleave',()=>{
delOut()
})
deleteAll.addEventListener('mouseenter',()=>{
redMove()
})
deleteAll.addEventListener('mouseleave',()=>{
redOut()
})
rightButton.addEventListener('click',()=>{
function download(filename, text) {
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
var cookie_split=document.cookie.split(";")
var cookie_txt
var p=0
//————————————————————————————————从cookie中匹配pixivid相关cookie
for(var k=0;k<cookie_split.length;k++){
var cookie_match=cookie_split[k].match("pixivid")
if(cookie_match!=null){
var cookie_url=cookie_match.input.split("=")[1]
var cookie_url_split=cookie_url.split(",")
var cookie_url_recombine=cookie_url_split[0]
for(var y=1;y<cookie_url_split.length;y++){
cookie_url_recombine=cookie_url_recombine+"\n"+cookie_url_split[y]
}
if(cookie_txt!=null){
cookie_txt=cookie_txt+cookie_url_recombine+"\n"
p++
}
else{
cookie_txt=cookie_url_recombine+"\n"
}
event.preventDefault()
}
}
for(var f=0;k<cookie_split.length;k++){
cookie_match=cookie_split[k].match("pixivid")
if(cookie_match!=null){
cookie_url=cookie_match.input.split("=")[1]
cookie_url_split=cookie_url.split(",")
cookie_url_recombine=cookie_url_split[0]
for(var o=1;y<cookie_url_split.length;y++){
cookie_url_recombine=cookie_url_recombine+"\n"+cookie_url_split[y]
}
if(cookie_txt!=null){
cookie_txt=cookie_txt+cookie_url_recombine+"\n"
p++
}
else{
cookie_txt=cookie_url_recombine+"\n"
}
event.preventDefault()
}
}
download("Pixiv Url.txt",cookie_txt);
for(o=0;o<p+1;o++){
var pixiv_preurl
if(pixiv_preurl==null){
pixiv_preurl=getCookie("pixivid"+o)+","
}
else{
pixiv_preurl=pixiv_preurl+getCookie("pixivid"+o)+","
}
delCookie("pixivid"+o)
}
setCookie("pixiv_preurl",pixiv_preurl,-1)
})
deleteCookie.addEventListener('click',()=>{
var pid_num=lastcookie()
delCookie("pixivid"+(pid_num-1))
})
deleteAll.addEventListener('click',()=>{
var pid_num=lastcookie()
if(alert_count==0){
alert("是否要清除所有已储存的pixiv图片链接?\n关闭此提示后再次点击清楚按钮即可清除。")
alert_count=1
}
else if(alert_count==1){
for(var v=pid_num-1;v>=0;v--){
var pixiv_preurl
if(pixiv_preurl==null){
pixiv_preurl=getCookie("pixivid"+v)+","
}
else{
pixiv_preurl=pixiv_preurl+getCookie("pixivid"+v)+","
}
delCookie("pixivid"+(v))
}
setCookie("pixiv_preurl",pixiv_preurl,-1)
alert("已清除所有pixiv图片链接")
alert_count=0
}
})
}
checkCookie()
//————————————————————————————————————————————————————————————
})();