Skip to content

Commit

Permalink
feat: add nyaa si monkey script
Browse files Browse the repository at this point in the history
  • Loading branch information
Arylo committed Jun 14, 2024
1 parent 1d0ad84 commit 6cd0529
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@js-sh/js-sh": "^0.1.1"
},
"devDependencies": {
"@types/jquery": "^3.5.30",
"concurrently": "^8.2.2",
"cross-env": "^7.0.3",
"esbuild": "^0.21.5",
Expand Down
8 changes: 8 additions & 0 deletions src/monkey/nyaa-si-show-image.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "Display image right now in nyaa.si",
"match": "https://sukebei.nyaa.si/view/*",
"grant": "none",
"version": "1.0",
"run-at": "document-end",
"require": "https://code.jquery.com/jquery-3.6.0.min.js"
}
32 changes: 32 additions & 0 deletions src/monkey/nyaa-si-show-image.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
setTimeout(() => {
const elems = $('.col-md-5 a[title="User"]')

if (elems.length && elems.text() === 'javsubs91') {
const pendMKElem = $('div[markdown-text]')
if (pendMKElem.length) {
const matches = pendMKElem[0].innerText.match(/\[!\[.+\]\((.+)\)\]\((.+)\)/)
if (matches) {
pendMKElem[0].innerHTML = `<a href="${matches[2]}"><img src="${matches[1]}"></a>`
}
}
const elems = $('a > img')
if (elems.length) {
let imgUrl = elems.attr('src')
if (!imgUrl) return
const linkUrl = elems.parent().attr('href')
if (!linkUrl) return
// console.log(imgUrl, linkUrl)
imgUrl = imgUrl.replace('//th', '/i')
const list = linkUrl.split('/')
imgUrl += '/'
imgUrl += list[list.length - 1]
elems.attr('src', imgUrl)
elems.on('error', function () {
setTimeout(function () {
elems.attr('src', imgUrl + (imgUrl.indexOf('?') === -1 ? '?' : '&') + 'refresh=' + Date.now())
}, Number(Math.random() * 2000))
})
}
}

}, 50)

0 comments on commit 6cd0529

Please sign in to comment.