Greasy Fork is available in English.

Go to the page which i want.

本脚本会对一些页面进行重定向,安装前请确认理解【此操作可能带来某些安全隐患】,并愿意自行承担由此造成的一切后果。

  1. // ==UserScript==
  2. // @name Go to the page which i want.
  3. // @namespace Go to the page which i want.
  4. // @icon https://i.v2ex.co/IY7K141dl.png
  5. // @grant none
  6. // @run-at document-start
  7. // @inject-into content
  8. // @version 1.0.2
  9. // @author 稻米鼠
  10. // @description 本脚本会对一些页面进行重定向,安装前请确认理解【此操作可能带来某些安全隐患】,并愿意自行承担由此造成的一切后果。
  11. // @supportURL https://meta.appinn.net/t/21266
  12. // @homepageURL https://meta.appinn.net/t/21266
  13. // @match *://*.m.smzdm.com/p/*
  14. // @match *://m.smzdm.com/*
  15. // @match *://t.cn/*
  16. // @match *://link.zhihu.com/?target=*
  17. // @match *://weixin110.qq.com/cgi-bin/mmspamsupport-bin/newredirectconfirmcgi?*
  18. // @match *://c.pc.qq.com/middle.html*
  19. // @match *://item.m.jd.com/*
  20. // @match *://www.jianshu.com/go-wild*
  21. // @match *://mail.qq.com/cgi-bin/readtemplate*
  22. // ==/UserScript==
  23. // Variables
  24. const L = window.location
  25. // Redirect to new URL
  26. const redirectTo = url=>{ L.href = url }
  27. // Replace something from URL
  28. const replaceLocation = (inReg, outReg)=>{
  29. redirectTo( L.href.replace(inReg, outReg) )
  30. }
  31. // Redirect to a sub Url which in now Url
  32. const redirectLocation = ()=>{
  33. redirectTo( decodeURIComponent(
  34. L.search
  35. .replace(/^.*?(https?%3A(?:%2F%2F|\/\/))/, '$1')
  36. .replace(/[?&#].*$/, '')
  37. ))
  38. }
  39. // Redirect based on element content
  40. const redirectByElementContent = selsector=>{
  41. window.addEventListener('load', ()=>{
  42. const el = document.body.querySelector(selsector)
  43. if(el && /^https?:\/\/.*/.test(el.innerText)){
  44. redirectTo(el.innerText)
  45. }
  46. })
  47. }
  48. // rules
  49. const rules = [
  50. { // smzdm mobile to PC
  51. reg: /^https?:\/\/(post\.)?m\.smzdm\.com\//i,
  52. redirect: ()=>{ replaceLocation(/\/\/(post\.)?m\./, '//$1') }
  53. },
  54. {/* JD mobile to PC */
  55. reg: /^https?:\/\/item\.m\.jd\.com\/(?:product\/|ware\/view\.action\?.*wareId=)(\d+).*$/i,
  56. redirect: ()=>{ replaceLocation(/^https?:\/\/item\.m\.jd\.com\/(?:product\/|ware\/view\.action\?.*wareId=)(\d+).*$/i, 'https://item.jd.com/$1.html') }
  57. },
  58. {/* JD hot sell */
  59. reg: /^http(?:s)?:\/\/re\.jd\.com\/cps\/item\/(\d+)\.html.*$/i,
  60. redirect: ()=>{ replaceLocation(/^http(?:s)?:\/\/re\.jd\.com\/cps\/item\/(\d+)\.html.*$/i, 'https://item.jd.com/$1.html') }
  61. },
  62. { // Weibo offsite link
  63. reg: /^https?:\/\/t.cn\/\w+/i,
  64. redirect: () => { redirectByElementContent('p.link, div.desc') }
  65. },
  66. { // WeChat blocking address auto redirect
  67. reg: /^https?:\/\/weixin110\.qq\.com\/cgi-bin\/mmspamsupport-bin\/newredirectconfirmcgi\?/,
  68. redirect: () => { redirectByElementContent('p.weui-msg__desc') }
  69. },
  70. { // All jumps to intermediate pages (destination address is included in the URL)
  71. reg: /https?%3A(?:%2F%2F|\/\/)/i,
  72. redirect: ()=>{ redirectLocation() }
  73. }
  74. ]
  75. for(const rule of rules){
  76. if(rule.reg.test(L.href)){
  77. rule.redirect()
  78. break
  79. }
  80. }