| 33 | } |
| 34 | |
| 35 | export default function WeixinPanel(props: { |
| 36 | onGetThumbMedia: () => void |
| 37 | onGetDescription: () => void |
| 38 | onEditMarkdown: () => void |
| 39 | onDownloadMarkdown: () => void |
| 40 | onParseMarkdown: () => void |
| 41 | onDownloadMarkdownWithImages: () => void |
| 42 | onDownloadPdf: () => void |
| 43 | onDownloadWord: () => void |
| 44 | onDownloadImages: () => void |
| 45 | onMakerQRPost: () => void |
| 46 | onClose: () => void |
| 47 | }) { |
| 48 | const { |
| 49 | onGetThumbMedia, |
| 50 | onGetDescription, |
| 51 | onEditMarkdown, |
| 52 | onDownloadMarkdown, |
| 53 | onParseMarkdown, |
| 54 | onDownloadMarkdownWithImages, |
| 55 | onDownloadPdf, |
| 56 | onDownloadWord, |
| 57 | onDownloadImages, |
| 58 | onMakerQRPost, |
| 59 | onClose |
| 60 | } = props |
| 61 | |
| 62 | function getPureLink() { |
| 63 | const rules = { |
| 64 | "mp.weixin.qq.com": { |
| 65 | testReg: /^http(?:s)?:\/\/mp\.weixin\.qq\.com\/s\?.*$/i, |
| 66 | query: ["__biz", "idx", "mid", "sn", "src", "timestamp", "ver", "signature"] |
| 67 | }, |
| 68 | other: { |
| 69 | testReg: /^(http(?:s)?:\/\/[^?#]*)[?#].*$/i, |
| 70 | query: ["id", "tid", "uid", "q", "wd", "query", "keyword", "keywords"] |
| 71 | } |
| 72 | } |
| 73 | const pureUrl = (function (url = window.location.href) { |
| 74 | const hash = url.replace(/^[^#]*(#.*)?$/, "$1"), |
| 75 | base = url.replace(/(\?|#).*$/, "") |
| 76 | let pureUrl = url |
| 77 | const getQueryString = function (key: string) { |
| 78 | let ret = url.match(new RegExp("(?:\\?|&)(" + key + "=[^&#]*)", "i")) |
| 79 | return null === ret ? "" : ret[1] |
| 80 | } |
| 81 | for (const i in rules) { |
| 82 | const rule = rules[i as keyof typeof rules] |
| 83 | if (rule.testReg.test(url)) { |
| 84 | let newQuerys = "" |
| 85 | if (rule.query && rule.query.length > 0) { |
| 86 | rule.query.forEach((query: string) => { |
| 87 | const ret = getQueryString(query) |
| 88 | if (ret !== "") { |
| 89 | newQuerys += (newQuerys.length ? "&" : "?") + ret |
| 90 | } |
| 91 | }) |
| 92 | } |