// ==UserScript== // @name Download Original Picture // @name:zh-CN 下载原始图片 // @description A tool to help you download full size images from websites // @description:zh-CN 一个帮你从网站下载原始尺寸图片的工具 // @namespace https://huching.net/ // @version 0.0.4 // @license GPL-3.0 // @icon data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB2aWV3Qm94PSIwIDAgNTA4IDUwOCIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+IDxjaXJjbGUgc3R5bGU9ImZpbGw6I0ZGRDA1QjsiIGN4PSIyNTQiIGN5PSIyNTQiIHI9IjI1NCIvPiA8cGF0aCBzdHlsZT0iZmlsbDojRkZGRkZGOyIgZD0iTTM3Mi44LDE5NkgzNjhjLTIuNC00MC40LTM1LjYtNzIuNC03Ni40LTcyLjRjLTQsMC04LDAuNC0xMS42LDAuOGMtMTYtMjguNC00Ni00Ny42LTgwLjgtNDcuNiBjLTUxLjIsMC05Mi40LDQxLjYtOTIuNCw5Mi40YzAsMTAuOCwyLDIxLjIsNS4yLDMwLjhjLTI1LjIsMTAtNDIuOCwzNC00Mi44LDYyLjRjMCwzNi40LDI5LjYsNjYuNCw2Ni40LDY2LjRoMjM3LjIgYzM2LjQsMCw2Ni40LTI5LjYsNjYuNC02Ni40QzQzOC44LDIyNS42LDQwOS4yLDE5NiwzNzIuOCwxOTZ6Ii8+IDxwYXRoIHN0eWxlPSJmaWxsOiNGRjcwNTg7IiBkPSJNMzI1LjIsMzYyLjRsLTY2LjQsNjYuNGMtMi44LDIuOC03LjIsMi44LTEwLDBsLTY2LTY2LjRjLTQuNC00LjQtMS4yLTEyLDQuOC0xMmgxNC44IGM0LDAsNy4yLTMuMiw3LjItNy4ydi05NmMwLTQsMy4yLTcuMiw3LjItNy4yaDc0LjhjNCwwLDcuMiwzLjIsNy4yLDcuMnY5NmMwLDQsMy4yLDcuMiw3LjIsNy4yaDE0LjggQzMyNi40LDM1MC40LDMyOS42LDM1OCwzMjUuMiwzNjIuNHoiLz4gPC9zdmc+IA== // @author huc < ht@live.se > // @supportURL https://github.com/hz2/user-scripts-and-styles/issues/new // @require https://greasyfork.org/scripts/396752-hx-script-library/code/hx-script-library.js // @resource HxLib https://greasyfork.org/scripts/396752-hx-script-library/code/hx-script-library.js // @contributionURL https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=your.email.here@example.com&item_name=Greasy+Fork+donation // @contributionAmount 5 // @include *://medium.com/* // @include *://twitter.com/* // @include *://mobile.twitter.com/* // @include *://weibo.com/* // @include *://*.weibo.com/* // @include *://*.vmgirls.com/* // @include *://wallpaperhub.app/* // @include *://*.bing.com/* // @include *://*.msn.cn/* // @noframes // @grant unsafeWindow // @grant GM_setClipboard // @grant GM_xmlhttpRequest // @grant GM_openInTab // @grant GM_registerMenuCommand // @grant GM_getValue // @grant GM_setValue // @grant GM_getResourceText // @grant GM_info // @grant GM_addStyle // @downloadURL none // ==/UserScript== const head = document.getElementsByTagName('head'); head[0].insertAdjacentHTML('beforeend', ``); const hostname = window.location.hostname const lastItem = arr => arr.length ? arr[arr.length - 1] : '' const createDomAll = (item, fn) => { let domDL = document.createElement('a'); domDL.className = 'hx-download-original-images-tool' domDL.title = '下载原始图片' item.addEventListener('load', _ => { let link = fn(item.src) domDL.href = link domDL.addEventListener('click', e => openDown(link, e)) }) item.insertAdjacentElement('afterEnd', domDL) } const createDom = (cfg) => { const { parent, link, name, className = '', style = '', postion = 'afterEnd' } = cfg let domDL = document.createElement('a'); Object.assign(domDL, { title: '下载原始图片', className: 'hx-download-original-images-tool ' + className, style: style, href: link, }) const newName = name || lastItem(link.split('/')) domDL.onclick = e => openDown(link, e, newName) const next = parent && parent.nextElementSibling if (next && next.className.includes('hx-download-original-images-tool')) { next = domDL } else { parent.insertAdjacentElement(postion, domDL) } } const updateLink = (dom, link) => { dom.href = link const newName = lastItem(link.split('/')) dom.onclick = e => openDown(link, e, newName) } const init = () => { if (hostname === "twitter.com" || hostname === "mobile.twitter.com") { //twitter window.addEventListener('mouseover', ({ target }) => { const src = target && target.src const parent = target.parentElement const next = parent && parent.nextElementSibling if (target.tagName == 'IMG' && !(next && next.className.includes('hx-download-original-images-tool')) && !/profile_images|video_thumb/g.test(src)) { const link = src.replace(/\&name=\w+/g, '&name=orig') const name = lastItem(link.split('/')).replace(/\?format=(\w+)\&name=orig/g, (_, b) => `.${b}`) const style = 'margin-left: 10px;margin-top: 10px;' const cfg = { parent, link, name, style } createDom(cfg) } }) } else if (hostname.includes('weibo')) { const isWeiboNode = dom => { const getNodeValue = el => el.attributes['node-type'] && el.attributes['node-type'].nodeValue if (getNodeValue(dom.parentElement) === 'artwork_box' || getNodeValue(dom) === 'img_box' || dom.className.includes('woo-picture-main') || dom.className.includes('woo-picture-slot') || dom.className.includes('imgInstance')) { return true } else { return false } } window.addEventListener('mouseover', ({ target }) => { const parent = target.parentElement const next = parent && parent.nextElementSibling if (target.tagName == 'IMG' && isWeiboNode(parent)) { const link = target.src.replace(/orj\d+|mw\d+/g, 'large') if (next && next.className.includes('hx-download-original-images-tool')) { updateLink(next, link) } else { const style = 'top: 40px;right: 10px;' const cfg = { parent, link, style } createDom(cfg) } } }) } else if (hostname === "www.vmgirls.com") { // vmgirls let domDL = document.createElement('a'); domDL.className = 'hx-download-original-images-tool ' domDL.style = 'position: relative;margin-right: 10px;display: inline-block;vertical-align: -20px;' domDL.title = '下载原始图片' domDL.onclick = e => { const list1 = [...document.querySelector('.post').querySelectorAll('a')].filter(x => x.src && x.src.indexOf('static.vmgirls.com/image') !== -1) const list2 = [...document.querySelector('.post-content').querySelectorAll('img')].filter(x => x.src && x.src.indexOf('t.cdn.ink/image') !== -1) const imgList = [...list1, ...list2].map((x, i) => ({ link: x.src && x.src.replace('-scaled', ''), name: `${x.alt || x.title}_${i}.jpg` })) domDL.title += ' ' + imgList.length imgList.forEach(x => openDown(x.link, e, x.name)) const link1 = imgList.map(x => x.link).join('\n') const link2 = imgList.map(x => `aria2c -o ${x.name} ${x.link}`).join('\n') const content = `获取链接 ` window.open(URL.createObjectURL(new Blob([content], {type : 'text/html'}))) } document.querySelector('.main-submenu').insertAdjacentElement('afterBegin', domDL) } else if (hostname === "medium.com") { // medium document.querySelector('article').querySelectorAll('img').forEach(x => (x.width > 80) && createDomAll(x, src => src.replace(/max\/\d+\//g, 'max/30000/'))) } else if (hostname === "wallpaperhub.app") { // wallpaperhub const odomList = [...document.querySelectorAll('.downloadButton')] odomList.forEach(odom => { if (odom) { let link0 = odom.href.split('downloadUrl=')[1] const link = link0 const style = 'position: relative;margin-right: 10px;display: inline-block;vertical-align: -20px;' const cfg = { parent: odom.parentElement.parentElement, link, style, postion: 'beforeBegin' } createDom(cfg) } }) } else if (hostname === "ntp.msn.cn") { // edge 首页 const link = document.querySelector('background-image')._imageSource; const style = 'position: fixed;right: 80px;top: 40px;' const cfg = { parent: document.body, link, className: 'white', style, postion: 'beforeBegin' } createDom(cfg) } else if (hostname === "www.bing.com") { // bing 首页 const orig = document.querySelector('[style*="th?id="]').style.backgroundImage const link = orig.match(/th\?id\=[\w\d\.\-\_]+/g)[0].replace('1920x1080', 'UHD') const name = link && link.split('=')[1] const style = 'position: relative;width: 42px;height: 42px;margin: 0;opacity: .9;' const cfg = { parent: document.querySelector('#id_h'), link, name, className: 'white', style, postion: 'afterBegin' } createDom(cfg) } else if (hostname === "cn.bing.com") { // bing 首页 const link = document.querySelector('#bgImgProgLoad').dataset.ultraDefinitionSrc.split('&')[0]; const name = link && link.split('=')[1] const style = 'position: fixed;right: 225px;bottom: 53px;margin: 0px;width: 64px;height: 64px;z-index: 550;opacity: .9;' const cfg = { parent: document.body, link, name, className: 'white', style, postion: 'beforeBegin' } createDom(cfg) } } setTimeout(() => { init() }, 1500);