Skip to content

Commit

Permalink
feat: support baidu pan auto submit password
Browse files Browse the repository at this point in the history
  • Loading branch information
IronKinoko committed Sep 17, 2024
1 parent ae97428 commit 5732b67
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 78 deletions.
5 changes: 5 additions & 0 deletions .changeset/tall-spies-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'xxxxx520': patch
---

feat: support baidu pan auto submit password
1 change: 1 addition & 0 deletions packages/xxxxx520/meta.template
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// @match https://download.gamer520.com/*
// @match https://*.espartasr.com/*
// @match https://*.fourpetal.com/*
// @match https://pan.baidu.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=gamer520.com
// @require https://unpkg.com/[email protected]/dist/jquery.min.js
// @grant none
Expand Down
10 changes: 10 additions & 0 deletions packages/xxxxx520/src/baidu.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { waitDOM } from 'shared'

export default async function main() {
const url = new URL(window.location.href)
const pwd = url.searchParams.get('pwd')
if (!pwd) return

const btn = await waitDOM<HTMLDialogElement>('#submitBtn')
btn.click()
}
100 changes: 22 additions & 78 deletions packages/xxxxx520/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,78 +1,22 @@
import { session } from 'shared'

autoCompletePassowrd()
moveDownloadToTop()
baiduCloudLinkAutoComplete()
modifyAnchorTarget()
enhanceDownloadLink()

function autoCompletePassowrd() {
const $pwd = $('[name="post_password"]')
if (!$pwd.length || session.getItem('is-auto-complete')) return
const $submit = $('input[name=Submit]')

const pwdSource = [$('.entry-title').text(), $('form>p').text()]
const re = /密码保护(?::|:)(\w+)/
const pwd = pwdSource.map((s) => s.match(re)?.[1]).find((s) => s)
if (!pwd) return

session.setItem('is-auto-complete', true)
$pwd.val(pwd)
$submit[0].click()
}

function moveDownloadToTop() {
const $area = $('.sidebar-right .sidebar-column .widget-area')
const $down = $('#cao_widget_pay-4')

$area.prepend($down)
}

function baiduCloudLinkAutoComplete() {
function complete() {
const $root = $('article .entry-content')

let panEl: HTMLParagraphElement | null = null
$root.find('p').each((i, el) => {
if (el.innerText.match(/pan\.baidu\.com/)) {
panEl = el
}
if (el.innerText.match('提取码') && panEl) {
const match = panEl.innerText.match(/https:\/\/pan.baidu.com\/s\/\S+/)
if (!match) return

const link = match[0]
const url = new URL(link)
if (url.searchParams.has('pwd')) return
const pwd = el.innerText.match(/提取码[::]\s?(\w{4})/)?.[1]
if (!pwd) return

url.searchParams.set('pwd', pwd)
panEl.innerHTML = panEl.innerHTML.replaceAll(link, url.toString())
panEl = null
}
})
}

complete()
new MutationObserver(complete).observe(document.body, {
subtree: true,
childList: true,
})
}

function modifyAnchorTarget() {
$<HTMLAnchorElement>('article .entry-content a').each((i, el) => {
el.target = '_blank'
})
}

function enhanceDownloadLink() {
const $dom = $('.go-down')
const id = $dom.attr('data-id')

$dom.attr('href', `/go/?post_id=${id}`)
$dom[0].addEventListener('click', (e) => e.stopPropagation(), {
capture: true,
})
}
import { router } from 'shared'
import xxxxx520 from './xxxxx520'
import baidu from './baidu'

router({
domain: ['pan.baidu.com'],
routes: [{ path: '/share/init', run: baidu }],
})

router({
domain: [
/xxxxx520/,
/xxxxx525/,
/xxxxx528/,
/xxxxx520/,
/gamer520/,
/efemovies/,
/espartasr/,
/fourpetal/,
],
routes: [{ run: xxxxx520 }],
})
80 changes: 80 additions & 0 deletions packages/xxxxx520/src/xxxxx520.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { session } from 'shared'

export default function main() {
autoCompletePassowrd()
moveDownloadToTop()
baiduCloudLinkAutoComplete()
modifyAnchorTarget()
enhanceDownloadLink()
}

function autoCompletePassowrd() {
const $pwd = $('[name="post_password"]')
if (!$pwd.length || session.getItem('is-auto-complete')) return
const $submit = $('input[name=Submit]')

const pwdSource = [$('.entry-title').text(), $('form>p').text()]
const re = /密码保护(?::|:)(\w+)/
const pwd = pwdSource.map((s) => s.match(re)?.[1]).find((s) => s)
if (!pwd) return

session.setItem('is-auto-complete', true)
$pwd.val(pwd)
$submit[0].click()
}

function moveDownloadToTop() {
const $area = $('.sidebar-right .sidebar-column .widget-area')
const $down = $('#cao_widget_pay-4')

$area.prepend($down)
}

function baiduCloudLinkAutoComplete() {
function complete() {
const $root = $('article .entry-content')

let panEl: HTMLParagraphElement | null = null
$root.find('p').each((i, el) => {
if (el.innerText.match(/pan\.baidu\.com/)) {
panEl = el
}
if (el.innerText.match('提取码') && panEl) {
const match = panEl.innerText.match(/https:\/\/pan.baidu.com\/s\/\S+/)
if (!match) return

const link = match[0]
const url = new URL(link)
if (url.searchParams.has('pwd')) return
const pwd = el.innerText.match(/提取码[::]\s?(\w{4})/)?.[1]
if (!pwd) return

url.searchParams.set('pwd', pwd)
panEl.innerHTML = panEl.innerHTML.replaceAll(link, url.toString())
panEl = null
}
})
}

complete()
new MutationObserver(complete).observe(document.body, {
subtree: true,
childList: true,
})
}

function modifyAnchorTarget() {
$<HTMLAnchorElement>('article .entry-content a').each((i, el) => {
el.target = '_blank'
})
}

function enhanceDownloadLink() {
const $dom = $('.go-down')
const id = $dom.attr('data-id')

$dom.attr('href', `/go/?post_id=${id}`)
$dom[0].addEventListener('click', (e) => e.stopPropagation(), {
capture: true,
})
}

0 comments on commit 5732b67

Please sign in to comment.