Greasy Fork is available in English.
提供 500px 图片保存功能
当前为
// ==UserScript==
// @name 500px 图片下载
// @namespace https://www.yffjglcms.com/
// @version 0.4.1.20210314
// @description 提供 500px 图片保存功能
// @author yffjglcms
// @match https://*.500px.com/photo/*
// @match https://500px.com/photo/*
// @grant none
// @require https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js
// ==/UserScript==
(function() {
'use strict';
// Your code h ere...
// 图片选择器
const imgSelector = ".photo-show__img"
const corsApi = "https://cors.yffjglcms.workers.dev/?url="
// 如果存在则执行
function ifExist(selector, func){
if($(selector)[0]==null)
{
setTimeout( function(){ifExist(selector, func);}, 5000);
}
else
{
func()
}
}
// 添加导出按钮
function addBtn() {
// 下载按钮,导出按钮
$(imgSelector).before(`<div style="display:inline;z-index:999;position: absolute;left: 10%;">
<button class='Elements__OldButton-tze21g-0 czOfbc' style="display: block;" id="saveImg">下载图片</button>
<button class='Elements__OldButton-tze21g-0 czOfbc' style="display: block;" id="openInNewTab">新窗打开</button>
</div>`)
$("body").on("click", "#saveImg", ()=>{
let imgSrc = $(imgSelector).attr("src")
// console.log(imgSrc)
downloadImg(corsApi + encodeURIComponent(imgSrc) + '&filename='+ encodeURIComponent(document.title))
})
$("body").on("click", "#openInNewTab", ()=>{
let imgSrc = $(imgSelector).attr("src")
// console.log(imgSrc)
window.open(imgSrc)
})
}
// 下载图片
function downloadImg(src){
var a=document.createElement('a');
a.href=src
a.download="file";
a.click();
}
// 执行
ifExist(imgSelector, addBtn)
})();