支持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== // ==UserScript==
// @name JetBra // @name JetBra
// @namespace https://github.com/novice88/jetbra // @namespace https://github.com/novice88/jetbra
// @version 4.0 // @version 5.0
// @license MIT // @license MIT
// @description Add a button on the plugin homepage and click to get the plugin activation code // @description Add a button on the plugin homepage and click to get the plugin activation code
// @author novice.li // @author novice.li
@ -9,8 +9,6 @@
// @grant GM_setClipboard // @grant GM_setClipboard
// @grant GM_addStyle // @grant GM_addStyle
// @grant window.onurlchange // @grant window.onurlchange
// @downloadURL https://update.greasyfork.org/scripts/480799/JetBra.user.js
// @updateURL https://update.greasyfork.org/scripts/480799/JetBra.meta.js
// ==/UserScript== // ==/UserScript==
const pemEncodedKey = `-----BEGIN PRIVATE KEY----- const pemEncodedKey = `-----BEGIN PRIVATE KEY-----
@ -103,6 +101,7 @@ function injectStyles() {
text-align: center; text-decoration: none; display: inline-block; 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); 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; transition-duration: 0.4s;
margin-left:5px
} }
.jetbra-button:hover { background-color: #057e47; color: white; } .jetbra-button:hover { background-color: #057e47; color: white; }
`); `);
@ -141,7 +140,17 @@ function genLicenseId() {
}).join(''); }).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({ return JSON.stringify({
"licenseId": licenseId, "licenseId": licenseId,
"licenseeName": "reborn", "licenseeName": "reborn",
@ -150,17 +159,16 @@ function buildLicensePartJson(pluginCode, licenseId) {
"licenseRestriction": "", "licenseRestriction": "",
"checkConcurrentUse": false, "checkConcurrentUse": false,
"products": [{ "products": [{
"code": pluginCode, code: productCode,
"fallbackDate": "2026-12-30", fallbackDate: fallbackDate,
"paidUpTo": "2026-12-30", paidUpTo: paidUpTo
"extended": false
}], }],
"metadata": "0120230102PPAA013009", "metadata": "0120230102PPAA013009",
"hash": "41472961/0:1563609451", "hash": "41472961/0:1563609451",
"gracePeriodDays": 7, "gracePeriodDays": 7,
"autoProlongated": true, "autoProlongated": true,
"isAutoProlongated": true "isAutoProlongated": true
}) });
} }
async function addButton() { async function addButton() {
@ -183,16 +191,24 @@ async function addButton() {
} }
let newElement = document.createElement('div'); let newElement = document.createElement('div');
newElement.classList.toggle('wt-col-inline'); 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) parentElement.appendChild(newElement)
newElement.addEventListener('click', async () => { newElement.addEventListener('click', async (e) => {
if (pluginDetail.purchaseInfo === undefined) { let productCode = pluginDetail?.purchaseInfo?.productCode;
window.alert('This plugin is not a paid plugin in the market'); if (productCode === undefined) {
window.alert('该插件不是市场付费插件!');
return; return;
} }
let licenseId = genLicenseId() 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)), { let privateKey = await window.crypto.subtle.importKey("pkcs8", base64ToArrayBuffer(pem2base64(pemEncodedKey)), {
name: "RSASSA-PKCS1-v1_5", hash: "SHA-1", name: "RSASSA-PKCS1-v1_5", hash: "SHA-1",
@ -203,7 +219,7 @@ async function addButton() {
let cert_base64 = pem2base64(pemEncodedCrt); let cert_base64 = pem2base64(pemEncodedCrt);
GM_setClipboard(`${licenseId}-${licensePartBase64}-${sigResultsBase64}-${cert_base64}`, 'text'); GM_setClipboard(`${licenseId}-${licensePartBase64}-${sigResultsBase64}-${cert_base64}`, 'text');
window.alert('The activation code has been copied to your clipboard'); window.alert('激活码已经拷贝到你的剪切板');
}) })
} }