// ==UserScript==
// @name 🔥🔥🔥 战地1 - 图章分享码获取 🔥🔥🔥
// @namespace http://tampermonkey.net/
// @version 1.1.4
// @description 可以将玩家图章生成对应分享码,粘贴到脚本对应处运行即可获取图章,无视图章数量限制(无需控制台操作)。感谢B_bili22、白梧
// @author CrazyZhang666
// @license MIT
// @match *://*.battlefield.com/companion/*
// @icon https://pic.rmb.bdstatic.com/bjh/cea155e70735d0028259b600d4dbffdd.png
// @require https://cdn.bootcdn.net/ajax/libs/limonte-sweetalert2/11.4.20/sweetalert2.all.min.js
// @grant GM_addStyle
// @grant GM_xmlhttpRequest
// @grant GM_setClipboard
// ==/UserScript==
// 添加 css 样式
function addStyle() {
let css = `
#btn_main {
position: fixed;
padding: 10px;
z-index: 9999;
color: #FFFFFF;
background-color: #409EFF;
text-align: center;
text-decoration: none;
border: none;
transition-duration: 0.4s;
cursor: pointer;
border-radius: 5px;
}
#btn_main:hover {
background-color: #4CAF50;
box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24), 0 17px 50px 0 rgba(0,0,0,0.19);
}
`
GM_addStyle(css)
}
// 主体功能区
(function () {
let cHeight = window.screen.availHeight / 2.5 + "px";
console.log(cHeight)
let btn_main = document.createElement("button");
btn_main.innerHTML = "⚡️";
btn_main.id = "btn_main";
btn_main.style.left = "1px";
btn_main.style.bottom = cHeight;
btn_main.onclick = function () {
Swal.fire({
title: '提示',
text: "请选择你要对【图章分享码】执行的操作",
icon: 'info',
showCancelButton: true,
showDenyButton: true,
confirmButtonColor: '#3085d6',
denyButtonColor: '#7066e0',
cancelButtonColor: '#d33',
confirmButtonText: "🌙 获取",
denyButtonText: "⭐️ 设置",
cancelButtonText: '❌ 取消'
}).then((result) => {
if (result.isConfirmed) {
getShareCode()
} else if (result.isDenied) {
setShareCode()
}
})
return;
};
document.body.append(btn_main);
addStyle();
})();
function getShareCode() {
if (window.location.href.indexOf("career/") <= 0) {
Swal.fire({
title: '警告',
text: '请先选择要分享的图章,操作取消',
icon: 'warning'
});
return;
}
var domimg = document.querySelector("#emblem-preview div div img");
console.log(domimg.src)
console.log("PersonaId", window.location.href.split("career/")[1].split("/")[0])
console.log("Slot", window.location.href.split("/").pop())
console.log("SessionId", localStorage.gatewaySessionId)
GM_xmlhttpRequest({
method: "POST",
url: '/jsonrpc/web/api',
data: JSON.stringify({
jsonrpc: "2.0",
method: "Emblems.shareGalleryEmblem",
params: {
slot: window.location.href.split("/").pop()
}
}),
dataType: "json",
headers: {
"X-GatewaySession": localStorage.gatewaySessionId
},
onload: function (res) {
if (res.status === 200) {
console.log('成功')
var e = JSON.parse(res.responseText);
let shareCode = e.result.shareKey
console.log("ShareCode", shareCode)
GM_setClipboard(shareCode);
Swal.fire({
title: '成功',
text: '操作成功,分享码已自动复制到剪切板\n' + shareCode,
imageUrl: domimg.src,
imageWidth: 300,
imageHeight: 300,
imageAlt: '分享图章预览',
});
} else {
Swal.fire({
title: '失败',
text: '操作失败' + res,
type: 'warning'
});
console.log("失败", res)
}
},
onerror: function (err) {
Swal.fire({
title: '错误',
text: '发生错误' + err,
type: 'error'
});
console.log("错误", err)
}
});
}
function setShareCode() {
Swal.fire({
title: '提示',
icon: 'info',
input: 'textarea',
inputLabel: '输入图章分享代码',
inputPlaceholder: '请输入其他玩家分享的图章分享码,例如:F22JBXRWSVD4VOWSVQVCZFWC7I------',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: '确定',
cancelButtonText: '取消',
inputValidator: (value) => {
if (!value) {
return '请输入正确的图章分享码'
}
}
}).then((result) => {
if (!result.value)
return;
GM_xmlhttpRequest({
method: "POST",
url: '/jsonrpc/web/api',
data: JSON.stringify({
jsonrpc: "2.0",
method: "Emblems.importSharedEmblem",
params: {
shareKey: result.value.trim()
}
}),
dataType: "json",
headers: {
"X-GatewaySession": localStorage.gatewaySessionId
},
onload: function (res) {
if (res.status === 200) {
Swal.fire({
title: '成功',
text: '操作成功,请前往图章最下面处查看',
icon: 'success'
});
location.assign("https://companion-api.battlefield.com/companion/emblems");
console.log('成功')
} else {
Swal.fire({
title: '失败',
text: '操作失败' + res,
type: 'warning'
});
console.log("失败", res)
}
},
onerror: function (err) {
Swal.fire({
title: '错误',
text: '发生错误' + err,
type: 'error'
});
console.log("错误", err)
}
});
});
}