// ==UserScript==
// @name AuTo Redeemer Steamkey(自动激活Steamkey)
// @namespace HCLonely
// @author HCLonely
// @description 复制网页中的Steamkey后自动激活
// @supportURL https://steamcn.com/t344489-1-1
// @include *://*/*
// @exclude *store.steampowered.com/widget/*
// @version 3.0.5 Beta
// @grant GM_setClipboard
// @grant GM_addStyle
// @grant GM_registerMenuCommand
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_xmlhttpRequest
// @run-at document-end
// @require https://greasyfork.org/scripts/376437-hclonely-function/code/HCLonely_function.js?version=660229
// @require https://greasyfork.org/scripts/388035-$jQuery/code/$jQuery.js?version=721233
// @require https://greasyfork.org/scripts/389177-arshtml/code/arsHtml.js?version=727231
// @require https://cdn.bootcss.com/sweetalert/2.1.2/sweetalert.min.js
// @connect *
// @downloadURL none
// ==/UserScript==
(function() {
'use strict';
try{
const url = window.location.href;
const defaultSetting={
newTab:false,
copyListen:true,
selectListen:true,
clickListen:true,
asf:false,
asfProtocol:'http',
asfHost:'127.0.0.1',
asfPort:1242,
asfPassword:'',
asfBot:'',
}
let sessionID="";
try{
sessionID=g_sessionID;
}catch(e){
sessionID="";
}
if(Object.prototype.toString.call(GM_getValue("setting")) != '[object Object]') GM_setValue("setting",defaultSetting);
const asfCommands=$jQuery(arsHtml[0])[0];
if(GM_getValue("setting").selectListen){
//选中激活功能
const iconSize = 24;
const translationTestSize = 16;
let icon = document.createElement('div');
const style = '' +
'position:absolute;' +
'width:32px;' +
'height:32px;' +
'margin:0px!important;' +
'';
icon.innerHTML = '' +
''
'';
icon.setAttribute('style', '' +
'width:32px!important;' +
'height:32px!important;' +
'display:none!important;' +
'background:#fff!important;' +
'border-radius:16px!important;' +
'box-shadow:4px 4px 8px #888!important;' +
'position:absolute!important;' +
'z-index:2147483647!important;' +
'cursor:pointer;'+
'');
icon.setAttribute("title","激活");
// 添加激活图标到 DOM
document.documentElement.appendChild(icon);
// 鼠标事件:防止选中的文本消失
document.addEventListener('mousedown', function (e) {
if (e.target == icon || (e.target.parentNode && e.target.parentNode == icon) || (e.target.parentNode.parentNode && e.target.parentNode.parentNode == icon)) {// 点击了激活图标
e.preventDefault();
}
});
// 选中变化事件:当点击已经选中的文本的时候,隐藏激活图标和激活面板(此时浏览器动作是:选中的文本已经取消选中了)
document.addEventListener("selectionchange", ()=> {
if (!window.getSelection().toString().trim()) {
icon.style.display = 'none';
}
});
// 鼠标事件:防止选中的文本消失;显示、隐藏激活图标
document.addEventListener('mouseup', function (e) {
if (e.target == icon || (e.target.parentNode && e.target.parentNode == icon) || (e.target.parentNode.parentNode && e.target.parentNode.parentNode == icon)) {// 点击了激活图标
e.preventDefault();
return;
}
let text = window.getSelection().toString().trim();
let productKey = window.getSelection().toString().trim() || e.target.value;
if (/^([\w\W]*)?([\d\w]{5}(\-[\d\w]{5}){2}(\r||,||,)?){1,}/.test(productKey) && text && icon.style.display == 'none') {
icon.style.top = e.pageY + 12 + 'px';
icon.style.left = e.pageX + 18 + 'px';
icon.style.display = 'block';
} else if (!text) {
icon.style.display = 'none';
}
});
// 激活图标点击事件
icon.addEventListener('click', function (e) {
let productKey = window.getSelection().toString().trim() || e.target.value;
registerkey(productKey);
});
}
//复制激活功能
if (!/https?:\/\/store\.steampowered\.com\/account\/registerkey[\w\W]{0,}/.test(url)&&GM_getValue("setting").copyListen){//非激活页面
let activateProduct = function(e) {
let productKey = window.getSelection().toString().trim() || e.target.value;
if (/^([\w\W]*)?([\d\w]{5}(\-[\d\w]{5}){2}(\r||,||,)?){1,}/.test(productKey)) {
if(!$jQuery("div.swal-overlay").hasClass("swal-overlay--show-modal")){
swal({
title:'检测到神秘key,是否激活?',
icon: 'success',
buttons:{
confirm:'激活',
cancel:'取消',
},
}).then((value) => {
if(value) registerkey(productKey);
});
}
}else if(/^\!addlicense.*[\d]$/gi.test(productKey)){
if(Object.prototype.toString.call(GM_getValue("setting")) === '[object Object]'&&GM_getValue("setting").asf&&!$jQuery("div.swal-overlay").hasClass("swal-overlay--show-modal")){
swal({
closeOnClickOutside: false,
className:'swal-user',
title:'检测到您复制了以下ASF指令,是否执行?',
text:productKey,
buttons:{
confirm:'执行',
cancel:'取消',
},
}).then((value)=>{
if(value) asfRedeem(productKey);
});
}
}
};
window.addEventListener("copy", activateProduct, false);
}
//激活页面自动激活
const selecter=url.includes("/account/registerkey")?"":".hclonely ";
const autoDivideNum = 9;
const waitingSeconds = 20;
const ajaxTimeout = 15;
let keyCount = 0;
let recvCount = 0;
let timer;
let allUnusedKeys = [];
const failureDetail = {
14: '无效激活码',
15: '重复激活',
53: '次数上限',
13: '地区限制',
9: '已拥有',
24: '缺少主游戏',
36: '需要PS3?',
50: '这是充值码',
};
const myTexts = {
fail: '失败',
success: '成功',
network: '网络错误或超时',
line: '——',
nothing: '',
others: '其他错误',
unknown: '未知错误',
redeeming: '激活中',
waiting: '等待中',
showUnusedKey: '显示未使用的Key',
hideUnusedKey: '隐藏未使用的Key',
};
const unusedKeyReasons = [
'次数上限',
'地区限制',
'已拥有',
'缺少主游戏',
'其他错误',
'未知错误',
'网络错误或超时',
];
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=${sessionID}`,
method: 'POST',
responseType: 'json',
timeout: 1000 * ajaxTimeout,
onloadstart:function(){
if (jQuery(selecter+'table').is(':hidden')) {
jQuery(selecter+'table').fadeIn();
}
},
onload: function(response){
if(response.status==200&&response.response){
let data=response.response;
if (data.success == 1) {
tableUpdateKey(key, myTexts.success, myTexts.line,
data.purchase_receipt_info.line_items[0].packageid,
data.purchase_receipt_info.line_items[0].line_item_description);
return;
} else if (data.purchase_result_details !== undefined && data.purchase_receipt_info) {
if (!data.purchase_receipt_info.line_items[0]) {
tableUpdateKey(key, myTexts.fail,
failureDetail[data.purchase_result_details] ? failureDetail[data.purchase_result_details] : myTexts.others,
0, myTexts.nothing);
} else {
tableUpdateKey(key, myTexts.fail,
failureDetail[data.purchase_result_details] ? failureDetail[data.purchase_result_details] : myTexts.others,
data.purchase_receipt_info.line_items[0].packageid,
data.purchase_receipt_info.line_items[0].line_item_description);
}
return;
}
tableUpdateKey(key, myTexts.fail, myTexts.nothing, 0, myTexts.nothing);
}else{
tableUpdateKey(key, myTexts.fail, myTexts.network, 0, myTexts.nothing);
return;
}
},
});
}
function setUnusedKeys(key, success, reason, subId, subName) {
if (success && allUnusedKeys.includes(key)) {
var listObject;
allUnusedKeys = allUnusedKeys.filter(function(keyItem){
return keyItem != key;
});
$jQuery(selecter+'li').map((i,e)=>{
if($jQuery(e).innerHTML.includes(key)) {
listObject.remove();
}
});
} else if (!success && !allUnusedKeys.includes(key) && unusedKeyReasons.includes(reason)) {
listObject = $jQuery('
' + subId + '
' + subName) : '') +
' )');
$jQuery('#unusedKeys').append(listObject);
allUnusedKeys.push(key);
}
}
function tableInsertKey(key) {
keyCount++;
let row = $jQuery('' + key + '
' + key + '
' + subId + '
' + subName + 'key
key
key
key,key,key
No. | Key | 结果 | 详情 | Sub |
---|