first commit

This commit is contained in:
编码猿
2024-09-27 01:07:59 +08:00
commit 6cd216628a
162 changed files with 21879 additions and 0 deletions

View File

@@ -0,0 +1 @@
9ee1ce08-fc01-4056-82ff-1b02b4bc49ab

128
static/page-script/500px.js Executable file
View File

@@ -0,0 +1,128 @@
const { ipcRenderer } = require('electron')
const axios = require('axios')
const { render } = require('./render')
const apiAddress = 'https://api.500px.com/v1/photos'
const getDownloadUrl = id => new Promise((resolve, reject) => {
axios.get(apiAddress, {
params: {
image_size: [1600, 2048, 2500, 3000, 4096, 4500, 5120, 5500, 6144, 7168],
ids: id,
},
responseType: 'json',
headers: {
Accept: 'application/json',
}
}).then((res) => {
if (res.status === 200){
const { photos } = res.data
const imageInfo = photos[id]
let maxSize = 0
let downloadUrl = ''
for (let i = 0; i < imageInfo.image_url.length; i++) {
const imagePath = imageInfo.image_url[i]
const realSize = imagePath.match(/m%3D(\d*)/)
if (realSize && realSize[1]){
const size = parseInt(realSize[1], 10)
if (size > maxSize) {
downloadUrl = imagePath
}
maxSize = size
}
}
resolve(downloadUrl)
} else {
reject()
}
}).catch(() => {
reject()
})
})
const isImg = target => (target.tagName === 'A' && target.parentNode.className.includes('photo_thumbnail'))
|| (target.tagName === 'IMG' && target.className === 'photo-show__img')
const mouseoverFn = function (e){
const { target } = e
if (isImg(target)){
const { parentNode } = target
if (!parentNode.addChild){
let href = ''
if (target.tagName === 'A'){
href = target.getAttribute('href')
}
else if (target.tagName === 'IMG'){
href = target.getAttribute('src')
}
const idMatches = href.match(/photo\/(\d*)\//)
let id = ''
if (idMatches && idMatches[1]){
[, id] = idMatches
}
const downloadFile = function (event){
event.stopPropagation()
event.preventDefault()
ipcRenderer.sendToHost('notify', {
type: 'info',
title: '提示',
message: '正在解析下载地址,请等待...'
})
getDownloadUrl(id).then((res) => {
ipcRenderer.sendToHost('download', { downloadUrl: res })
})
}
const setWallpaper = function (event){
event.stopPropagation()
event.preventDefault()
ipcRenderer.sendToHost('notify', {
type: 'info',
title: '提示',
message: '正在解析下载地址,请等待...'
})
getDownloadUrl(id).then((res) => {
ipcRenderer.sendToHost('setWallpaper', { downloadUrl: res })
})
}
const options = {
downloadFile,
setWallpaper,
}
parentNode.addChild = render(options)
if (target.tagName === 'IMG'){
parentNode.addChild.style.left = '50%'
parentNode.addChild.style.top = '50%'
}
else {
parentNode.addChild.style.left = 0
}
parentNode.appendChild(parentNode.addChild)
}
}
}
const mouseoutFn = function (e){
const { target } = e
if (isImg(target)){
const { parentNode } = target
if (parentNode.addChild){
window.setTimeout(() => {
if (!parentNode.addChild.mouseoverFlag){
parentNode.removeChild(parentNode.addChild)
parentNode.addChild = null
}
}, 50)
}
}
}
ipcRenderer.on('dom-ready', () => {
console.log('================500px-load')
document.querySelector('body').addEventListener('mouseover', mouseoverFn, false)
document.querySelector('body').addEventListener('mouseout', mouseoutFn, false)
})

48
static/page-script/nasa.js Executable file
View File

@@ -0,0 +1,48 @@
const { ipcRenderer } = require('electron')
const { render } = require('./render')
const PUBLICURL = '/sites/default/files/styles/image_card_4x3_ratio/public/'
const DOWNLOADPUBLICURL = '/sites/default/files/'
const isImg = target => target.tagName === 'IMG' && target.parentNode.className === 'image'
const mouseoverFn = function (e){
const { target } = e
if (isImg(target)){
const { parentNode } = target
window.setTimeout(() => {
if (!parentNode.addChild){
const src = target.getAttribute('src')
const options = {
width: 0,
height: 0,
url: src,
downloadUrl: `https://www.nasa.gov${src.replace(PUBLICURL, DOWNLOADPUBLICURL)}`
}
parentNode.addChild = render(options)
parentNode.appendChild(parentNode.addChild)
}
}, 80)
}
}
const mouseoutFn = function (e){
const { target } = e
if (isImg(target)){
const { parentNode } = target
if (parentNode.addChild){
window.setTimeout(() => {
if (!parentNode.addChild.mouseoverFlag){
parentNode.removeChild(parentNode.addChild)
parentNode.addChild = null
}
}, 80)
}
}
}
ipcRenderer.on('dom-ready', () => {
console.log('================nasa-load')
document.querySelector('body').addEventListener('mouseover', mouseoverFn, false)
document.querySelector('body').addEventListener('mouseout', mouseoutFn, false)
})

40
static/page-script/pexels.js Executable file
View File

@@ -0,0 +1,40 @@
const { ipcRenderer } = require('electron')
const { render } = require('./render')
const isImg = target => target.tagName === 'IMG' && ['photo-item__img'].includes(target.className)
const mouseoverFn = function (e){
const { target } = e
if (isImg(target)){
const imgParent = target.parentNode
if (!imgParent.addChild){
const options = {
width: target.getAttribute('data-image-width'),
height: target.getAttribute('data-image-height'),
url: target.getAttribute('data-large-src'),
downloadUrl: target.getAttribute('data-big-src').split('?')[0]
}
imgParent.addChild = render(options)
imgParent.appendChild(imgParent.addChild)
}
}
}
const mouseoutFn = function (e){
const { target } = e
if (isImg(target)){
const imgParent = target.parentNode
if (imgParent.addChild){
window.setTimeout(() => {
if (!imgParent.addChild.mouseoverFlag){
imgParent.removeChild(imgParent.addChild)
imgParent.addChild = null
}
}, 40)
}
}
}
ipcRenderer.on('dom-ready', () => {
document.querySelector('body').addEventListener('mouseover', mouseoverFn, false)
document.querySelector('body').addEventListener('mouseout', mouseoutFn, false)
})

98
static/page-script/render.js Executable file
View File

@@ -0,0 +1,98 @@
/* eslint-disable max-len */
const { ipcRenderer } = require('electron')
const iconDownload = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAABS0lEQVQ4T72TsU7DMBCGfU6y8gzMPAFMLQMbYqpjRQoLAwtiYIWhzcATsDExRIpsZ0SslAkeg2dgjeNDjmIprZLWkQJeklj2d3/++w/IxAsm5hEvoFKK2cKMMbVPgBdQCLGyIM5589y1/haY5/lBFEUnlNJjrfVHkiRrq2ZbYVEU8zAMZ8aYr6qqPtM0/XGqNxTai5TShTGmNMasdwEppXN3tmvFBlAp9a61zhzIVVVKLdumZF3/WqVLxthpr8Ih4FBTpJQXAHDnBbTVgyB4ruv62vplFVhf3Z79CynlJQBceQFdMwDgAREf7bd7d56VZXmDiAtvYAfaeIiIWbcBQoh7SunZKGBfbFwD2lTMRgOHJuP/gUIICQBvcRy/7JvZjhVHnPN4KIfniPhECDn0ARJCvgHgljH22gt0mzaDPsDtiWqi5XNxzJnJgb8whuUV13+BlgAAAABJRU5ErkJggg=='
const iconDownloadHover = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAABF0lEQVQ4T72TMU4DMRBF378AZ6DmBFAFCjpEBeloKGhQClooQgpOQEdFDSkRLUkFx+AMucBHtryRE+1ir7QwjS3LfvP9Z0YMHBqYRxXQ9nlILOm1JKAWeJ+Acf0t/hZoewc4APaBpaRFUGN7Q6HtQ2AEfAGfklaN6g2F6eEZMAcWBWCAxruS1lZsAz+AWQNqstqeJg9nuX9J6VTSUZfCLmBrUWyfAjdVwJT9CbhKfgURSyCehV/YvgAuq4BZMe6Ah/SluG88s30dfKwGZtDoYfJ3XQDbt8BxL2Bb22TFCvBRb2DXZKQ2+1/gC/Au6bk0s5kVe5LGXX14AjwCuzVA4BuYSHprBWZmh7EqxvZExWkqvup5YXDgD/V/oxUurSvtAAAAAElFTkSuQmCC'
const iconWallpaper = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAABQ0lEQVQ4T7XUsUrDUBQG4P8k6eZj6FJfQai4ueeeSzcfQVwVSsEn8Ams4JATcHDQsYrgAzi4uLgKoiCOjb/c1pQaLG1DvEvIublf/tyTRNDwkIY9TME8z3sAtmdvQPKFZCQiMYCIZCwiEYDxMZyHOoA7VQ3rJ6CZ7QHoiciRc+58ldRmtg7gOoqi4zRNByV4CeBCVU9Xwcpr8zzfJXmlqlKCw6Io+t1u96YOGNZkWfbovW83CX5679caA82MjT7y/4Micuicu6/blD8T1sXCujiOh7/2UCZvUO1BMjRlZ6xkWXYiIl+qul9HNLMzkq/e+4NpLDN7AvBM8n0VVEQ+AHRUdWP6LZeAmW0VRZFUwSRJOqE2Go1uq3OtVustTdOHsr7Uxv38ieCc6y9KPxc0s7aIGMnNKhK6OQ9eKuGiVLPzjYPfQXGrFUxePR0AAAAASUVORK5CYII='
const iconWallpaperHover = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAA/UlEQVQ4T7XUMUrEQBSH8e9TS4+hzXoFYcXOW3iExVZBFjyBJ1DBxsLCQstdETyAhY2NrSAKYu2TYGYJMZJNdpwm8Cbzm38yvJHMw8weMzAiDoGt2gYvwBKw3PK8U4v1P2BE7AJF4UA975I6ItaAG+BIPU3gFXCpnnTB0rsRsQNcW4wy4QQYq9M+YGk8qoOc4Ke6mhOM3J/8/+C+er/AofxO2Bcr103q/3BBjyLhdjrlY+BLHfVRI+IMeFX3qr38BDwD7x3RD2Cors96udJCm8BKAzgsa7cNc2/qQ6rPdX2VNxHquC39n2BEDIALYKOOpDugCZ8rYVuq6nx28BvGs3gV89CM0AAAAABJRU5ErkJggg=='
const render = (options) => {
const downloadFile = function (e){
e.stopPropagation()
e.preventDefault()
ipcRenderer.sendToHost('notify', {
type: 'info',
title: '提示',
message: '正在准备,请等待...'
})
ipcRenderer.sendToHost('download', { ...options })
}
const setWallpaper = function (e){
e.stopPropagation()
e.preventDefault()
ipcRenderer.sendToHost('notify', {
type: 'info',
title: '提示',
message: '正在准备,请等待...'
})
ipcRenderer.sendToHost('setWallpaper', { ...options })
}
const btnMouseOver = function (e, icon){
const { target } = e
target.style.color = '#ffffff'
target.style.background = `url(${icon}) no-repeat center center`
}
const btnMouseLeave = function (e, icon){
const { target } = e
target.style.color = '#bbbbbb'
target.style.background = `url(${icon}) no-repeat center center`
}
const dom = document.createElement('div')
const btnDownload = document.createElement('div')
btnDownload.setAttribute('title', '点击下载')
const btnWallpaper = document.createElement('div')
btnWallpaper.setAttribute('title', '设置壁纸')
const btnCssText = 'width:50px;height:100%;color:#bbb;cursor:default;font-size:20px;'
btnDownload.style.cssText = btnCssText
btnWallpaper.style.cssText = btnCssText
dom.style.cssText = 'display:flex; position:absolute;z-index:1; right:0;top:0; align-items:center; width:100px;height:40px;background-color:#222;'
btnDownload.onclick = null
btnDownload.onclick = options.downloadFile || downloadFile
btnDownload.onmouseover = (e) => { btnMouseOver(e, iconDownloadHover) }
btnDownload.onmouseleave = (e) => { btnMouseLeave(e, iconDownload) }
btnWallpaper.onclick = null
btnWallpaper.onclick = options.setWallpaper || setWallpaper
btnWallpaper.onmouseover = (e) => { btnMouseOver(e, iconWallpaperHover) }
btnWallpaper.onmouseleave = (e) => { btnMouseLeave(e, iconWallpaper) }
dom.appendChild(btnDownload)
dom.appendChild(btnWallpaper)
btnDownload.style.background = `url(${iconDownload}) no-repeat center center`
btnWallpaper.style.background = `url(${iconWallpaper}) no-repeat center center`
dom.className = 'wallpaper-ctrl'
dom.onmouseover = function (e){
e.stopPropagation()
e.preventDefault()
dom.mouseoverFlag = true
return false
}
dom.onmouseout = function (e){
e.stopPropagation()
e.preventDefault()
dom.mouseoverFlag = false
return false
}
return dom
}
module.exports = {
render
}

View File

@@ -0,0 +1,43 @@
const { ipcRenderer } = require('electron')
const { render } = require('./render')
const isImg = target => target.tagName === 'IMG' && target.parentNode.tagName === 'A' && target.parentNode.parentNode.className === 'image_content'
const mouseoverFn = function (e){
const { target } = e
if (isImg(target)){
const { parentNode } = target.parentNode
if (!parentNode.addChild){
const src = target.parentNode.getAttribute('href')
const options = {
width: 0,
height: 0,
url: src,
downloadUrl: src,
}
parentNode.addChild = render(options)
parentNode.appendChild(parentNode.addChild)
}
}
}
const mouseoutFn = function (e){
const { target } = e
if (isImg(target)){
const { parentNode } = target.parentNode
if (parentNode.addChild){
window.setTimeout(() => {
if (!parentNode.addChild.mouseoverFlag){
parentNode.removeChild(parentNode.addChild)
parentNode.addChild = null
}
}, 50)
}
}
}
ipcRenderer.on('dom-ready', () => {
console.log('================them-load')
document.querySelector('body').addEventListener('mouseover', mouseoverFn, false)
document.querySelector('body').addEventListener('mouseout', mouseoutFn, false)
})

45
static/page-script/unsplash.js Executable file
View File

@@ -0,0 +1,45 @@
const { ipcRenderer } = require('electron')
const { render } = require('./render')
const isImg = target => target.tagName === 'IMG' && target.getAttribute('srcset')
const mouseoverFn = function (e){
const { target } = e
if (isImg(target)){
const { parentNode } = target
if (!parentNode.addChild){
const srcList = target.getAttribute('srcset').split(', ')
const src = srcList[srcList.length - 1]
const options = {
width: 0,
height: 0,
url: src,
downloadUrl: src.split(' ')[0].split('?')[0],
}
parentNode.addChild = render(options)
parentNode.addChild.style.left = 0
parentNode.appendChild(parentNode.addChild)
}
}
}
const mouseoutFn = function (e){
const { target } = e
if (isImg(target)){
const { parentNode } = target
if (parentNode.addChild){
window.setTimeout(() => {
if (!parentNode.addChild.mouseoverFlag){
parentNode.removeChild(parentNode.addChild)
parentNode.addChild = null
}
}, 80)
}
}
}
ipcRenderer.on('dom-ready', () => {
console.log('================un-load')
document.querySelector('body').addEventListener('mouseover', mouseoverFn, false)
document.querySelector('body').addEventListener('mouseout', mouseoutFn, false)
})

50
static/page-script/wallhaven.js Executable file
View File

@@ -0,0 +1,50 @@
const { ipcRenderer } = require('electron')
const { render } = require('./render')
const isImg = target => target.tagName === 'A' && target.parentNode.tagName === 'FIGURE'
const mouseoverFn = function (e){
const { target } = e
if (isImg(target)){
const { parentNode } = target
if (!parentNode.addChild){
const node = parentNode
const wallpaperId = node.getAttribute('data-wallpaper-id')
const url = node.querySelector('img').getAttribute('data-src')
const isPng = Boolean(node.querySelector('.png'))
const [width, height] = node.querySelector('.wall-res').innerHTML.split('x')
const downloadUrl = `https://w.wallhaven.cc/full/${wallpaperId.slice(0, 2)}/wallhaven-${wallpaperId}.${isPng ? 'png' : 'jpg'}`
const options = {
width: width.trim(),
height: height.trim(),
url,
downloadUrl,
}
parentNode.addChild = render(options)
parentNode.addChild.style.zIndex = '9999'
parentNode.appendChild(parentNode.addChild)
}
}
}
const mouseoutFn = function (e){
const { target } = e
if (isImg(target)){
const { parentNode } = target
if (parentNode.addChild){
window.setTimeout(() => {
if (!parentNode.addChild.mouseoverFlag){
parentNode.removeChild(parentNode.addChild)
parentNode.addChild = null
}
}, 80)
}
}
}
ipcRenderer.on('dom-ready', () => {
console.log('================wall-load')
document.querySelector('body').addEventListener('mouseover', mouseoverFn, false)
document.querySelector('body').addEventListener('mouseout', mouseoutFn, false)
})