optimize: github油猴脚本,文件列表左边的☁️图标,点击直接下载,而不是在浏览器打开浏览。

pull/301/head
王良 2024-04-19 15:47:06 +08:00
parent 8c3f47e1c9
commit 1fbe260c4f
5 changed files with 13 additions and 6 deletions

View File

@ -248,6 +248,13 @@ module.exports = {
abort: true,
desc: '广告拦截'
}
},
'*': {
'^.*\\?DS_DOWNLOAD$': {
requestReplace: { doDownload: true },
responseReplace: { doDownload: true },
desc: '下载请求拦截:移除请求地址中的 `?DS_DOWNLOAD`,并设置响应头 `Content-Disposition: attachment; filename=xxxx`,使浏览器强制执行下载逻辑,而不是在浏览器中浏览。'
}
}
},
whiteList: {

View File

@ -378,7 +378,7 @@
}
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}」&#10;&#10;左键点击下载文件(注意:鼠标点击 [☁] 图标进行下载,而不是文件名!)&#10;&#10;${url_tip}&#10;&#10;提示:点击页面右侧飘浮着的 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}」&#10;&#10;左键点击下载文件(注意:鼠标点击 [☁] 图标进行下载,而不是文件名!)&#10;&#10;${url_tip}&#10;&#10;提示:点击页面右侧飘浮着的 TamperMonkey 扩展图标 - [ ${raw_url[menu_rawFast][1]} ] 加速源 (☁) 即可切换。">${svg[0]}</a>`);
// 绑定鼠标事件
trElm.onmouseover = mouseOverHandler;
trElm.onmouseout = mouseOutHandler;

View File

@ -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.path = rOptions.path.replace('?DS_DOWNLOAD', '')
rOptions.path = rOptions.path.replace(/[?&/]?DS_DOWNLOAD(=[^?&/]+)?$/gi, '')
actions += (actions ? ',' : '') + 'path:remove-DS_DOWNLOAD'
}

View File

@ -68,7 +68,7 @@ module.exports = {
let actions = ''
// 处理文件下载请求
if (responseReplaceConfig.doDownload && rOptions.doDownload) {
if (responseReplaceConfig.doDownload || rOptions.doDownload) {
const filename = (rOptions.path.match('^.*/([^/?]+)/?(\\?.*)?$') || [])[1] || 'UNKNOWN_FILENAME'
res.setHeader('Content-Disposition', 'attachment; filename=' + filename)
actions += 'download:' + filename

View File

@ -159,6 +159,7 @@ module.exports = function createRequestHandler (createIntercepts, middlewares, e
resolve(proxyRes)
})
// 代理请求的事件监听
proxyReq.on('timeout', () => {
const end = new Date().getTime()
const cost = end - start
@ -170,7 +171,6 @@ module.exports = function createRequestHandler (createIntercepts, middlewares, e
error.status = 408
reject(error)
})
proxyReq.on('error', (e) => {
const end = new Date().getTime()
const cost = end - start
@ -178,7 +178,6 @@ module.exports = function createRequestHandler (createIntercepts, middlewares, e
countSlow(isDnsIntercept, 'error:' + e.message)
reject(e)
})
proxyReq.on('aborted', () => {
const end = new Date().getTime()
const cost = end - start