解决的问题:
当前微博的图片无法将链接直接作为外部直链使用,需要稍加转换后使用。故开发此脚本,方便获取图片直链。使用此脚本后:右击即可获取到图片直链。
配置完毕后使用方法:
在“我的相册”tab中,右击图片,即可将转换后的直链粘贴到剪切板
配置方式:
1.先决条件:浏览器安装油猴脚本
2.新建脚本,导入以下代码并保存
// ==UserScript==
// @name 微博图片链接转直链
// @namespace http://tampermonkey.net/
// @version 2025-12-11
// @description try to take over the world!
// @author You
// @match https://photo.weibo.com/*/photos
// @icon https://www.google.com/s2/favicons?sz=64&domain=weibo.com
// @grant none
// ==/UserScript==
(function() {
'use strict';
let imgIdReg = /^.*\/(.*?)$/
const parseUrl = (originUrl)=>{
if(originUrl == null || originUrl == ''){
return
}
let matchRes = originUrl.match(imgIdReg)
if(matchRes == null || matchRes.length != 2){
return
}
let imgSuffix = matchRes[1]
let res = "https://cdn.cdnjson.com/pic.html?url=tvax3.sinaimg.cn/large/"+imgSuffix;
console.log(res)
navigator.clipboard.writeText(res)
}
window.addEventListener('load', () => {
let photoContainerOuter = document.querySelector(".m_photo_list_a")
if(photoContainerOuter == null){
console.log("图片外部未找到")
return
}
function parseChatData() {
let imgs = document.querySelectorAll(".photoList img")
console.log(imgs)
if(imgs == null || imgs.length == 0){
return
}
for(let img of imgs){
img.addEventListener('contextmenu',(e)=>{
parseUrl(e.target.getAttribute('src'))
e.preventDefault()
})
}
}
const observer = new MutationObserver((mutationsList) => {
parseChatData(); // 解析详细数据
});
const observerConfig = {
childList: true, // 监听子节点变化
subtree: true // 监听所有后代节点
};
observer.observe(photoContainerOuter, observerConfig);
})
// Your code here...
})();
评论区