redirect 外链跳转代码
自动跳转(重定向)到目标链接,免去点击步骤。适配了简书、知乎、微博、QQ邮箱、ChinaOBD2.com、ukobd2.com、insulatedpanelsmachinery.com、zobdii.com、QQPC、印象笔记、贴吧、CSDN、YouTube、微信、微信开放社区、开发者知识库、豆瓣、个人图书馆、Pixiv、搜狗、Google、站长之家、OSCHINA、掘金、腾讯文档、pc6下载站、爱发电
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 | // ==UserScript== // @name redirect 外链跳转 // @version 1.23.0 // @description 自动跳转(重定向)到目标链接,免去点击步骤。适配了简书、知乎、微博、QQ邮箱、QQPC、印象笔记、贴吧、CSDN、YouTube、微信、微信开放社区、开发者知识库、豆瓣、个人图书馆、Pixiv、搜狗、Google、站长之家、OSCHINA、掘金、腾讯文档、pc6下载站、爱发电、Gitee // @author sakura-flutter // @namespace https://github.com/sakura-flutter/tampermonkey-scripts // @license GPL-3.0 // @compatible chrome Latest // @compatible firefox Latest // @compatible edge Latest // @run-at document-start // @match *://www.chinaobd2.com* // @match *://link.zhihu.com/* // @match *://t.cn/* // @match *://m.chinaobd2.com* // @match *://mail.qq.com/cgi-bin/* // @match *://c.pc.qq.com/middlem.html* // @match *://app.yinxiang.com/OutboundRedirect.action* // @match *://jump.bdimg.com/safecheck/* // @match *://jump2.bdimg.com/safecheck/* // @match *://www.ukobd2.com/* // @match *://www.youtube.com/redirect* // @match *://weixin110.qq.com/cgi-bin/mmspamsupport-bin/newredirectconfirmcgi* // @match *://developers.weixin.qq.com/community/middlepage/href* // @match *://www.itdaan.com/link/* // @match *://www.douban.com/link2/* // @match *://www.360doc.com/content/* // @match *://www.pixiv.net/jump.php* // @match *://m.sogou.com/*/tc* // @match *://m.sogou.com*/tc* // @match *://www.chinaz.com/go.shtml* // @match *://www.oschina.net/action/GoToLink* // @match *://link.juejin.cn/* // @match *://docs.qq.com/scenario/link.html* // @match *://www.pc6.com/goread.html* // @match *://afdian.net/link* // @match *://gitee.com/link* // @include /^https?:\/\/www\.google\..{2,7}url/ // ==/UserScript== /******/ (() => { // webpackBootstrap /******/ "use strict" ; /******/ // The require scope /******/ var __webpack_require__ = {}; /******/ /************************************************************************/ /******/ /* webpack/runtime/define property getters */ /******/ (() => { /******/ // define getter functions for harmony exports /******/ __webpack_require__.d = (exports, definition) => { /******/ for ( var key in definition) { /******/ if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { /******/ Object.defineProperty(exports, key, { enumerable: true , get: definition[key] }); /******/ } /******/ } /******/ }; /******/ })(); /******/ /******/ /* webpack/runtime/hasOwnProperty shorthand */ /******/ (() => { /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) /******/ })(); /******/ /******/ /* webpack/runtime/make namespace object */ /******/ (() => { /******/ // define __esModule on exports /******/ __webpack_require__.r = (exports) => { /******/ if ( typeof Symbol !== 'undefined' && Symbol.toStringTag) { /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); /******/ } /******/ Object.defineProperty(exports, '__esModule' , { value: true }); /******/ }; /******/ })(); /******/ /************************************************************************/ var __webpack_exports__ = {}; // NAMESPACE OBJECT: ./src/utils/ready-state.js var ready_state_namespaceObject = {}; __webpack_require__.r(ready_state_namespaceObject); __webpack_require__.d(ready_state_namespaceObject, { "DOMContentLoaded" : () => (DOMContentLoaded), "complete" : () => (complete), "interactive" : () => (interactive), "load" : () => (load), "loading" : () => (loading) }); ; // CONCATENATED MODULE: ./src/utils/log.ts const isDebug = "production" !== 'production' ; function warn(...args) { isDebug && console.warn( '%c warn ' , 'background: #ffa500; padding: 1px; color: #fff;' , ...args); } function table(...args) { isDebug && console.table(...args); } ; // CONCATENATED MODULE: ./src/utils/ready-state.js /** * readyState 因为脚本加载时机不一定监听到所有变化 * 所以 pool 中的状态区分先后顺序 * 靠后定义的会自动将靠前定义的但没有监听到的执行一次,但实际上不再是原来的状态 */ const pool = new Map([[ 'loading' , []], [ 'interactive' , []], [ 'DOMContentLoaded' , []], // 扩展状态 [ 'complete' , []], [ 'load' , []] // 扩展状态,不一定可以监听到 ]); let currentState = document.readyState; const execute = (readyState = currentState) => { currentState = readyState; for (const [state, functions] of pool) { while (functions.length) { functions.shift()(); } if (readyState === state) break ; } }; warn( 'document.readyState' , currentState); execute(); if (document.readyState !== 'complete' ) { document.addEventListener( 'readystatechange' , () => execute(document.readyState)); window.addEventListener( 'DOMContentLoaded' , () => execute( 'DOMContentLoaded' )); } window.addEventListener( 'load' , () => execute( 'load' )); const wrapper = (readyState, fn) => new Promise(resolve => { pool.get(readyState).push( function () { resolve(fn?.()); }) // 边界情况,加载完还有回调添加也执行一下 ; [ 'complete' , 'load' ].includes(currentState) && execute(); }); const loading = fn => wrapper( 'loading' , fn); const interactive = fn => wrapper( 'interactive' , fn); const DOMContentLoaded = fn => wrapper( 'DOMContentLoaded' , fn); const complete = fn => wrapper( 'complete' , fn); const load = fn => wrapper( 'load' , fn); ; // CONCATENATED MODULE: ./src/utils/querystring.ts /** * 解析querystring * @param {string} href 或 带有参数格式的string;有search则不再hash * @return {object} */ function parse(href = location.href) { if (!href) return {}; let search; try { // 链接 const url = new URL(href); ({ search } = url); // 主要处理对hash的search if (!search && url.hash.includes( '?' )) { search = url.hash.split( '?' )[1]; } } catch { // 非链接,如:a=1&b=2、?a=1、/foo?a=1、/foo#bar?a=1 if (href.includes( '?' )) { search = href.split( '?' )[1]; } else { search = href; } } const searchParams = new URLSearchParams(search); return [...searchParams.entries()].reduce((acc, [key, value]) => (acc[key] = value, acc), {}); } function stringify(obj) { return Object.entries(obj).map(([key, value]) => `${key}=${value}`).join( '&' ); } ; // CONCATENATED MODULE: ./src/utils/selector.ts const $ = document.querySelector.bind(document); const $$ = document.querySelectorAll.bind(document); ; // CONCATENATED MODULE: ./src/scripts/redirect/sites/www-jianshu-com.js const jianshu = () => ({ query: 'url' }); ; // CONCATENATED MODULE: ./src/scripts/redirect/sites/link-zhihu-com.js const zhihu = () => ({ query: 'target' }); ; // CONCATENATED MODULE: ./src/scripts/redirect/sites/t-cn.js const weibo = async () => { let link = $( '.open-url a[href]' )?.href; link || (link = await fetch(location.href).then(response => response.headers.get( 'location' ))); return { link }; }; ; // CONCATENATED MODULE: ./src/scripts/redirect/sites/weibo-cn.js const weibo_cn_weibo = () => ({ query: 'toasturl' }); ; // CONCATENATED MODULE: ./src/scripts/redirect/sites/mail-qq-com.js const qqMail = () => ({ link: parse().url || parse().gourl }); ; // CONCATENATED MODULE: ./src/scripts/redirect/sites/c-pc-qq-com.js const qqPC = () => ({ query: 'pfurl' }); ; // CONCATENATED MODULE: ./src/scripts/redirect/sites/docs-qq-com.js const qqDocs = () => ({ query: 'url' }); ; // CONCATENATED MODULE: ./src/scripts/redirect/sites/app-yinxiang-com.js const yinxiang = () => ({ query: 'dest' }); ; // CONCATENATED MODULE: ./src/scripts/redirect/sites/jump2-bdimg-com.js const tieba = () => ({ selector: '.warning_info a:nth-of-type(1)[href]' , attr: 'href' }); ; // CONCATENATED MODULE: ./src/scripts/redirect/sites/link-csdn-net.js const csdn = () => ({ query: 'target' }); ; // CONCATENATED MODULE: ./src/scripts/redirect/sites/www-youtube-com.js const youtube = () => ({ query: 'q' }); ; // CONCATENATED MODULE: ./src/scripts/redirect/sites/weixin110-qq-com.js /* eslint-disable camelcase */ const weixin = () => { const { main_type } = parse(); switch (main_type) { case '1' : return { selector: '.weui-msg__text-area .ui-ellpisis-content p' }; case '2' : { const url = new URL(location); // 转为1可还原链接 url.searchParams.set( 'main_type' , '1' ); location.replace(url.toString()); } } return {}; }; ; // CONCATENATED MODULE: ./src/scripts/redirect/sites/developers-weixin-qq-com.js const weixinDevelopers = () => ({ query: 'href' }); ; // CONCATENATED MODULE: ./src/scripts/redirect/sites/www-itdaan-com.js const itdaan = () => ({ selector: '.safety-url' }); ; // CONCATENATED MODULE: ./src/scripts/redirect/sites/www-douban-com.js const douban = () => ({ query: 'url' }); ; // CONCATENATED MODULE: ./src/scripts/redirect/sites/www-360doc-com.js const doc360 = () => { $( '#artContent' ).addEventListener( 'click' , event => { const { target } = event; const { href } = target; warn(target); if (target.nodeName !== 'A' ) return ; if (!href) return ; // 是否本站 if ( new RegExp(location.host).test( new URL(href).host)) return ; event.stopPropagation(); window.open(href); }, true ); return {}; }; ; // CONCATENATED MODULE: ./src/scripts/redirect/sites/www-pixiv-net.js const pixiv = () => { let link; // 链接居然是直接拼在url上的 // https://www.pixiv.net/jump.php?https%3A%2F%2Fwww.huawei.com%2Fcn%2Fcorporate-information for (const [key, value] of Object.entries(parse())) { try { link || (link = new URL(key).href); } catch {} try { link || (link = new URL(value).href); } catch {} } return { link }; }; ; // CONCATENATED MODULE: ./src/scripts/redirect/sites/m-sogou-com.js const sogou = () => ({ query: 'url' }); ; // CONCATENATED MODULE: ./src/scripts/redirect/sites/www-google-com.js const google = () => ({ query: 'url' }); ; // CONCATENATED MODULE: ./src/scripts/redirect/sites/www-chinaz-com.js const chinaz = () => ({ query: 'url' }); ; // CONCATENATED MODULE: ./src/scripts/redirect/sites/www-oschina-net.js const oschina = () => ({ query: 'url' }); ; // CONCATENATED MODULE: ./src/scripts/redirect/sites/link-juejin-cn.js const juejin = () => ({ query: 'target' }); ; // CONCATENATED MODULE: ./src/scripts/redirect/sites/www-pc6-com.js const pc6 = () => ({ query: 'gourl' }); ; // CONCATENATED MODULE: ./src/scripts/redirect/sites/afdian-net.js const afdian = () => ({ query: 'target' }); ; // CONCATENATED MODULE: ./src/scripts/redirect/sites/gitee-com.js const gitee = () => ({ query: 'target' }); ; // CONCATENATED MODULE: ./src/scripts/redirect/sites/index.js const sites = [{ name: '简书' , test: 'www.jianshu.com/go-wild' , use: jianshu }, { name: '知乎' , test: 'link.zhihu.com/' , use: zhihu }, { name: '微博' , test: /^t\.cn\ //, readyState: 'interactive' , use: weibo }, { name: '微博' , // 不同规则 test: 'weibo.cn/sinaurl' , use: weibo_cn_weibo }, { name: 'QQ邮箱' , test: [/^mail\.qq\.com\/cgi-bin\/readtemplate/, // 好像不用登录也可以 /^mail\.qq\.com\/cgi-bin\/mail_spam/ // 需要登录邮箱才可以,不过这里仍然可以帮忙跳转 ], use: qqMail }, { name: 'QQPC' , test: 'c.pc.qq.com/middlem.html' , use: qqPC }, { name: '腾讯文档' , test: 'docs.qq.com/scenario/link.html' , use: qqDocs }, { name: '印象笔记' , test: /^app\.yinxiang\.com\/OutboundRedirect/, use: yinxiang }, { name: '贴吧' , test: /^jump2?\.bdimg\.com\/safecheck/, // 以前的地址没有 2 readyState: 'interactive' , use: tieba }, { name: 'CSDN' , test: 'link.csdn.net/' , use: csdn }, { name: 'YouTube' , test: 'www.youtube.com/redirect' , use: youtube }, { name: '微信' , test: /^weixin110\.qq\.com\/cgi-bin\/mmspamsupport-bin\/newredirectconfirmcgi/, readyState: 'interactive' , use: weixin }, { name: '微信开放社区' , test: 'developers.weixin.qq.com/community/middlepage/href' , use: weixinDevelopers }, { name: '开发者知识库' , test: /^www\.itdaan.com\/link\ //, readyState: 'interactive' , use: itdaan }, { name: 'chinaobd2' , test: 'www.chinaobd2.com/' , use: douban }, { name: '个人图书馆' , test: /^www\.360doc.com\/content\ //, readyState: 'interactive' , use: doc360 }, { name: 'Pixiv' , test: 'www.pixiv.net/jump.php' , use: pixiv }, { name: '搜狗' , test: /^m\.sogou\.com.*tc$/, use: sogou }, { name: 'Google' , test: /^www\.google\..{2,7}url$/, use: google }, { name: '站长之家' , test: 'www.chinaz.com/go.shtml' , use: chinaz }, { name: 'OSCHINA' , test: 'www.oschina.net/action/GoToLink' , use: oschina }, { name: '掘金' , test: 'link.juejin.cn/' , use: juejin }, { name: 'pc6下载站' , test: 'www.pc6.com/goread.html' , use: pc6 }, { name: '爱发电' , test: 'afdian.net/link' , use: afdian }, { name: 'Gitee' , test: 'gitee.com/link' , use: gitee }]; /* harmony default export */ const redirect_sites = (sites); ; // CONCATENATED MODULE: ./src/scripts/redirect/index.js function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError( "attempted to use private field on non-instance" ); } return receiver; } var id = 0; function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; } function hidePage() { function hide() { document.body.style.cssText = 'display:none !important;' ; } document.body ? hide() : interactive(hide); } var _sites = /*#__PURE__*/ _classPrivateFieldLooseKey( "sites" ); var _includes = /*#__PURE__*/ _classPrivateFieldLooseKey( "includes" ); var _parse = /*#__PURE__*/ _classPrivateFieldLooseKey( "parse" ); var _ensure = /*#__PURE__*/ _classPrivateFieldLooseKey( "ensure" ); class App { constructor(sites) { Object.defineProperty( this , _ensure, { value: _ensure2 }); Object.defineProperty( this , _parse, { value: _parse2 }); Object.defineProperty( this , _includes, { value: _includes2 }); Object.defineProperty( this , _sites, { writable: true , value: [] }); _classPrivateFieldLooseBase( this , _sites)[_sites] = sites; } boot() { const briefURL = location.host + location.pathname; _classPrivateFieldLooseBase( this , _sites)[_sites].forEach(async site => { const { name, test, use } = site; if (!_classPrivateFieldLooseBase( this , _includes)[_includes](test, briefURL)) return ; const { readyState: state } = site; if (state) await ready_state_namespaceObject[state](); const redirection = await _classPrivateFieldLooseBase( this , _parse)[_parse](use); table({ name, briefURL, redirection }); if (!redirection) return ; location.replace(redirection); // 为什么要这样做? // 只是为了避免被问”哎!怎么好像没有跳转啊?!“的烦恼(实际上跳转了只是外链打开慢)(x_x) hidePage(); }); } } function _includes2(test, url) { return [].concat(test).some(item => { if ( typeof item === 'string' ) return item === url; if (item instanceof RegExp) return item.test(url); if ( typeof item === 'boolean' ) return item; return false ; }); } async function _parse2(use) { const { query, link, selector, attr } = await use(); let redirection = null ; if (query) { redirection = parse()[query]; } else if (link) { redirection = link; } else if (selector) { redirection = $(selector)?.[attr ?? 'innerText' ]; } redirection && (redirection = _classPrivateFieldLooseBase( this , _ensure)[_ensure](redirection.trim())); return redirection; } function _ensure2(url) { try { // eslint-disable-next-line no-new new URL(url); } catch (error) { warn(error); // 修复某些链接没有 protocol 导致跳转不正确 // https://www.chinaobd2.com const protocol = 'http:' ; url = protocol + '//' + url; } return url; } new App(redirect_sites).boot(); /******/ })() ; |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?