better build setup

This commit is contained in:
2022-06-06 14:02:13 -05:00
parent cfbfa171e6
commit 707c150e2b
11 changed files with 590 additions and 75 deletions

2
scripts/index.d.ts vendored Normal file
View File

@@ -0,0 +1,2 @@
declare const UserScriptProjectName: string
declare const UserScriptFileUrl: string

86
scripts/meta.schema.json Normal file
View File

@@ -0,0 +1,86 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "UserScriptMeta",
"type": "object",
"properties": {
"name": {
"description": "Script Name",
"type": "string"
},
"namespace": {
"description": "Author namespace",
"type": "string"
},
"match": {
"description": "",
"type": ["string", "array"],
"minItems": 1,
"uniqueItems": true
},
"excludematch": {
"description": "",
"type": "string"
},
"version": {
"description": "",
"type": "string"
},
"description": {
"description": "",
"type": "string"
},
"icon": {
"description": "",
"type": "string"
},
"require": {
"description": "",
"type": ["string", "array"],
"minItems": 1,
"uniqueItems": true
},
"resource": {
"description": "",
"type": ["string", "array"],
"minItems": 1,
"uniqueItems": true
},
"runat": {
"description": "",
"type": "string",
"enum": ["document-start", "document-end", "document-idle"]
},
"noframes": {
"description": "",
"type": "boolean"
},
"grant": {
"description": "",
"type": ["string", "array"],
"minItems": 1,
"uniqueItems": true
},
"injectinto": {
"description": "",
"type": "string",
"enum": ["page", "content", "auto"]
},
"downloadURL": {
"description": "",
"type": "string"
},
"supportURL": {
"description": "",
"type": "string"
},
"homepageURL": {
"description": "",
"type": "string"
},
"unwrap": {
"description": "",
"type": "boolean"
}
},
"required": ["name", "namespace", "version"]
}

View File

@@ -0,0 +1,11 @@
// ==UserScript==
// @name OptiFine Download Links
// @namespace zomo.dev
// @match https://optifine.net/*
// @grant none
// @version 1.0
// @author zomo
// @description automatically grab optifine links through the ads
// @downloadURL https://git.zomo.dev/zomo/browser-scripts/raw/branch/main/dist/optifine-download-links.zomo.js
// @updateURL https://git.zomo.dev/zomo/browser-scripts/raw/branch/main/dist/optifine-download-links.zomo.js
// ==/UserScript==

View File

@@ -0,0 +1,58 @@
const onhover = false // when to load link, false will load immediately
async function getDownload(href: string): Promise<string | null> {
let resp = await fetch(href)
let text = await resp.text()
let match = text.match(/<a href=['"](downloadx.*?)['"]/i)
if (match) {
return match[1]
}
return null
}
function attachFetchDownloadLink(a: HTMLLinkElement, depth = 0) {
function run() {
a.innerText = 'Loading'
let url = new URL(a.href)
if (url.pathname === '/adloadx') {
getDownload(a.href).then(downloadUrl => {
if (downloadUrl) {
a.href = downloadUrl
a.innerText = 'Download'
} else {
a.innerText = 'Failed'
if (onhover) attachFetchDownloadLink(a, ++depth)
else
setTimeout(
() => attachFetchDownloadLink(a, ++depth),
1000
)
}
})
}
}
if (depth > 5) return
if (onhover) {
a.addEventListener('mouseover', run, { once: true })
} else {
run()
}
}
addEventListener('load', () => {
document.querySelectorAll<HTMLLinkElement>('a').forEach(a => {
let href = new URL(a.href)
if (href.hostname === 'adfoc.us') {
let params = href.searchParams
if (params.has('url')) {
let url = params.get('url')?.replace('http://', 'https://')
if (url) {
a.href = url
attachFetchDownloadLink(a)
}
}
}
})
})

View File

@@ -0,0 +1,8 @@
{
"$schema": "../meta.schema.json",
"name": "OptiFine Download Links",
"namespace": "zomo.dev",
"match": "https://optifine.net/*",
"version": "1.0",
"description": "automatically grab optifine links through the ads"
}