-
-
Save goodjack/c7f7c51ad6ba907f2e046dd636ed465c to your computer and use it in GitHub Desktop.
JCB ezcard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name ezcard-helper | |
// @namespace http://tampermonkey.net/ | |
// @version 2024.06.02 | |
// @description 懂的都懂 | |
// @author Oschangkai | |
// @match https://ezweb.easycard.com.tw/Event01/JCBLoginServlet | |
// @match https://ezweb.easycard.com.tw/Event01/JCBLoginRecordServlet | |
// @grant none | |
// ==/UserScript== | |
(function () { | |
'use strict'; | |
// (0) default buttons, all you need to do is to modify the default ones | |
var buttons = [{ | |
text: "測試卡 1", | |
txtCreditCard1: "1111", | |
txtCreditCard2: "22", | |
txtCreditCard4: "3333", | |
txtEasyCard1: "4444", | |
txtEasyCard2: "5555", | |
txtEasyCard3: "6666", | |
txtEasyCard4: "7777", | |
}, { | |
text: "測試卡 2", | |
txtCreditCard1: "8888", | |
txtCreditCard2: "99", | |
txtCreditCard4: "0000", | |
txtEasyCard1: "1111", | |
txtEasyCard2: "2222", | |
txtEasyCard3: "3333", | |
txtEasyCard4: "4444", | |
}]; | |
// if injector is working, replace buttons with data from injector | |
var data = document.body.getAttribute("cards"); | |
if (!!data && !!data.length) { | |
buttons = JSON.parse(data); | |
} | |
// (1) create buttons | |
buttons.forEach(function (btn, index) { | |
// create element | |
var button = document.createElement("button"); | |
button.innerHTML = btn.text; | |
// style | |
button.style.position = "fixed"; | |
button.style.bottom = (10 + index * 37) + "px"; // 調整每個按鈕的位置 | |
button.style.right = "35px"; | |
var elements = { | |
'accept': !!document.getElementById('accept'), | |
'txtCreditCard1': !!document.getElementById('txtCreditCard1'), | |
'txtCreditCard2': !!document.getElementById('txtCreditCard2'), | |
'txtCreditCard3': !!document.getElementById('txtCreditCard3'), | |
'txtCreditCard4': !!document.getElementById('txtCreditCard4'), | |
'txtEasyCard1': !!document.getElementById('txtEasyCard1'), | |
'txtEasyCard2': !!document.getElementById('txtEasyCard2'), | |
'txtEasyCard3': !!document.getElementById('txtEasyCard3'), | |
'txtEasyCard4': !!document.getElementById('txtEasyCard4') | |
}; | |
// onclick event | |
button.onclick = function () { | |
for (var key in elements) { | |
if (!elements[key]) { | |
continue; | |
} | |
if (key === 'accept') { | |
document.getElementById(key).click(); | |
} else { | |
document.getElementById(key).value = buttons[index][key]; | |
} | |
} | |
}; | |
// show button on page | |
document.body.appendChild(button); | |
}); | |
// (2) create submit button | |
var submitBtn = document.createElement("button"); | |
submitBtn.innerHTML = "手動送出"; | |
// style | |
submitBtn.style.position = "fixed"; | |
submitBtn.style.bottom = (10 + buttons.length * 37) + "px"; // 調整每個按鈕的位置 | |
submitBtn.style.right = "35px"; | |
// onclick event | |
submitBtn.onclick = function () { | |
document.forms[0].submit(); | |
}; | |
// show button on page | |
document.body.appendChild(submitBtn); | |
// (3) modify message, add card number with card name | |
// find message on page | |
var message = document.querySelector('.success') || document.querySelector('.card_num'); | |
// modify message on page | |
if (message) { | |
var card = message.textContent.match(/(\d{16})/); | |
if (card) { | |
var cardNumber = card[1]; | |
var foundCard = buttons.find(function (card) { | |
var easyCardNumber = card.txtEasyCard1 + card.txtEasyCard2 + card.txtEasyCard3 + card.txtEasyCard4; | |
return easyCardNumber === cardNumber; | |
}); | |
if (foundCard) { | |
message.innerHTML = message.innerHTML.replace(cardNumber, foundCard.text + " - " + cardNumber); //TODO: 要改 | |
} | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment