optimize: github油猴脚本,文件列表左边的☁️图标,点击直接下载,而不是在浏览器打开浏览。
parent
8c3f47e1c9
commit
1fbe260c4f
|
@ -248,6 +248,13 @@ module.exports = {
|
||||||
abort: true,
|
abort: true,
|
||||||
desc: '广告拦截'
|
desc: '广告拦截'
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
'*': {
|
||||||
|
'^.*\\?DS_DOWNLOAD$': {
|
||||||
|
requestReplace: { doDownload: true },
|
||||||
|
responseReplace: { doDownload: true },
|
||||||
|
desc: '下载请求拦截:移除请求地址中的 `?DS_DOWNLOAD`,并设置响应头 `Content-Disposition: attachment; filename=xxxx`,使浏览器强制执行下载逻辑,而不是在浏览器中浏览。'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
whiteList: {
|
whiteList: {
|
||||||
|
|
|
@ -378,7 +378,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
url_name = raw_url[menu_rawFast][1]; url_tip = raw_url[menu_rawFast][2];
|
url_name = raw_url[menu_rawFast][1]; url_tip = raw_url[menu_rawFast][2];
|
||||||
fileElm.insertAdjacentHTML('afterend', `<a href="${url}" download="${Name}" target="_blank" rel="noreferrer noopener nofollow" class="fileDownLink" style="display: none;" title="「${url_name}」 左键点击下载文件(注意:鼠标点击 [☁] 图标进行下载,而不是文件名!) ${url_tip} 提示:点击页面右侧飘浮着的 TamperMonkey 扩展图标 - [ ${raw_url[menu_rawFast][1]} ] 加速源 (☁) 即可切换。">${svg[0]}</a>`);
|
fileElm.insertAdjacentHTML('afterend', `<a href="${url}?DS_DOWNLOAD" download="${Name}" target="_blank" rel="noreferrer noopener nofollow" class="fileDownLink" style="display: none;" title="「${url_name}」 左键点击下载文件(注意:鼠标点击 [☁] 图标进行下载,而不是文件名!) ${url_tip} 提示:点击页面右侧飘浮着的 TamperMonkey 扩展图标 - [ ${raw_url[menu_rawFast][1]} ] 加速源 (☁) 即可切换。">${svg[0]}</a>`);
|
||||||
// 绑定鼠标事件
|
// 绑定鼠标事件
|
||||||
trElm.onmouseover = mouseOverHandler;
|
trElm.onmouseover = mouseOverHandler;
|
||||||
trElm.onmouseout = mouseOutHandler;
|
trElm.onmouseout = mouseOutHandler;
|
||||||
|
|
|
@ -36,9 +36,10 @@ module.exports = {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 替换下载文件请求的请求地址(此功能主要是为了方便拦截配置)
|
// 替换下载文件请求的请求地址(此功能主要是为了方便拦截配置)
|
||||||
if (requestReplaceConfig.doDownload && rOptions.path.indexOf('?DS_DOWNLOAD') >= 0) {
|
// 注:要转换为下载请求,需要 responseReplace 拦截器的配合使用。
|
||||||
|
if (requestReplaceConfig.doDownload && rOptions.path.match(/DS_DOWNLOAD/i)) {
|
||||||
rOptions.doDownload = true
|
rOptions.doDownload = true
|
||||||
rOptions.path = rOptions.path.replace('?DS_DOWNLOAD', '')
|
rOptions.path = rOptions.path.replace(/[?&/]?DS_DOWNLOAD(=[^?&/]+)?$/gi, '')
|
||||||
actions += (actions ? ',' : '') + 'path:remove-DS_DOWNLOAD'
|
actions += (actions ? ',' : '') + 'path:remove-DS_DOWNLOAD'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,7 +68,7 @@ module.exports = {
|
||||||
let actions = ''
|
let actions = ''
|
||||||
|
|
||||||
// 处理文件下载请求
|
// 处理文件下载请求
|
||||||
if (responseReplaceConfig.doDownload && rOptions.doDownload) {
|
if (responseReplaceConfig.doDownload || rOptions.doDownload) {
|
||||||
const filename = (rOptions.path.match('^.*/([^/?]+)/?(\\?.*)?$') || [])[1] || 'UNKNOWN_FILENAME'
|
const filename = (rOptions.path.match('^.*/([^/?]+)/?(\\?.*)?$') || [])[1] || 'UNKNOWN_FILENAME'
|
||||||
res.setHeader('Content-Disposition', 'attachment; filename=' + filename)
|
res.setHeader('Content-Disposition', 'attachment; filename=' + filename)
|
||||||
actions += 'download:' + filename
|
actions += 'download:' + filename
|
||||||
|
|
|
@ -159,6 +159,7 @@ module.exports = function createRequestHandler (createIntercepts, middlewares, e
|
||||||
resolve(proxyRes)
|
resolve(proxyRes)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 代理请求的事件监听
|
||||||
proxyReq.on('timeout', () => {
|
proxyReq.on('timeout', () => {
|
||||||
const end = new Date().getTime()
|
const end = new Date().getTime()
|
||||||
const cost = end - start
|
const cost = end - start
|
||||||
|
@ -170,7 +171,6 @@ module.exports = function createRequestHandler (createIntercepts, middlewares, e
|
||||||
error.status = 408
|
error.status = 408
|
||||||
reject(error)
|
reject(error)
|
||||||
})
|
})
|
||||||
|
|
||||||
proxyReq.on('error', (e) => {
|
proxyReq.on('error', (e) => {
|
||||||
const end = new Date().getTime()
|
const end = new Date().getTime()
|
||||||
const cost = end - start
|
const cost = end - start
|
||||||
|
@ -178,7 +178,6 @@ module.exports = function createRequestHandler (createIntercepts, middlewares, e
|
||||||
countSlow(isDnsIntercept, 'error:' + e.message)
|
countSlow(isDnsIntercept, 'error:' + e.message)
|
||||||
reject(e)
|
reject(e)
|
||||||
})
|
})
|
||||||
|
|
||||||
proxyReq.on('aborted', () => {
|
proxyReq.on('aborted', () => {
|
||||||
const end = new Date().getTime()
|
const end = new Date().getTime()
|
||||||
const cost = end - start
|
const cost = end - start
|
||||||
|
|
Loading…
Reference in New Issue