By Admin Sir
Font size:
12px
/**
* Step 1: Google Sheets Backend
* - Create a new Google Sheet.
* - Add headers: `License Key`, `Status` (Active/Inactive), `Expiration Date`.
* - Open Extensions > Apps Script and paste the script below.
*/
function generateLicenseKey() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var licenseKey = "LIC-" + Math.random().toString(36).substr(2, 10).toUpperCase();
sheet.appendRow([licenseKey, "Active", new Date()]);
return licenseKey;
}
function checkLicenseKey(key) {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var data = sheet.getDataRange().getValues();
for (var i = 1; i < data.length; i++) {
if (data[i][0] === key && data[i][1] === "Active") {
return "Valid";
}
}
return "Invalid";
}
function doGet(e) {
var key = e.parameter.key;
return ContentService.createTextOutput(checkLicenseKey(key));
}
/**
* Step 2: Deploy Web App
* - Click `Deploy` > `New Deployment` > `Web App`.
* - Set access to `Anyone with the link`.
* - Copy the URL for verification in Blogger.
*/
/**
* Step 3: JavaScript in Blogger Theme
* - This script checks the license by calling the Apps Script Web App.
*/
const LICENSE_API_URL = "YOUR_DEPLOYED_WEB_APP_URL"; // Replace with your Google Apps Script URL
function verifyLicense() {
var userKey = prompt("Enter your license key:");
if (!userKey) return;
fetch(LICENSE_API_URL + "?key=" + userKey)
.then(response => response.text())
.then(status => {
if (status.trim() === "Valid") {
alert("License Verified! Theme Unlocked.");
document.body.style.display = "block";
} else {
alert("Invalid License Key! Contact Support.");
document.body.style.display = "none";
}
})
.catch(error => alert("Error verifying license: " + error));
}
// Hide content until license is verified
document.body.style.display = "none";
verifyLicense();
Also read:
0Comments