`;
showSwalMessage({
closeOnClickOutside: false,
title: `当前国家/地区:${cartConfig.rgUserCountryOptions[userInfo.country_code] || userInfo.country_code}`,
//@ts-ignore
content: $(`
`)[0]
}).then(() => {
$(".currency_change_option").click(function() {
const country = $(this).attr("data-country");
if (country) {
changeCountry(country);
}
});
});
}
function changeCountry(country) {
showSwalMessage({
closeOnClickOutside: false,
icon: "info",
title: "正在更换国家/地区..."
});
$.ajax({
url: "//store.steampowered.com/country/setcountry",
type: "post",
data: {
sessionid: g_sessionID,
cc: country
},
complete() {
$.ajax({
url: "//store.steampowered.com/cart/",
type: "get",
success(data) {
const cartConfigRaw = data.match(/data-cart_config="(.*?)"/)?.[1];
const temp = document.createElement("div");
temp.innerHTML = cartConfigRaw || "";
const cartConfigStr = temp.textContent || temp.innerText || "";
let cartConfig;
try {
cartConfig = JSON.parse(cartConfigStr);
} catch (e) {
console.error(e);
showSwalMessage({ title: "获取当前国家/地区失败!", icon: "error" });
return;
}
const userInfoRaw = data.match(/data-userinfo="(.*?)"/)?.[1];
const temp1 = document.createElement("div");
temp1.innerHTML = userInfoRaw || "";
const userInfoStr = temp1.textContent || temp1.innerText || "";
let userInfo;
try {
userInfo = JSON.parse(userInfoStr);
} catch (e) {
console.error(e);
showSwalMessage({ title: "获取当前国家/地区失败!", icon: "error" });
return;
}
const divContent = data.match(/
([\w\W]*?)
`;
if (userInfo?.country_code === country) {
showSwalMessage({ title: "更换成功!", icon: "success" }).then(() => {
showSwalMessage({
closeOnClickOutside: false,
title: `当前国家/地区:${cartConfig?.rgUserCountryOptions[userInfo.country_code] || userInfo.country_code}`,
//@ts-ignore
content: $(`
${div}
`)[0]
}).then(() => {
$(".currency_change_option").click(function() {
const newCountry = $(this).attr("data-country");
if (newCountry) {
changeCountry(newCountry);
}
});
});
});
} else {
showSwalMessage({ title: "更换失败!", icon: "error" });
}
},
error: () => {
showSwalMessage({ title: "获取当前国家/地区失败!", icon: "error" });
}
});
}
});
}
// redeem.ts
var FAILURE_DETAILS = {
14: "无效激活码",
15: "重复激活",
53: "次数上限",
13: "地区限制",
9: "已拥有",
24: "缺少主游戏",
36: "需要PS3?",
50: "这是充值码"
};
var UNUSED_KEY_REASONS = [
"次数上限",
"地区限制",
"已拥有",
"缺少主游戏",
"其他错误",
"未知错误",
"网络错误或超时"
];
function redeemKey(key) {
GM_xmlhttpRequest({
url: "https://store.steampowered.com/account/ajaxregisterkey/",
headers: {
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
Origin: "https://store.steampowered.com",
Referer: "https://store.steampowered.com/account/registerkey"
},
data: `product_key=${key}&sessionid=${globalThis.sessionID}`,
method: "POST",
responseType: "json",
onloadstart() {
if ($(globalThis.selecter + "table").is(":hidden")) {
$(globalThis.selecter + "table").fadeIn();
}
},
onload(response) {
if (response.status === 200 && response.response) {
const data = response.response;
if (data.success === 1 && data.purchase_receipt_info?.line_items[0]) {
const item = data.purchase_receipt_info.line_items[0];
tableUpdateKey(
key,
globalThis.myTexts.success,
globalThis.myTexts.line,
item.packageid,
item.line_item_description
);
return;
} else if (data.purchase_result_details !== void 0 && data.purchase_receipt_info) {
const item = data.purchase_receipt_info.line_items[0];
const failureReason = FAILURE_DETAILS[data.purchase_result_details] || globalThis.myTexts.others;
if (!item) {
tableUpdateKey(
key,
globalThis.myTexts.fail,
failureReason,
0,
globalThis.myTexts.nothing
);
} else {
tableUpdateKey(
key,
globalThis.myTexts.fail,
failureReason,
item.packageid,
item.line_item_description
);
}
return;
}
tableUpdateKey(key, globalThis.myTexts.fail, globalThis.myTexts.nothing, 0, globalThis.myTexts.nothing);
} else {
tableUpdateKey(key, globalThis.myTexts.fail, globalThis.myTexts.network, 0, globalThis.myTexts.nothing);
}
},
ontimeout: () => {
tableUpdateKey(key, globalThis.myTexts.fail, globalThis.myTexts.network, 0, globalThis.myTexts.nothing);
},
onerror: () => {
tableUpdateKey(key, globalThis.myTexts.fail, globalThis.myTexts.network, 0, globalThis.myTexts.nothing);
},
onabort: () => {
tableUpdateKey(key, globalThis.myTexts.fail, globalThis.myTexts.network, 0, globalThis.myTexts.nothing);
}
});
}
function setUnusedKeys(key, success, reason, subId, subName) {
if (success && globalThis.allUnusedKeys.includes(key)) {
let listObject;
globalThis.allUnusedKeys = globalThis.allUnusedKeys.filter((keyItem) => keyItem !== key);
$(`${globalThis.selecter}li`).each((i, e) => {
if ($(e).html()?.includes(key)) {
listObject = $(e);
listObject.remove();
}
});
} else if (!success && !globalThis.allUnusedKeys.includes(key) && UNUSED_KEY_REASONS.includes(reason)) {
const listObject = $("
");
listObject.html(
`${key} (${reason}${subId !== 0 ? `:
${subId} ${subName}` : ""})`
);
$("#unusedKeys").append(listObject);
globalThis.allUnusedKeys.push(key);
}
}
function tableInsertKey(key) {
globalThis.keyCount++;
const row = $("
|
");
row.append(`
${globalThis.keyCount} | `);
row.append(`
${key} | `);
row.append(`
${globalThis.myTexts.redeeming}... | `);
$(`${globalThis.selecter}tbody`).prepend(row);
}
function tableWaitKey(key) {
globalThis.keyCount++;
const row = $("
|
");
row.append(`
${globalThis.keyCount} | `);
row.append(`
${key} | `);
row.append(`
${globalThis.myTexts.waiting} (${globalThis.waitingSeconds}秒)... | `);
$(`${globalThis.selecter}tbody`).prepend(row);
}
function tableUpdateKey(key, result, detail, subId, subName) {
setUnusedKeys(key, result === globalThis.myTexts.success, detail, subId, subName);
globalThis.recvCount++;
if (!globalThis.selecter && globalThis.recvCount === globalThis.keyCount) {
$("#buttonRedeem").fadeIn();
$("#inputKey").removeAttr("disabled");
}
const rowObjects = $(`${globalThis.selecter}tr`);
for (let i = 1; i < rowObjects.length; i++) {
const rowElement = rowObjects[i];
const rowObject = $(rowElement);
if (rowObject.children()[1].innerHTML.includes(key) && rowObject.children()[2].innerHTML.includes(globalThis.myTexts.redeeming)) {
rowObject.children()[2].remove();
if (result === globalThis.myTexts.fail) {
rowObject.append(`
${result} | `);
} else {
rowObject.append(`
${result} | `);
}
rowObject.append(`
${detail} | `);
if (subId === 0) {
rowObject.append("
—— | ");
} else {
rowObject.append(
`
${subId} ${subName} | `
);
}
break;
}
}
}
function startTimer() {
const timer = setInterval(() => {
let flag = false;
let nowKey = 0;
const rowObjects = $(`${globalThis.selecter}tr`);
for (let i = rowObjects.length - 1; i >= 1; i--) {
const rowElement = rowObjects[i];
const rowObject = $(rowElement);
const cellContent = rowObject.children()[2]?.innerHTML;
if (cellContent?.includes(globalThis.myTexts.waiting)) {
nowKey++;
if (nowKey <= globalThis.autoDivideNum) {
let key = rowObject.children()[1]?.innerHTML.substring(6);
key = key?.substring(0, key.indexOf("")) || "";
rowObject.children()[2].innerHTML = `
${globalThis.myTexts.redeeming}... | `;
redeemKey(key);
} else {
flag = true;
break;
}
}
}
if (!flag) {
clearInterval(timer);
}
}, 1e3 * globalThis.waitingSeconds);
}
function redeem(keys) {
if (keys.length <= 0) {
return;
}
if (!globalThis.selecter) {
$("#buttonRedeem").hide();
$("#inputKey").attr("disabled", "disabled");
}
let nowKey = 0;
keys.forEach((key) => {
nowKey++;
if (nowKey <= globalThis.autoDivideNum) {
tableInsertKey(key);
redeemKey(key);
} else {
tableWaitKey(key);
}
});
if (nowKey > globalThis.autoDivideNum) {
startTimer();
}
}
function redeemKeys(key) {
const keys = key ? key.split(",") : getKeysByRE($("#inputKey").val()?.toString()?.trim() || "");
redeem(keys);
}
function toggleUnusedKeyArea() {
if (!globalThis.selecter) {
const unusedKeyArea = $("#unusedKeyArea");
if (unusedKeyArea.is(":hidden")) {
unusedKeyArea.show();
} else {
unusedKeyArea.hide();
}
}
}
function registerkey(key) {
const setting = GM_getValue("setting");
const keys = getKeysByRE(key);
if (setting?.asf) {
const asfCommand = `!redeem ${setting.asfBot ? `${setting.asfBot} ` : ""}${keys.join(",")}`;
asfRedeem(asfCommand);
} else if (setting?.newTab) {
const url = `https://store.steampowered.com/account/registerkey?key=${keys.join(",")}`;
window.open(url, "_blank");
} else {
webRedeem(keys.join(","));
}
}
// css.ts
var css = `table.hclonely {
font-family: verdana,arial,sans-serif;
font-size: 11px;
color: #333333;
border-width: 1px;
border-color: #999999;
border-collapse: collapse;
}
table.hclonely th {
background-color: #c3dde0;
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #a9c6c9;
}
table.hclonely tr {
background-color: #d4e3e5;
}
table.hclonely td {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #a9c6c9;
}
table.hclonely caption {
padding-top: 8px;
color: #808294;
text-align: center;
caption-side: top;
background-color: #94d7df;
}
table.hclonely h2 {
margin: 0;
font-size: 25px;
}
.swal-user {
width: 80%;
}
table.hclonely a {
color: #2196F3;
}
table.hclonely .swal-button {
padding: 5px;
}
#unusedKeyArea code {
padding: 2px 4px;
font-size: 90%;
color: #c7254e;
background-color: #f9f2f4;
border-radius: 3px;
}
.notice_box_content {
border: 1px solid #a25024;
border-radius: 3px;
color: #acb2b8;
font-size: 14px;
font-family: "Motiva Sans", Sans-serif;
font-weight: normal;
padding: 15px 15px;
margin-bottom: 15px;
}
.notice_box_content b {
font-weight: normal;
color: #f47b20;
float: left;
}
#unusedKeys {
margin:0 15px;
}
#copyUnuseKey span {
font-size: 15px;
line-height: 20px;
}
#unusedKeyArea li {
white-space: nowrap;
color: #007fff;
}
.currency_change_option_ctn {
vertical-align: top;
margin: 0 6%;
}
.currency_change_option_ctn:first-child {
margin-bottom: 12px;
}
.currency_change_option_ctn > p {
font-size: 12px;
margin: 8px 8px 0 8px;
}
.currency_change_option_ctn {
vertical-align: top;
margin: 0 6%;
}
.currency_change_option_ctn:first-child {
margin-bottom: 12px;
}
.currency_change_option {
font-family: "Motiva Sans", Sans-serif;
font-weight: 300; /* light */
display: block;
}
.currency_change_option > span {
display: block;
padding: 9px 19px;
}
.currency_change_option .country {
font-size: 20px;
}
.currency_change_option .notes {
font-size: 13px;
line-height: 18px;
}
.currency_change_option_ctn > p {
font-size: 12px;
margin: 8px 8px 0 8px;
}
.asf-class input[type="text"]{
border: 1px solid #c2e9ee;
width:180px;
}
.asf-output{
width:90%;
min-height:150px;
}
.switch-key {
margin:0 15%;
height:100px;
}
.switch-key-left {
float:left;
}
.switch-key-right {
float:right;
}
.switch-key div {
width: 50%;
position: relative;
cursor:default;
}
.switch-key input {
margin:10px 0;
}
.switch-key p {
font-size:25px;
height:25px;
color:black;
margin:0;
}
.swal-content *{
color:#000;
}
.swal-content textarea{
background: #fff;
}
#allKey{
display: inline-block;
padding: 6px 12px;
margin-bottom: 0;
font-size: 14px;
font-weight: 400;
line-height: 1.42857143;
text-align: center;
white-space: nowrap;
vertical-align: middle;
-ms-touch-action: manipulation;
touch-action: manipulation;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
background-image: none;
border: 1px solid transparent;
border-radius: 4px;color: #333;
background-color: #fff;
border-color: #ccc;
}
#allKey:hover{
color: #333;
background-color: #e6e6e6;
border-color: #adadad;
text-decoration: none;
}
#allKey:focus{
color: #333;
background-color: #e6e6e6;
border-color: #8c8c8c;
text-decoration: none;
}
#allKey:active{
background-image: none;
outline: 0;
-webkit-box-shadow: inset 0 3px 5px rgba(0,0,0,.125);
box-shadow: inset 0 3px 5px rgba(0,0,0,.125);color: #333;
background-color: #e6e6e6;
border-color: #adadad;
}
.icon-img {
position: absolute;
width: 32px;
height: 32px;
margin: 0px!important;
}
.icon-div {
width: 32px!important;
height: 32px!important;
display: none;
background: #fff!important;
border-radius: 16px!important;
box-shadow: 4px 4px 8px #888!important;
position: absolute!important;
z-index: 2147483647!important;
cursor: pointer;
}
`;
// main.ts
globalThis.url = window.location.href;
globalThis.defaultSetting = {
newTab: false,
copyListen: true,
selectListen: true,
clickListen: true,
allKeyListen: false,
asf: false,
asfProtocol: "http",
asfHost: "127.0.0.1",
asfPort: 1242,
asfPassword: "",
asfBot: ""
};
globalThis.sessionID = "";
try {
globalThis.sessionID = g_sessionID;
} catch (e) {
globalThis.sessionID = "";
}
globalThis.allUnusedKeys = [];
globalThis.selecter = globalThis.url.includes("/account/registerkey") ? "" : ".hclonely ";
globalThis.myTexts = {
fail: "失败",
success: "成功",
network: "网络错误或超时",
line: "——",
nothing: "",
others: "其他错误",
unknown: "未知错误",
redeeming: "激活中",
waiting: "等待中",
showUnusedKey: "显示未使用的Key",
hideUnusedKey: "隐藏未使用的Key"
};
globalThis.autoDivideNum = 9;
globalThis.waitingSeconds = 20;
globalThis.keyCount = 0;
globalThis.recvCount = 0;
try {
const setting = GM_getValue("setting");
if (Object.prototype.toString.call(setting) !== "[object Object]") {
GM_setValue("setting", globalThis.defaultSetting);
}
if (setting?.selectListen) {
const icon = document.createElement("div");
icon.className = "icon-div";
icon.title = "激活";
icon.innerHTML = `

`;
const $icon = $(icon);
$("html").append(icon);
$(document).mousedown((e) => {
if (e.target === icon || e.target?.parentNode === icon || e.target?.parentNode?.parentNode === icon) {
e.preventDefault();
}
});
document.addEventListener("selectionchange", () => {
if (!window.getSelection()?.toString()?.trim()) {
$icon.hide();
}
});
$(document).mouseup((e) => {
if (e.target === icon || e.target?.parentNode === icon || e.target?.parentNode?.parentNode === icon) {
e.preventDefault();
return false;
}
const text = window.getSelection()?.toString()?.trim();
const productKey = text || e.target?.value;
if (/[\d\w]{5}(-[\d\w]{5}){2}/.test(productKey) && text && $icon.is(":hidden")) {
$icon.css({
top: e.pageY + 12,
left: e.pageX + 18
}).show();
} else if (!text) {
$icon.hide();
}
});
$icon.click((e) => {
const productKey = window.getSelection()?.toString()?.trim() || e.target?.value;
registerkey(productKey);
});
}
if (!/https?:\/\/store\.steampowered\.com\/account\/registerkey[\w\W]{0,}/.test(globalThis.url) && setting?.copyListen) {
const activateProduct = async function(e) {
const productKey = window.getSelection()?.toString()?.trim() || e.target?.value;
const clipboardSuccess = await navigator.clipboard.writeText(productKey).then(() => true, () => false);
if (/^([\w\W]*)?([\d\w]{5}(-[\d\w]{5}){2}(\r||,||,)?){1,}/.test(productKey)) {
if (!$("div.swal-overlay").hasClass("swal-overlay--show-modal")) {
swal({
title: "检测到神秘key,是否激活?",
icon: "success",
//@ts-ignore
buttons: {
confirm: "激活",
cancel: "取消"
}
}).then((value) => {
if (value) registerkey(productKey);
});
}
} else if (/^![\w\d]+\s+asf\s+.+/gi.test(productKey)) {
if (setting?.asf && !$("div.swal-overlay").hasClass("swal-overlay--show-modal")) {
swal({
closeOnClickOutside: false,
className: "swal-user",
title: "检测到您复制了以下ASF指令,是否执行?",
text: productKey,
//@ts-ignore
buttons: {
confirm: "执行",
cancel: "取消"
}
}).then((value) => {
if (value) asfRedeem(productKey);
});
}
}
};
window.addEventListener("copy", activateProduct, false);
}
if (/^https?:\/\/store\.steampowered\.com\/account\/registerkey*/.test(globalThis.url)) {
$("#registerkey_examples_text").html(`
`);
$("#copyUnuseKey").click(() => {
const unusedKeys = $("#unusedKeys").text();
GM_setClipboard(arr(getKeysByRE(unusedKeys)).join(","));
swal({ title: "复制成功!", icon: "success" });
});
$(".registerkey_input_box_text").parent().css("float", "none").append(`
`);
if (/^https?:\/\/store\.steampowered\.com\/account\/registerkey\?key=.+/.test(globalThis.url)) {
$("#inputKey").val(globalThis.url.replace(/https?:\/\/store\.steampowered\.com\/account\/registerkey\?key=/i, ""));
}
$(".registerkey_input_box_text,#purchase_confirm_ssa").hide();
$("#register_btn").parent().css("margin", "10px 0").append(`
激活key
激活sub
更换国家/地区
`);
$("#register_btn").remove();
if (/^https?:\/\/store\.steampowered\.com\/account\/registerkey\?key=.+/.test(globalThis.url)) {
redeem(getKeysByRE(globalThis.url.replace(/https?:\/\/store\.steampowered\.com\/account\/registerkey\?key=/i, "").trim()));
}
$("#redeemKey").click(() => {
redeemKeys();
});
$("#redeemSub").click(redeemSubs);
$("#changeCountry").click(cc);
toggleUnusedKeyArea();
} else if (/https?:\/\/steamdb\.info\/freepackages\//.test(globalThis.url)) {
const activateConsole = () => {
const sub = [];
$("#freepackages span:visible").each(function() {
const subId = $(this).attr("data-subid");
if (subId) sub.push(subId);
});
const freePackages = sub.join(",");
window.open(`https://store.steampowered.com/account/licenses/?sub=${freePackages}`, "_self");
};
const fp = setInterval(() => {
if ($("#freepackages").length > 0) {
$("#freepackages").click(activateConsole);
clearInterval(fp);
}
}, 1e3);
} else if (/https?:\/\/store\.steampowered\.com\/account\/licenses\/(\?sub=[\w\W]{0,})?/.test(globalThis.url)) {
$("h2.pageheader").parent().append(`
激活SUB
更改国家/地区
`);
$("#buttonSUB").click(() => {
redeemSub();
});
$("#changeCountry-account").click(cc);
if (/https?:\/\/store\.steampowered\.com\/account\/licenses\/\?sub=([\d]+,)+/.test(globalThis.url)) {
setTimeout(() => {
redeemSub(globalThis.url);
}, 2e3);
}
} else if (setting?.clickListen) {
let htmlEl = null;
if ($("body").length > 0) {
$("body").click((event) => {
htmlEl = event.target;
if ($(htmlEl).parents(".swal-overlay").length === 0 && !["A", "BUTTON", "TEXTAREA"].includes(htmlEl.tagName) && !["button", "text"].includes(htmlEl.getAttribute("type") || "") && ($(htmlEl).children().length === 0 || !/([0-9,A-Z]{5}-){2,4}[0-9,A-Z]{5}/gim.test($.makeArray($(htmlEl).children().map(function() {
return $(this).text();
})).join(""))) && /([0-9,A-Z]{5}-){2,4}[0-9,A-Z]{5}/gim.test($(htmlEl).text())) {
mouseClick($, event);
arr($(htmlEl).text().match(/[\w\d]{5}(-[\w\d]{5}){2}/gim) || []).map((e) => {
$(htmlEl).html($(htmlEl).html()?.replace(new RegExp(e, "gi"), `
${e}`));
});
$(".redee-key").click(function() {
registerkey($(this).attr("key") || "");
});
}
});
}
}
if (/https?:\/\/store\.steampowered\.com\//.test(globalThis.url)) {
$("#account_pulldown").before('
更改国家/地区 |');
$("#changeCountry").click(cc);
}
if (setting?.allKeyListen) {
redeemAllKey();
}
GM_addStyle(css);
GM_registerMenuCommand("⚙设置", settingChange);
GM_registerMenuCommand("执行ASF指令", () => {
asfSend();
});
} catch (e) {
swal("AuTo Redeem Steamkey脚本执行出错,详情请查看控制台!", e.stack, "error");
console.error(e);
}