支持2年和永久

This commit is contained in:
novice 2024-08-02 23:36:36 +08:00
parent 922d275204
commit 8c659c2ac4
1 changed files with 32 additions and 16 deletions

View File

@ -1,7 +1,7 @@
// ==UserScript==
// @name JetBra
// @namespace https://github.com/novice88/jetbra
// @version 4.0
// @version 5.0
// @license MIT
// @description Add a button on the plugin homepage and click to get the plugin activation code
// @author novice.li
@ -9,8 +9,6 @@
// @grant GM_setClipboard
// @grant GM_addStyle
// @grant window.onurlchange
// @downloadURL https://update.greasyfork.org/scripts/480799/JetBra.user.js
// @updateURL https://update.greasyfork.org/scripts/480799/JetBra.meta.js
// ==/UserScript==
const pemEncodedKey = `-----BEGIN PRIVATE KEY-----
@ -103,6 +101,7 @@ function injectStyles() {
text-align: center; text-decoration: none; display: inline-block;
border-radius: 16px; box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);
transition-duration: 0.4s;
margin-left:5px
}
.jetbra-button:hover { background-color: #057e47; color: white; }
`);
@ -141,7 +140,17 @@ function genLicenseId() {
}).join('');
}
function buildLicensePartJson(pluginCode, licenseId) {
function buildLicensePartJson(productCode, licenseId,twoYears) {
let formattedDateTwoYears = '2099-08-01';
if (twoYears) {
let futureDateTwoYears = new Date();
futureDateTwoYears.setFullYear(futureDateTwoYears.getFullYear() + 2);
formattedDateTwoYears = futureDateTwoYears.toISOString().split('T')[0];
}
let fallbackDate = formattedDateTwoYears;
let paidUpTo = formattedDateTwoYears;
return JSON.stringify({
"licenseId": licenseId,
"licenseeName": "reborn",
@ -150,17 +159,16 @@ function buildLicensePartJson(pluginCode, licenseId) {
"licenseRestriction": "",
"checkConcurrentUse": false,
"products": [{
"code": pluginCode,
"fallbackDate": "2026-12-30",
"paidUpTo": "2026-12-30",
"extended": false
code: productCode,
fallbackDate: fallbackDate,
paidUpTo: paidUpTo
}],
"metadata": "0120230102PPAA013009",
"hash": "41472961/0:1563609451",
"gracePeriodDays": 7,
"autoProlongated": true,
"isAutoProlongated": true
})
});
}
async function addButton() {
@ -183,16 +191,24 @@ async function addButton() {
}
let newElement = document.createElement('div');
newElement.classList.toggle('wt-col-inline');
newElement.innerHTML = `<button class="jetbra-button" type="button">CLICK TO GENERATE ACTIVATION CODE</button>`;
newElement.innerHTML =
`<div class="customize-btn" style="display: flex; flex-direction: column;white-space: nowrap;">
<div class="generate-plugin-code" style="display: flex;height: 40px;">
<button class="jetbra-button" type="button" id="permanentLicense">获取永久激活码</button>
<button class="jetbra-button" type="button" id="twoYearsLicense">获取两年激活码</button>
</div>
</div>`;
parentElement.appendChild(newElement)
newElement.addEventListener('click', async () => {
if (pluginDetail.purchaseInfo === undefined) {
window.alert('This plugin is not a paid plugin in the market');
newElement.addEventListener('click', async (e) => {
let productCode = pluginDetail?.purchaseInfo?.productCode;
if (productCode === undefined) {
window.alert('该插件不是市场付费插件!');
return;
}
let licenseId = genLicenseId()
let licensePartJson = buildLicensePartJson(pluginDetail.purchaseInfo.productCode, licenseId)
let licensePartJson = buildLicensePartJson(productCode, licenseId,e.target.id === "twoYearsLicense")
let privateKey = await window.crypto.subtle.importKey("pkcs8", base64ToArrayBuffer(pem2base64(pemEncodedKey)), {
name: "RSASSA-PKCS1-v1_5", hash: "SHA-1",
@ -203,7 +219,7 @@ async function addButton() {
let cert_base64 = pem2base64(pemEncodedCrt);
GM_setClipboard(`${licenseId}-${licensePartBase64}-${sigResultsBase64}-${cert_base64}`, 'text');
window.alert('The activation code has been copied to your clipboard');
window.alert('激活码已经拷贝到你的剪切板');
})
}
@ -212,4 +228,4 @@ if (window.onurlchange === null) {
window.addEventListener('urlchange', (ignore) => {
addButton();
});
}
}